[experiment] bootstrap: leverage cargo trim-paths - #161049
Draft
weihanglo wants to merge 5 commits into
Draft
Conversation
Member
Author
|
@bors try |
This comment has been minimized.
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
This comment has been minimized.
This comment has been minimized.
Member
Author
|
@bors try cancel |
Contributor
|
Try build cancelled. Cancelled workflows: |
Member
Author
|
@bors try jobs=dist-x86_64-msvc,dist-x86_64-linux,dist-aarch64-apple |
This comment has been minimized.
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
This comment has been minimized.
This comment has been minimized.
Contributor
|
💔 Test for bd743b7 failed: CI. Failed jobs:
|
weihanglo
force-pushed
the
bootstrap-trim-paths-exp
branch
from
August 13, 2026 16:17
b0b31e6 to
9981c62
Compare
This comment has been minimized.
This comment has been minimized.
Member
Author
|
@bors try jobs=dist-x86_64-msvc,dist-x86_64-linux,dist-aarch64-apple |
This comment has been minimized.
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
Contributor
weihanglo
force-pushed
the
bootstrap-trim-paths-exp
branch
from
August 13, 2026 22:52
9981c62 to
21aed96
Compare
This comment has been minimized.
This comment has been minimized.
weihanglo
force-pushed
the
bootstrap-trim-paths-exp
branch
from
August 14, 2026 01:45
21aed96 to
80d0ecc
Compare
Member
Author
|
@bors try jobs=dist-x86_64-msvc,dist-x86_64-linux,dist-aarch64-apple |
This comment has been minimized.
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
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
force-pushed
the
bootstrap-trim-paths-exp
branch
from
August 22, 2026 03:11
e416b25 to
7d23b0e
Compare
Member
Author
|
@bors try jobs=dist-x86_64-msvc,dist-x86_64-linux,dist-aarch64-apple |
This comment has been minimized.
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
Contributor
RalfJung
pushed a commit
to RalfJung/rust
that referenced
this pull request
Aug 23, 2026
With this, we get C dep remap for free when building in rustc bootstrap: See * rust-lang#161049 * rust-lang/cargo#17309 * rust-lang/cc-rs#1794
Contributor
|
☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
RalfJung
pushed a commit
to RalfJung/miri
that referenced
this pull request
Aug 24, 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: * rust-lang/rust#146186 * rust-lang/rust#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 <rust-lang/rust#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 <rust-lang/rust#161049>, but not the bootstrap LTO change in this PR.
weihanglo
added a commit
to weihanglo/cargo
that referenced
this pull request
Aug 25, 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 26, 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 26, 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 26, 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 26, 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 linyihai/cargo
that referenced
this pull request
Aug 27, 2026
…ang#17366) ### What does this PR try to resolve? This adds the missing rustc bootstrap custom remap prefix for packages relative to the working directory. Cargo's [workspace remap rule][ws-remap] was pretty simple: everything under the working directory[^1] becomes relative to the working directory (like `strip_prefix(root)`). For supporting rustc bootstrap remaps (rust-lang#17309), we added specific env var `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` to set custom prefix for workspace remap rule. That covers absolute paths starting with `<ws-root> Unfortunately, it didn't cover paths already relative to the working directory. The reason is that Cargo already passes workspace member paths relative to the working directory. For example, the path rustc saw was already relative like `library/std/src/lib.rs`. The path never matches the remap prefix `<ws-root>` so cannot be remapped by Cargo's `-Ztrim-paths`. Below are incorrect and expected diagnostics: ``` note: required by a bound in `std::fs::read_to_string` --> library/std/src/fs.rs:383:0 (before this PR, wrong) --> /rustc/<sha>/library/std/src/fs.rs:383:0 (expected) ``` This PR extends `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` to additionally add a remap rule for everything relative to workspace. The new remap rule joisn the prefix with the relative path, so `library/std/src/lib.rs` becomes `/<custom-prefix>/library/std/src/lib.rs`. Full comparsion: | rule | old handwritten remap| `-Ztrim-paths` before this | `-Ztrim-paths` after this | |---|---|---|---| | ws | `<root>` -> `/rustc/<sha>` | `<root>` -> `/rustc/<sha>` | `<root>` → `/rustc/<sha>` | | ws relative | `library/` -> `/rustc/<sha>/library/` | `library/` -> `library/` (no remap at all) | `library/` -> `/rustc/<sha>/library` | [ws-remap]: https://github.com/rust-lang/cargo/blob/2305ac97ea879ad32ea0dd6366b5f8dad1ba4ce7/src/compiler/trim_paths.rs#L98 [^1]: by default it is Cargo workspace root but rustc bootstrap use `-Zroot-dir` to set the working directory always to the repo root (or checkout out, whatever you like, it is the directory that has the x.py) See <rust-lang/rust#161049 (comment)> Part of <rust-lang#17309> ### How to test and review this PR? cc @Urgau **🤖 LLM disclosure**: Used for verifying it actually works with rustc bootstrap, which has been signed off on rust-lang/rust side (rust-lang/rust#161049).
weihanglo
added a commit
to weihanglo/cargo
that referenced
this pull request
Aug 28, 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)>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
View all comments
What
Leverage Cargo's
-Ztrim-pathsto 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