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.
|
r? @bjorn3 |
|
@rustbot ready |
|
@bors r+ |
allow `-Ldependency` search paths for panic runtimes Part of [build-std=always RFC](https://rust-lang.github.io/rfcs/3874-build-std-always.html). This PR supports `-Ldependency=` search paths for panic runtimes. To do so, both panic runtimes (or one if the other hasn't been built) are injected as conditional dependencies of `std` during crate resolution. Therefore, the panic runtimes will be present in the `std` metadata and loaded like regular transitive dependencies, rather than being injected as a direct dependency. The activation of one particular runtime happens later in `dependency_format.rs`, based on the desired strategy. This will allow Cargo to treat panic runtimes as regular transitive dependencies, rather than special-casing them. cc @adamgemmell
|
💔 I suspect this PR failed tests as part of a rollup After fixing the problem, consider running a try job for the failed job before re-approving. Link to failure: #160278 (comment) |
|
This pull request was unapproved. This PR was contained in a rollup (#160278), which was unapproved. |
My test with |
|
implemented #160007 (comment) |
View all comments
Part of build-std=always RFC.
This PR supports
-Ldependency=search paths for panic runtimes.To do so, both panic runtimes (or one if the other hasn't been built) are injected as conditional dependencies of
stdduring crate resolution. Therefore, the panic runtimes will be present in thestdmetadata and loaded like regular transitive dependencies, rather than being injected as a direct dependency. The activation of one particular runtime happens later independency_format.rs, based on the desired strategy.This will allow Cargo to treat panic runtimes as regular transitive dependencies, rather than special-casing them.
cc @adamgemmell