Skip to content

Build std with panic = "abort" errors with a bunch of duplicated lang items #15347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xTachyon opened this issue Sep 19, 2023 · 9 comments
Closed
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself.

Comments

@xTachyon
Copy link

xTachyon commented Sep 19, 2023

Code

[profile.release]
panic = "abort"
rustup run nightly-2023-09-17 cargo rustc -p dune --profile release -Z build-std=std,core --target x86_64-pc-windows-msvc

The nightly version is not important, it's only what I was testing on.

Current output

A bunch of these:

error[E0152]: duplicate lang item in crate `core`: `sized`.
  |
  = note: the lang item is first defined in crate `core` (which `std` depends on)
  = note: first definition in `core` loaded from \\?\D:\repos\dune\target\x86_64-pc-windows-msvc\release\deps\libcore-8e933d06c178c4de.rlib, \\?\D:\repos\dune\target\x86_64-pc-windows-msvc\release\deps\libcore-8e933d06c178c4de.rmeta
  = note: second definition in `core` loaded from \\?\C:\Users\tachyon\.rustup\toolchains\nightly-2023-08-17-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcore-b86a9ba077d96bbb.rlib

Desired output

A nice message that said panic_abort must be included in build-std if compiled with panic = "abort".

Rationale and extra context

From @Nilstrieb:
rustc can't find a panic_abort in your self-built standard library, so it falls back to loading panic_abort from the sysroot. But that sysroot panic_abort then also brings in the rest of the sysroot, including core, so now you have two cores, one from your target dir and one from your sysroot. This is bad.

Other cases

No response

Anything else?

No response

@xTachyon xTachyon added the A-diagnostics Area: Error and warning messages generated by Cargo itself. label Sep 19, 2023
@Noratrieb
Copy link
Member

Probably makes sense to have a specialized error message when loading core twice.

@klensy
Copy link
Contributor

klensy commented Sep 20, 2023

@Enselic
Copy link
Member

Enselic commented Nov 29, 2024

Triage: Since for this particular issue it is needed to parse Cargo.toml, I think this should be moved to the cargo repo, right? Cargo knows what is in Cargo.toml and what is passed to -Z build-std=..., so it knows when to report a nice error.

@Noratrieb
Copy link
Member

I think it would make sense for cargo to not allow this, if it does have all the necessary knowledge. But it would also be nice for rustc to detect cases like this better (I've also encountered this in other cursed cases).

@Enselic
Copy link
Member

Enselic commented Dec 3, 2024

I'm sure there are ways to improve the error message (although personally I think it is quite informative already), but as the original issue was written, I think it needs to be moved to the cargo project. Keeping the issue in this issue track makes the cargo people not see it.

If it was easy to file a corresponding high-quality issue intended for the rust repo I would do it, but unfortunately it's not clear to me how to write such an issue and make it high quality. For example: I lack awareness of a concrete example for easy reproduction without using cargo.

@SaltyKitkat
Copy link

I'm just curious that why we don't have panic related things rebuilt when using -Zbuild-std?

@Enselic
Copy link
Member

Enselic commented Mar 24, 2025

@rustbot transfer cargo

@rustbot rustbot transferred this issue from rust-lang/rust Mar 24, 2025
@ehuss
Copy link
Contributor

ehuss commented Mar 24, 2025

I'm going to close as this is generally a known problem tracked in rust-lang/wg-cargo-std-aware#29 and rust-lang/wg-cargo-std-aware#31.

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Mar 24, 2025
@weihanglo
Copy link
Member

And also #7359, which is exactly the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself.
Projects
None yet
Development

No branches or pull requests

7 participants