Skip to content
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

Error when building with panic = "abort" and -Z build-std #80685

Closed
dalcde opened this issue Jan 4, 2021 · 4 comments
Closed

Error when building with panic = "abort" and -Z build-std #80685

dalcde opened this issue Jan 4, 2021 · 4 comments
Labels
C-bug Category: This is a bug.

Comments

@dalcde
Copy link
Contributor

dalcde commented Jan 4, 2021

EDIT: The same happens with building an (empty) binary crate with panic = "abort" and -Z build-std, without cross-compilation

Create an empty library crate with crate-type = ["cdylib"]. Then attempt to build with

cargo +nightly build -Z build-std --target wasm32-unknown-unknown

Then you get lots of errors of the form

error: duplicate lang item in crate `core`: `RangeToInclusive`.
  |
  = note: the lang item is first defined in crate `core` (which `std` depends on)
  = note: first definition in `core` loaded from /tmp/foobar/target/wasm32-unknown-unknown/debug/deps/libcore-7e733f1b75b6332e.rlib, /tmp/foobar/target/wasm32-unknown-unknown/debug/deps/libcore-7e733f1b75b6332e.rmeta
  = note: second definition in `core` loaded from /home/$USER/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-73412d1456c20040.rlib

This works if either cdylib, build-std or cross-compiling to wasm32-unknown-unknown is removed. I have not attempted to cross-compile to other architectures.

Meta

This is using rustc 1.51.0-nightly (80184183b 2021-01-03)

@dalcde
Copy link
Contributor Author

dalcde commented Jan 6, 2021

I tried to rmove the directory /home/$USER/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-73412d1456c20040.rlib. What I get is

...
   Compiling test_ v0.1.0 (/tmp/test_)
error[E0463]: can't find crate for `panic_abort`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `test_`

To learn more, run the command again with --verbose.

@dalcde
Copy link
Contributor Author

dalcde commented Jan 6, 2021

Running cargo build with -v gives

Running `rustc --crate-name test_ --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type cdylib --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=31d921365bf56f2f --out-dir /tmp/test_/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/tmp/test_/target/wasm32-unknown-unknown/debug/incremental -L dependency=/tmp/test_/target/wasm32-unknown-unknown/debug/deps -L dependency=/tmp/test_/target/debug/deps --extern 'noprelude:alloc=/tmp/test_/target/wasm32-unknown-unknown/debug/deps/liballoc-72b348a1b400a2d6.rlib' --extern 'noprelude:compiler_builtins=/tmp/test_/target/wasm32-unknown-unknown/debug/deps/libcompiler_builtins-5f05eb2fe9129705.rlib' --extern 'noprelude:core=/tmp/test_/target/wasm32-unknown-unknown/debug/deps/libcore-7e733f1b75b6332e.rlib' --extern 'noprelude:panic_unwind=/tmp/test_/target/wasm32-unknown-unknown/debug/deps/libpanic_unwind-8d4d61c87153bded.rlib' --extern 'noprelude:proc_macro=/tmp/test_/target/wasm32-unknown-unknown/debug/deps/libproc_macro-e8cb90b4a1a8b576.rlib' --extern 'noprelude:std=/tmp/test_/target/wasm32-unknown-unknown/debug/deps/libstd-65633797cc840a5f.rlib' -Z unstable-options`

Manually running this command and adding

--extern 'noprelude:panic_abort=/tmp/test_/target/wasm32-unknown-unknown/debug/deps/libpanic_abort-fae018c7a2b94f26.rlib'

at the end makes it proceed

@dalcde dalcde changed the title Duplicate lang item when cross-compiling cdylib with build-std Error when building with panic = "abort" and -Z build-std Jan 6, 2021
@dalcde
Copy link
Contributor Author

dalcde commented Jan 6, 2021

The same bug is triggered when building an empty binary with -Z build-std and panic = "abort", without needing to cross-compile and/or use cdylib. The effect of cross-compiling to wasm32-unknown-unknown was simply to trigger panic = "abort". I have updated the issue title accordingly

@dalcde
Copy link
Contributor Author

dalcde commented Jan 6, 2021

Closing as duplicate of #69090, rust-lang/wg-cargo-std-aware#29 . Fixed by setting -Z build-std=panic_abort,std

@dalcde dalcde closed this as completed Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant