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

build_std can't find crate for panic_abort #83805

Closed
Timmmm opened this issue Apr 3, 2021 · 5 comments
Closed

build_std can't find crate for panic_abort #83805

Timmmm opened this issue Apr 3, 2021 · 5 comments
Labels
C-bug Category: This is a bug.

Comments

@Timmmm
Copy link
Contributor

Timmmm commented Apr 3, 2021

I'm trying to build std for wasm32-unknown-unknown. I cloned the wasm template but compiling it gives this:

$ cargo +nightly build -Z build-std --target wasm32-unknown-unknown
...
   Compiling wasm-pack-template v0.1.0 (/Users/tim/wasm-pack-template)
error[E0463]: can't find crate for `panic_abort`

I tried adding the panic_abort crate from crates.io but it gives some other errors and I'm pretty sure I shouldn't have to.

Compiling with RUSTC_LOG=info gives a bit more info:

INFO rustc_metadata::creader panic runtime not found -- loading panic_abort
INFO rustc_metadata::creader resolving crate `panic_abort`
INFO rustc_metadata::creader falling back to a load
INFO rustc_metadata::locator lib candidate: /Users/tim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_abort-14c6721c1e3ddac4.rlib
INFO rustc_metadata::locator rlib reading metadata from: /Users/tim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_abort-14c6721c1e3ddac4.rlib
INFO rustc_metadata::locator Rejecting via proc macro: expected true got false
INFO rustc_metadata::locator metadata mismatch

As you can see it is looking for the wrong libpanic_abort.rlib! It's especially weird because it finds the right crate when it tries to resolve other ones, e.g:

INFO rustc_metadata::creader resolving crate `cfg_if`
INFO rustc_metadata::creader falling back to a load
INFO rustc_metadata::locator lib candidate: /Users/tim/wasm-pack-template/target/wasm32-unknown-unknown/debug/deps/libcfg_if-40fde05178aa587c.rlib
INFO rustc_metadata::locator lib candidate: /Users/tim/wasm-pack-template/target/wasm32-unknown-unknown/debug/deps/libcfg_if-40fde05178aa587c.rmeta
INFO rustc_metadata::locator rmeta reading metadata from: /Users/tim/wasm-pack-template/target/wasm32-unknown-unknown/debug/deps/libcfg_if-40fde05178aa587c.rmeta
INFO rustc_metadata::creader register crate `cfg_if` (cnum = 17. private_dep = false)

And it actually did successfully compile libpanic_abort.rlib for wasm:

$ ls -1 target/wasm32-unknown-unknown/debug/deps/*panic*
target/wasm32-unknown-unknown/debug/deps/console_error_panic_hook-837ce2b56de85633.d
target/wasm32-unknown-unknown/debug/deps/libconsole_error_panic_hook-837ce2b56de85633.rlib
target/wasm32-unknown-unknown/debug/deps/libconsole_error_panic_hook-837ce2b56de85633.rmeta
target/wasm32-unknown-unknown/debug/deps/libpanic_abort-5dadd1d612661286.rlib
target/wasm32-unknown-unknown/debug/deps/libpanic_abort-5dadd1d612661286.rmeta
target/wasm32-unknown-unknown/debug/deps/libpanic_unwind-e15a40c08ac4e7e5.rlib
target/wasm32-unknown-unknown/debug/deps/libpanic_unwind-e15a40c08ac4e7e5.rmeta
target/wasm32-unknown-unknown/debug/deps/panic_abort-5dadd1d612661286.d
target/wasm32-unknown-unknown/debug/deps/panic_unwind-e15a40c08ac4e7e5.d

Possibly related to #56228. I also made a thread about this here.

@Timmmm Timmmm added the C-bug Category: This is a bug. label Apr 3, 2021
@ehuss
Copy link
Contributor

ehuss commented Apr 3, 2021

This is a known issue (unfortunately), mainly tracked in rust-lang/wg-cargo-std-aware#29. The build-std feature doesn't know how to handle abort vs unwind targets, so it doesn't handle them automatically. wasm doesn't support unwinding, so it needs to use abort. You can force it by using -Zbuild-std=std,panic_abort.

@Timmmm
Copy link
Contributor Author

Timmmm commented Apr 3, 2021

Aha, that worked perfectly, thanks! Are the options for build-std documented anywhere? I guess I'll close this since it is tracked elsewhere.

@Timmmm Timmmm closed this as completed Apr 3, 2021
@ehuss
Copy link
Contributor

ehuss commented Apr 3, 2021

@TopDev1007
Copy link

I try all the feedback but it doesn't work successfully.

@Timmmm
Copy link
Contributor Author

Timmmm commented Apr 14, 2022

What error did you get? Coincidentally I did a talk about this yesterday and it still works for me.

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

3 participants