Skip to content

[experiment] bootstrap: leverage cargo trim-paths - #161049

Draft
weihanglo wants to merge 5 commits into
rust-lang:mainfrom
weihanglo:bootstrap-trim-paths-exp
Draft

[experiment] bootstrap: leverage cargo trim-paths#161049
weihanglo wants to merge 5 commits into
rust-lang:mainfrom
weihanglo:bootstrap-trim-paths-exp

Conversation

@weihanglo

@weihanglo weihanglo commented Aug 13, 2026

Copy link
Copy Markdown
Member

View all comments

What

Leverage Cargo's -Ztrim-paths to remap compiler and library. See rust-lang/cargo#17309.

I'll do some dist jobs and see if artifacts are remapped correctly.

try-jobs: dist-x86_64-msvc
try-jobs: dist-x86_64-linux
try-jobs: dist-aarch64-apple

🤖 LLM disclosure: I used LLM to do the first pass of bootstrap integration and temporary stage0 bump. The usage was signed off here on Zulip: #llm-reviews > Experiment with Cargo's trim-path in bootstrap

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-release Relevant to the release subteam, which will review and decide on the PR/issue. labels Aug 13, 2026
@weihanglo

Copy link
Copy Markdown
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 13, 2026
[experiment] bootstrap: leverage cargo trim-paths
@rust-log-analyzer

This comment has been minimized.

@weihanglo

Copy link
Copy Markdown
Member Author

@bors try cancel

@rust-bors

rust-bors Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Try build cancelled. Cancelled workflows:

@weihanglo

Copy link
Copy Markdown
Member Author

@bors try jobs=dist-x86_64-msvc,dist-x86_64-linux,dist-aarch64-apple

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 13, 2026
[experiment] bootstrap: leverage cargo trim-paths


try-job: dist-x86_64-msvc
try-job: dist-x86_64-linux
try-job: dist-aarch64-apple
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

💔 Test for bd743b7 failed: CI. Failed jobs:

@weihanglo
weihanglo force-pushed the bootstrap-trim-paths-exp branch from b0b31e6 to 9981c62 Compare August 13, 2026 16:17
@rust-log-analyzer

This comment has been minimized.

@weihanglo

Copy link
Copy Markdown
Member Author

@bors try jobs=dist-x86_64-msvc,dist-x86_64-linux,dist-aarch64-apple

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 13, 2026
[experiment] bootstrap: leverage cargo trim-paths


try-job: dist-x86_64-msvc
try-job: dist-x86_64-linux
try-job: dist-aarch64-apple
@rust-bors

rust-bors Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 67c6105 (67c6105718f0714463e9014eca86d60e96ba0b12)
Base parent: ba28ff7 (ba28ff76f353a722f31c4f3dd2ac4e437d36411b)

@weihanglo
weihanglo force-pushed the bootstrap-trim-paths-exp branch from 9981c62 to 21aed96 Compare August 13, 2026 22:52
@rust-log-analyzer

This comment has been minimized.

@weihanglo
weihanglo force-pushed the bootstrap-trim-paths-exp branch from 21aed96 to 80d0ecc Compare August 14, 2026 01:45
@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Aug 14, 2026
@weihanglo

Copy link
Copy Markdown
Member Author

@bors try jobs=dist-x86_64-msvc,dist-x86_64-linux,dist-aarch64-apple

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 14, 2026
[experiment] bootstrap: leverage cargo trim-paths


try-job: dist-x86_64-msvc
try-job: dist-x86_64-linux
try-job: dist-aarch64-apple
rust-bors Bot pushed a commit that referenced this pull request Aug 15, 2026
[experiment] bootstrap: leverage cargo trim-paths


try-job: dist-x86_64-msvc
try-job: dist-x86_64-linux
try-job: dist-aarch64-apple
pull Bot pushed a commit to Mattlk13/cargo that referenced this pull request Aug 15, 2026
With this we get remap for free when building in rustc bootstrap:

See

* rust-lang/rust#161049
* rust-lang#17309
pull Bot pushed a commit to Mattlk13/cargo that referenced this pull request Aug 15, 2026
### What does this PR try to resolve?

With this we get remap for free when building in rustc bootstrap:

See

* rust-lang/rust#161049
* rust-lang#17309
* rust-lang/cc-rs#1794

### How to test and review this PR?
@rust-bors

rust-bors Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 62cf67c (62cf67c121864e5bfc57b32497dc24e22b7a91a0)
Base parent: d453bdd (d453bdd8f092d099bc336f0bda4163f809ad18e0)

