mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-05 09:23:31 +00:00
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. This will allow Cargo to treat panic runtimes as regular transitive dependencies, rather than special-casing them. To do so: 1. During panic runtime injection we remove the early‑return `only_rlib` check. As a result the panic runtime is injected as a conditional dependency when building `std` and is subsequently included in `std`'s metadata. When building a crate that uses `std`, the panic runtime is resolved through `resolve_crate_deps` in the same way as any other transitive dependency. </br> For a prebuilt `std` (unlike `build-std`), the `-Cpanic=` option passed to `std` may 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. 2. `NoPanicStrategy` is checked only for `panic_abort`. We can compile `panic_unwind` with `-Cpanic=abort` for some targets. This was previously overlooked. #### Summary of the history and discussions in this PR 1. In the first iteration of this PR `PathKind` for injected dependencies was simply changed from `-Lcrate=` to `-Ldependency`, but this raised a [concern](https://github.com/rust-lang/rust/pull/160007#issuecomment-5090756832). Bjorn3 [suggested](https://github.com/rust-lang/rust/pull/160007#issuecomment-5093637723) to include both panic runtimes as a dependency of `std` so we don't have to inject it as a dependency for any user of `std`. The correct one should then be activated later in `dependency_format.rs`. 2. In the second iteration Bjorn3's suggestion was implemented. The problem was that for `build-std=always`, we might want to avoid building `panic_unwind` when not necessary. From the compiler perspective we need to </br> 2.1. Either always resolve `panic_unwind` and ignore any resulting error. (might lead to bugs) 2.2. Or conditionally resolve `panic_unwind`. For `build-std` we might rely on `-Cpanic=` option for this in accordance with [panic strategies](https://rust-lang.github.io/rfcs/3874-build-std-always.html#panic-strategies) but for prebuilt `std` this will fail for some targets. </br> It was decided to relax the implementation so we can inject panic runtime as direct dependency for prebuilt `std`. 3. Third iteration: we are here cc @adamgemmell