cargo-show-asm
cargo-show-asm copied to clipboard
thread 'main' panicked at 'No cdylib?'
I want to inspect wasm instructions using cargo-show-asm. When I run the command cargo asm -p my_lib --lib --release some_func --wasm
, I encounter an error that says:
"thread 'main' panicked at 'No cdylib?', /Users/oker/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-show-asm-0.2.21/src/main.rs:342:14 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace."
My library can be compiled into wasm without any issues, and I have specified in the cargo.toml file:
[lib]
crate-type = ["cdylib", "lib"]
Where does cargo-show-asm look for .dylib files? I see libxxx.dylib in the target/release directory, but copying it to another directory like deps doesn't seem to resolve the issue.
Try passing -vvv
for more details
https://github.com/pacak/cargo-show-asm/blob/master/src/main.rs#L334 - it happens around here, if c-s-a detects an artifact of cdylib
type - it tries to find it and fails if it's not compiled. I wonder if wasm changes something.
Can you make a smaller reproduction?
Managed to reproduce something similar, did some experiments. With crate-type = ["cdylib", "lib"]
rustc creates an .s
file but it's mostly empty and doesn't contain a test function I added in lib.rs
. A better reproduction might help. I suspect rust compiler or cargo handles ["cdylib"]
in a special way, I don't know much about it though. Removing ["cdylib"]
makes it work as expected.
I can revisit this again if you give me a smaller reproduction that does what you want it to do. Or once I know more about wasm.
Try passing
-vvv
for more details
This is the execution result of cargo asm with the -vvv option.
Running `CARGO=/Users/oker/.rustup/toolchains/nightly-2022-11-23-x86_64-apple-darwin/bin/cargo CARGO_CRATE_NAME=mylib_wasm CARGO_MANIFEST_DIR=/Users/oker/code/github/okex/mylib-wasm/core/lib/mylib CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=mylib_wasm CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 DYLD_FALLBACK_LIBRARY_PATH='/Users/oker/code/github/okex/mylib-wasm/target/release/deps:/Users/oker/.rustup/toolchains/nightly-2022-11-23-x86_64-apple-darwin/lib:/Users/oker/.rustup/toolchains/nightly-2022-11-23-x86_64-apple-darwin/lib:/Users/oker/lib:/usr/local/lib:/usr/lib' rustc --crate-name mylib_wasm --edition=2021 core/lib/mylib/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type cdylib --crate-type lib --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no --emit asm -Ccodegen-units=1 -Cdebuginfo=2 --cfg 'feature="zkwasm"' -C metadata=5587bcb9bccba4e1 --out-dir /Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/deps --target wasm32-unknown-unknown -L dependency=/Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/deps -L dependency=/Users/oker/code/github/okex/mylib-wasm/target/release/deps --extern num_bigint=/Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/deps/libnum_bigint-cde64e92b534153f.rlib --extern num_traits=/Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/deps/libnum_traits-7c1a02c2bc62590b.rlib --extern primitive_types=/Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/deps/libprimitive_types-4d1b4aca39aff137.rlib --extern sha3=/Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/deps/libsha3-3b9b8ba422f4e373.rlib --extern static_assertions=/Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/deps/libstatic_assertions-b3ca28a0812ddf16.rlib --extern wasm_bindgen=/Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/deps/libwasm_bindgen-8aab294c2d7bc213.rlib --extern zkwasm_rust_sdk=/Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/deps/libzkwasm_rust_sdk-3ad1d5222296d6ea.rlib`
Artifact files: [ Finished release [optimized] target(s) in 10.55s
"/Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/mylib_wasm.wasm", "/Users/oker/code/github/okex/mylib-wasm/target/wasm32-unknown-unknown/release/libmylib_wasm.rlib"]
thread 'main' panicked at 'No cdylib?', /Users/oker/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-show-asm-0.2.21/src/main.rs:342:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Can you make a smaller reproduction?
https://github.com/cwbhhjl/cargo-asm-wasm-test
I tried creating a small project following the structure of my main project, and can reproduce the same issue.
Managed to reproduce something similar, did some experiments. With
crate-type = ["cdylib", "lib"]
rustc creates an.s
file but it's mostly empty and doesn't contain a test function I added inlib.rs
. A better reproduction might help. I suspect rust compiler or cargo handles["cdylib"]
in a special way, I don't know much about it though. Removing["cdylib"]
makes it work as expected.I can revisit this again if you give me a smaller reproduction that does what you want it to do. Or once I know more about wasm.
Wow, after changing the lib type from ["cdylib", "lib"] to ["lib"], cargo asm can show wasm instructions. However, at this point, I can no longer generate wasm for my project using wasm-pack. It prompts me to add the cdylib type in the toml file.
Made a ticket upstream, we'll see.
Works now on your repro example after I update nightly version to today's date.