// When building the standard library sources, we want to apply the std remap scheme.
let map = [
// Cargo use relative paths for workspace members, so let's remap those.
format!("library/={map_to}/library"),

@Urgau Urgau Aug 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this remapping isn't done anymore.

$ rustc +62cf67c121864e5bfc57b32497dc24e22b7a91a0 diag.rs
error[E0277]: the trait bound `{integer}: AsRef<Path>` is not satisfied
 --> diag.rs:2:37
  |
2 |     let a = std::fs::read_to_string(12).unwrap();
  |             ----------------------- ^^ the trait `AsRef<Path>` is not implemented for `{integer}`
  |             |
  |             required by a bound introduced by this call
  |
note: required by a bound in `std::fs::read_to_string`
 --> library/std/src/fs.rs:383:0

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we forgot library=<map_to>/library remap, which its relative form not covered by Cargo's <absolute-workspace-root>=<map_to>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the same is probably also not done for compiler.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors

This comment has been minimized.

weihanglo added a commit to weihanglo/cargo that referenced this pull request Aug 15, 2026
This is effectively `library/=<to>/library`
and `compiler/=<to>/compiler` in rustc bootstrap,
when `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` is set.

This isn't needed for normal cases
because relative member paths are exactly what users want.

See <rust-lang/rust#161049 (comment)>
weihanglo added a commit to weihanglo/cargo that referenced this pull request Aug 15, 2026
This is effectively `library/=<to>/library`
and `compiler/=<to>/compiler` in rustc bootstrap,
when `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` is set.

This isn't needed for normal cases
because relative member paths are exactly what users want.

See <rust-lang/rust#161049 (comment)>
weihanglo added a commit to weihanglo/cargo that referenced this pull request Aug 15, 2026
This is effectively `library/=<to>/library`
and `compiler/=<to>/compiler` in rustc bootstrap,
when `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` is set.

This isn't needed for normal cases
because relative member paths are exactly what users want.

See <rust-lang/rust#161049 (comment)>
weihanglo added a commit to weihanglo/cargo that referenced this pull request Aug 15, 2026
This is effectively `library/=<to>/library`
and `compiler/=<to>/compiler` in rustc bootstrap,
when `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` is set.

This isn't needed for normal cases
because relative member paths are exactly what users want.

See <rust-lang/rust#161049 (comment)>
weihanglo added a commit to weihanglo/cargo that referenced this pull request Aug 16, 2026
This is effectively `library/=<to>/library`
and `compiler/=<to>/compiler` in rustc bootstrap,
when `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` is set.

This isn't needed for normal cases
because relative member paths are exactly what users want.

See <rust-lang/rust#161049 (comment)>
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Aug 17, 2026
With this,
we get C dep remap for free when building in rustc bootstrap:

See

* rust-lang/rust#161049
* rust-lang/cargo#17309
* rust-lang/cc-rs#1794
weihanglo added a commit to weihanglo/cargo that referenced this pull request Aug 19, 2026
This is effectively `library/=<to>/library`
and `compiler/=<to>/compiler` in rustc bootstrap,
when `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` is set.

This isn't needed for normal cases
because relative member paths are exactly what users want.

See <rust-lang/rust#161049 (comment)>
rust-bors Bot pushed a commit that referenced this pull request Aug 19, 2026
chore: bump to cc@1.4.3 for rustc_llvm and library



### What is this?

Old cc-rs derives this from the `-Clto` rustflag on its own.
`cc@1.2.39` starts gating that behind `-Clinker-plugin-lto`,
which bootstrap doesn't pass.
Therefore,
we need to pass this flag explicitly to keep LTO mode

Previous efforts:

* #146186
* #155438

I personally want this because of cc 1.3.0+ has the support of Cargo `-Ztrim-paths`,
which helps what I am experimenting in <#161049>.

### How to review

Commit by commit. 

To keep commits bisect-able,
I added the first commit without cc bump.
clang should be fine with duplicate `-flto` flags.

One thing I am not certain is whether we should probe `-flto` flag in this case,
or just make this fail if `-flto` isn't supported.
(I assume `-flto` is quote widely supported)

r? Kobzol

---

🤖 **LLM disclosure:** I used LLM for the experiment of <#161049>, but not the bootstrap LTO change in this PR.
rust-bors Bot pushed a commit that referenced this pull request Aug 19, 2026
chore: bump to cc@1.4.3 for rustc_llvm and library



### What is this?

Old cc-rs derives this from the `-Clto` rustflag on its own.
`cc@1.2.39` starts gating that behind `-Clinker-plugin-lto`,
which bootstrap doesn't pass.
Therefore,
we need to pass this flag explicitly to keep LTO mode

Previous efforts:

* #146186
* #155438

I personally want this because of cc 1.3.0+ has the support of Cargo `-Ztrim-paths`,
which helps what I am experimenting in <#161049>.

### How to review

Commit by commit. 

To keep commits bisect-able,
I added the first commit without cc bump.
clang should be fine with duplicate `-flto` flags.

One thing I am not certain is whether we should probe `-flto` flag in this case,
or just make this fail if `-flto` isn't supported.
(I assume `-flto` is quote widely supported)

r? Kobzol

---

🤖 **LLM disclosure:** I used LLM for the experiment of <#161049>, but not the bootstrap LTO change in this PR.
weihanglo added a commit to weihanglo/cargo that referenced this pull request Aug 21, 2026
This is effectively `library/=<to>/library`
and `compiler/=<to>/compiler` in rustc bootstrap,
when `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` is set.

This isn't needed for normal cases
because relative member paths are exactly what users want.

See <rust-lang/rust#161049 (comment)>
rust-bors Bot pushed a commit that referenced this pull request Aug 21, 2026
chore: bump to cc@1.4.3 for rustc_llvm and library



### What is this?

Old cc-rs derives this from the `-Clto` rustflag on its own.
`cc@1.2.39` starts gating that behind `-Clinker-plugin-lto`,
which bootstrap doesn't pass.
Therefore,
we need to pass this flag explicitly to keep LTO mode

Previous efforts:

* #146186
* #155438

I personally want this because of cc 1.3.0+ has the support of Cargo `-Ztrim-paths`,
which helps what I am experimenting in <#161049>.

### How to review

Commit by commit. 

To keep commits bisect-able,
I added the first commit without cc bump.
clang should be fine with duplicate `-flto` flags.

One thing I am not certain is whether we should probe `-flto` flag in this case,
or just make this fail if `-flto` isn't supported.
(I assume `-flto` is quote widely supported)

r? Kobzol

---

🤖 **LLM disclosure:** I used LLM for the experiment of <#161049>, but not the bootstrap LTO change in this PR.
Replace `RUSTC_DEBUGINFO_MAP` and `RUSTC_CARGO_REGISTRY_SRC_TO_REMAP`
with cargo trim-paths and `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` override
(See cargo#17309).

The `RUSTC_DEBUGINFO_MAP` into `-ffile-prefix-map` in rustc_llvm
will be covered cc@1.3.0+ natively
(which inherits and forwards `CARGO_TRIM_PATHS_REMAP`)
The current dwarfdump checks cannot see `.rmeta` leaks:

* The compiler keeps unremapped local paths in metadata
  unless the remap scope is `all` (see issue 159621)
* std ships metadata as separate `.rmeta` via `-Zembed-metadata=no`
  so the leak does not even appear in the rlibs

This commit enhances to also check rmeta files.
Registry dependencies are now remapped by cargo trim-paths as
`/cargo/registry/{source-hash}/{pkg}-{ver}/`
The `-fdebug-prefix-map` flags in `cc_unhandled_cflags` served three
kinds of consumers.

* The cc-rs-driven C/C++ builds inside cargo:
  They now inherit the same remap pairs from cargo trim-paths
  so passing the flag through `CFLAGS` there is redundant.
* The CMake-driven LLVM build:
  This is the one we need the remaps.
* The remaining callers
  (`compiler_file` probing, cc detection, test fixtures):
  They never produce distributed artifacts.
@weihanglo
weihanglo force-pushed the bootstrap-trim-paths-exp branch from e416b25 to 7d23b0e Compare August 22, 2026 03:11
@weihanglo

Copy link
Copy Markdown
Member Author

@bors try jobs=dist-x86_64-msvc,dist-x86_64-linux,dist-aarch64-apple

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 22, 2026
[experiment] bootstrap: leverage cargo trim-paths


try-job: dist-x86_64-msvc
try-job: dist-x86_64-linux
try-job: dist-aarch64-apple
@rust-bors

rust-bors Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 0f3f6ba (0f3f6bab4b478ccba6ce0c6c6649899863d51eac)
Base parent: def3ee9 (def3ee9e4f0fe1429574f402bb624439bbd13fc6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs A-testsuite Area: The testsuite used to check the correctness of rustc A-tidy Area: The tidy tool S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-release Relevant to the release subteam, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants