rust-lang / rust-lang/cargo

Support -Zno-link

Open
#9,019 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-linkage C-feature-request Performance S-needs-design
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

Describe the problem you are trying to solve
Compilation pipelining can currently compile dependent crates as soon as the crate metadata is written in most cases. This improves cpu utilization for from-scratch builds. It is however not possible to apply pipelining on crates that need to be linked like executables and dylibs as all object files need to be available to link something.

Describe the solution you'd like
Using the -Zno-link option of rustc it is possible to separate the compilation and linking step. This makes it possible to pipeline the compilation and only wait for all crates to be fully compiled once we want to link the final executable. This option was introduced in https://github.com/rust-lang/rust/pull/68487 and fixed in https://github.com/rust-lang/rust/pull/80187 (now with a test to prevent regressions).

Notes
cc https://github.com/rust-lang/rust/issues/64191

To implement this rustc will first need to be invoked with -Zno-link as argument. This will produce all object files and a .rlink file. Once all dependencies are compiled you need to invoke rustc a second time with -Zlink-only as argument and the .rlink file instead of the source file.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the compilation-pipelining context and the referenced rustc pull requests #68487 and #80187, along with issue #64191. Trace where Cargo invokes rustc for dependent crates and determine how to perform the two invocations: -Zno-link during compilation, followed by -Zlink-only with the .rlink file before final linking; done means linked crates can be pipelined without regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.