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 pull request was unapproved. This PR was contained in a rollup (#160278), which was unapproved. |
My test with |
|
implemented #160007 (comment) |
|
@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
…uwer Rollup of 21 pull requests Successful merges: - #159844 (Subtree cg_gcc sync (2026-07-24)) - #159326 (Deny multiple EII impls on a single item) - #159535 (Optimize slice::contains for bytewise types) - #159595 (Promote loongarch32-unknown-none* to Tier 2) - #160007 (allow `-Ldependency` search paths for panic runtimes) - #160320 (point at trait definition when it is used as a derive macro) - #160369 (When suggesting method names, prefer *exact* doc aliases over similar names) - #160406 (`DepKind` cleanups) - #160424 (Use `thread::available_parallelism` as the default limit for backend parallelism) - #159014 ([rustdoc] Do not take `doc(cfg())` into account when filtering doctests) - #159303 (Fix ICE for direct inline const generic defaults) - #159977 (Add regression test for bool indexing codegen) - #160165 (reject `...` without pattern post-expansion) - #160295 (Fix rustdoc ICE when checking if a generic arg can be elided) - #160305 (Linkify C-SKY targets in `platform-support.md`) - #160314 (fix borrowck ICE for consts with fn pointer type) - #160322 (ElaborateBoxDeref: remove unnecessary projection) - #160338 (Add regression test for supertrait associated type normalization through dyn) - #160340 (Add regression test for unused_parens on contract clauses) - #160371 (Add doc aliases for transpositions `read_exact_buf` and `read_exact_buf_at`) - #160384 (Add PR body notes for Cargo lock file maintenance)
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
…uwer Rollup of 23 pull requests Successful merges: - #153749 (Account for ownership mismatch on argument that doesn't meet bound) - #159326 (Deny multiple EII impls on a single item) - #159535 (Optimize slice::contains for bytewise types) - #159595 (Promote loongarch32-unknown-none* to Tier 2) - #160007 (allow `-Ldependency` search paths for panic runtimes) - #160184 (Add -Zinstrument-mcount={fentry-nop-record,fentry-record}) - #160320 (point at trait definition when it is used as a derive macro) - #160369 (When suggesting method names, prefer *exact* doc aliases over similar names) - #160406 (`DepKind` cleanups) - #160424 (Use `thread::available_parallelism` as the default limit for backend parallelism) - #159303 (Fix ICE for direct inline const generic defaults) - #159977 (Add regression test for bool indexing codegen) - #160011 (remove InterpError::map_err_info) - #160165 (reject `...` without pattern post-expansion) - #160295 (Fix rustdoc ICE when checking if a generic arg can be elided) - #160305 (Linkify C-SKY targets in `platform-support.md`) - #160314 (fix borrowck ICE for consts with fn pointer type) - #160322 (ElaborateBoxDeref: remove unnecessary projection) - #160338 (Add regression test for supertrait associated type normalization through dyn) - #160340 (Add regression test for unused_parens on contract clauses) - #160371 (Add doc aliases for transpositions `read_exact_buf` and `read_exact_buf_at`) - #160384 (Add PR body notes for Cargo lock file maintenance) - #160435 (bump tracing-tree)
|
💔 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: #160455 (comment) Probably this PR? |
|
This pull request was unapproved. This PR was contained in a rollup (#160455), which was unapproved. |
This comment has been minimized.
This comment has been minimized.
allow `-Ldependency` search paths for panic runtimes try-job: aarch64-apple
|
💔 Test for 5dfe67d failed: CI. Failed job:
|
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
|
|
Lines 75 to 81 in c9ff496 -Cpanic=abort, but I guess -Zbuild-std currently ignores that. Would it be possible to temporarily hard code -Cpanic=abort for panic_abort in cargo?
|
The whole point of this change is to remove the use of panic runtimes from Cargo. Otherwise, we could just pass them with --extern |
I mean temporarily until cargo respects |
|
Removed my last comment, I think I misunderstood the premise. If the issue only happens when panic_abort is passed via --extern, yes hardcoding panic abort in Cargo temporarily seems fine. You could also just remove panic_abort from the list of crates if you're sure they're no longer need to be specified. |
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