Failed opening './target/wasm32-unknown-unknown/release/*.wasm'

Hi. I am trying to create an optimized version of my contract.rs file using the command:

docker run --rm -v "$(pwd)":/contract --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry enigmampc/secret-contract-optimizer:1.0.9

but I keep getting the error

Finished release [optimized] target(s) in 56.54s
Failed opening './target/wasm32-unknown-unknown/release/*.wasm'

Even though i havent used any sudo commands . The way I run this is

  1. cargo build
  2. docker run --rm -v "$(pwd)":/contract --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry enigmampc/secret-contract-optimizer:1.0.9.

After the second command it gives error.

This is my code GitHub - mahamzaidi/secret

Try replacing this with cargo build --release

Also, might be useful to show the output of:

find ./target/wasm32-unknown-unknown/

Tried this and got the same error.

  1. Can you change that line to:
	cargo build --target=wasm32-unknown-unknown --release

and then show the output of find ./target/wasm32-unknown-unknown/ again ?

  1. Are you calling 'cargo build' from anywhere else ?
  1. This command says release [optimized] target(s) in 50.82s
    after build and find ./target/wasm32-unknown-unknown/ gives this output - Pastebin. Also same error after docker command.
  2. No I am calling the commands from my terminal.

Can you run:

cargo build --target=wasm32-unknown-unknown --release
find ./target | grep wasm$
env | grep CARGO_TARGET_DIR

without running any of the docker commands? This bisects the problem into "cargo build" vs "docker"

got this

Finished release [optimized] target(s) in 51.26s
./target/wasm32-unknown-unknown/release/.fingerprint/serde-json-wasm-b7bd4c7addc075d6/dep-lib-serde-json-wasm
./target/wasm32-unknown-unknown/release/.fingerprint/serde-json-wasm-b7bd4c7addc075d6/lib-serde-json-wasm

WASM requires the crate be a binary or of cdylib type - the latter being the actually supported, sensible type. Ensure you have cdylib in your manifest: Cargo.toml - Hello wasm-pack!

1 Like

Thanks! Adding this solved the issue

1 Like