rust-lang / wg-cargo-std-aware

Repo for working on "std aware cargo"
133 stars 8 forks source link

"duplicate lang item in crate `core`" when building #71

Closed TheBlueMatt closed 2 years ago

TheBlueMatt commented 2 years ago

With current nightly, on x86_64 linux (and reproduced on a friend's machine, linking fails when building with -Zbuild-std. It appears to be trying to link libstd twice, and results in a billion and one error messages, starting with the one below.

cargo +nightly build -Zbuild-std --target x86_64-unknown-linux-gnu -v

error: duplicate lang item in crate `core`: `bool`.
  |
  = note: the lang item is first defined in crate `core` (which `ldk` depends on)
  = note: first definition in `core` loaded from /home/matt/Documents/Projects/Bitcoin/ldk-c-bindings/lightning-c-bindings/target/x86_64-unknown-linux-gnu/debug/deps/libcore-0df5b54d697e5761.rlib, /home/matt/Documents/Projects/Bitcoin/ldk-c-bindings/lightning-c-bindings/target/x86_64-unknown-linux-gnu/debug/deps/libcore-0df5b54d697e5761.rmeta
  = note: second definition in `core` loaded from /home/matt/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-9924c22ae1efcf66.rlib
$ rustc +nightly --version --verbose
rustc 1.55.0-nightly (952fdf2a1 2021-07-05)
binary: rustc
commit-hash: 952fdf2a1119affa1b37bcacb0c49cf9f0168ac8
commit-date: 2021-07-05
host: x86_64-unknown-linux-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1
$ cargo +nightly --version --verbose
cargo 1.55.0-nightly (3ebb5f15a 2021-07-02)
release: 1.55.0
commit-hash: 3ebb5f15a940810f250b68821149387af583a79e
commit-date: 2021-07-02
ehuss commented 2 years ago

Can you put together a small reproduction, or is there a public project where this happens?

TheBlueMatt commented 2 years ago

Sorry for the delay, this should reproduce:

git clone https://git.bitcoin.ninja/ldk-c-bindings
cd ldk-c-bindings/
git checkout 2021-07-testcase
cd lightning-c-bindings
cargo +nightly build -Zbuild-std --target x86_64-unknown-linux-gnu -v
ehuss commented 2 years ago

Ah. The reason is that it is using panic="abort". A workaround for now is to use -Zbuild-std=std,panic_abort.

I believe this is essentially the same as #56 (and #29), so closing in favor of those.