allow -Ldependency search paths for panic runtimes - #160007
Conversation
|
r? @TaKO8Ki rustbot has assigned @TaKO8Ki. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
This would risk accidentally getting a crates.io crate replacing compiler-builtins or a panic runtime from the sysroot even when it isn't a direct dependency, right? Currently |
|
One possible alternative is using something like
|
|
Wouldn't |
|
When cargo builds some final binary depending on libstd, panic runtime crates are already indirect dependencies. |
I mean when building user crates.
At
|
From my understanding, we want to avoid special cases for |
|
That's indeed the reason, we'd like Cargo to only have to be aware of stable crates (plus test)
rustc does report an error when it finds more than one candidate, including if one of these candidates is in the sysroot. So for this to happen, rustc would need to want to inject a crate that cargo hasn't built as part of build-std (and doesn't exist in the sysroot), which I don't think is possible right now. If it is possible I think you'd have to pass a panic strategy via RUSTFLAGS rather than the profile, and we do have this line in the RFC to fall back on:
|
Sysroot crates should have lower priority than user crates. Otherwise it wouldn't be possible to use libc from crates.io. Would it work if we make rustc add a conditional dependency on both panic_unwind and panic_abort when compiling libstd rather than only on panic_unwind? |
|
Sorry, I'm just referring to injected dependencies, for which Kirill found that rustc threw an error when he added
Sorry, I'm clearly not awake yet! |
There is no such thing as priority from the crate locator perspective: rust/compiler/rustc_metadata/src/locator.rs Lines 502 to 505 in dfbea5b The right version of
When compiling libstd as rlib, we don't inject the panic runtime at all. So the panic runtime is not present in std metadata as a dependency and therefore is not loaded like regular transitive dependencies. |
It's not about building a panic runtime. It's about rustc representation of dependencies in the crate graph. Here is what conditional dependency mean: rust/compiler/rustc_session/src/cstore.rs Lines 42 to 44 in ad0c9dc |
For indirect dependencies yes. For direct dependencies the
panic_unwind is absolutely present as conditional dependency in the libstd crate metadata: rustc +nightly -Zls=root $(rustc +nightly --print target-libdir)/libstd-*.rmeta | rg "Dependencies|panic_unwind"
=External Dependencies=
18 panic_unwind-aff6afe86ac8b0f1 hash 362c7180b46c57babeedc50f4e9b00d0 host_hash None kind Conditional private linkage Some(RequireStatic)The problem is that the panic runtime injection code attempts to include it as direct dependency. My suggestion is to include both panic runtimes (or one if the other hasn't been built) as conditional dependency of libstd replacing the code at rust/compiler/rustc_metadata/src/creader.rs Lines 956 to 1025 in ad0c9dc rust/compiler/rustc_metadata/src/dependency_format.rs Lines 253 to 260 in ad0c9dc |
Then it seems like |
|
I'm curious what should we do with On the one hand, as Adam already said, we want to use only stable names in Cargo and therefore remove https://github.com/rust-lang/cargo/blob/0158e40d8638a7de292b7242b1533caaf48cbe5f/src/compiler/standard_lib.rs#L31 On the other hand |
|
I was planning on making it a dependency of |
2b1ab0a to
6f99176
Compare
-Ldependency search paths for injected crates-Ldependency search paths for panic runtimes
|
For panic runtimes I implemented #160007 (comment). |
This comment has been minimized.
This comment has been minimized.
3f3435c to
d0b6b13
Compare
|
@rustbot ready While debugging the last CI failure I realized that conditional resolution might fail for some targets when using prebuilt std. I found a much simpler fix: remove the |
This comment has been minimized.
This comment has been minimized.
d0b6b13 to
7283be6
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
3f51075 to
847ad1c
Compare
|
@bors delegate=try I'll r+ this in a ~week since this is blocking other work. |
|
✌️ @Bryanskiy, you can now perform try builds on this pull request! Warning You used the legacy format of the delegate command. You can now post |
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing 3ffb26f (parent) -> e081d66 (this PR) Test differencesShow 6 test diffsStage 1
Stage 2
Additionally, 2 doctest diffs were found. These are ignored, as they are noisy. Job group index
Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard e081d6616f3be5a96c6b42eecc6410f1a5378b7e --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (e081d66): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 3.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -2.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.1%, secondary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 476.994s -> 473.971s (-0.63%) |
View all comments
Part of build-std=always RFC.
This PR supports
-Ldependency=search paths for panic runtimes. This will allow Cargo to treat panic runtimes as regular transitive dependencies, rather than special-casing them.To do so:
only_rlibcheck. As a result the panic runtime is injected as a conditional dependency when buildingstdand is subsequently included instd's metadata. When building a crate that usesstd, the panic runtime is resolved throughresolve_crate_depsin the same way as any other transitive dependency.For a prebuilt
std(unlikebuild-std), the-Cpanic=option passed tostdmay differ from that passed to its dependents, so we might still need to inject another panic runtime as a direct dependency. However, this is not important in the context of prebuilt std.NoPanicStrategyis checked only forpanic_abort. We can compilepanic_unwindwith-Cpanic=abortfor some targets. This was previously overlooked.Summary of the history and discussions in this PR
PathKindfor injected dependencies was simply changed from-Lcrate=to-Ldependency, but this raised a concern. Bjorn3 suggested to include both panic runtimes as a dependency ofstdso we don't have to inject it as a dependency for any user ofstd. The correct one should then be activated later independency_format.rs.build-std=always, we might want to avoid buildingpanic_unwindwhen not necessary. From the compiler perspective we need to2.1. Either always resolve
panic_unwindand ignore any resulting error. (might lead to bugs)2.2. Or conditionally resolve
panic_unwind. Forbuild-stdwe might rely on-Cpanic=option for this in accordance with panic strategies but for prebuiltstdthis will fail for some targets.It was decided to relax the implementation so we can inject panic runtime as direct dependency for prebuilt
std.cc @adamgemmell