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
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)

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
@rust-bors

rust-bors Bot commented Aug 24, 2026

Copy link
Copy Markdown
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)>
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