Stream: general

Topic: running example wasi


view this post on Zulip celine santosh (Jul 15 2024 at 05:55):

HI

I was trying to run one of the examples which is wasi, main.rs file.
these are the two commands I executed.
cmake examples/
cargo run --example wasi

but I Gott he following error

error:** failed to run custom build command for test-programs-artifacts v0.0.0 (/Users/celinesantosh/Desktop/sem_5/wasmtime/crates/test-programs/artifacts)

Caused by:

process didn't exit successfully: /Users/celinesantosh/Desktop/sem_5/wasmtime/target/debug/build/test-programs-artifacts-22b912d9b572dd6f/build-script-build (exit status: 101)

--- stdout

cargo:rerun-if-changed=../../wasi-preview1-component-adapter

--- stderr

running: env -u CARGO_ENCODED_RUSTFLAGS CARGO_TARGET_DIR="/Users/celinesantosh/Desktop/sem_5/wasmtime/target/debug/build/test-programs-artifacts-2e8e593f7698d1fd/out" RUSTFLAGS="" "cargo" "build" "--release" "--package=wasi-preview1-component-adapter" "--target=wasm32-unknown-unknown"

Compiling indexmap v2.2.6

Compiling serde_json v1.0.107

Compiling serde_derive v1.0.188

Compiling memchr v2.5.0

Compiling prettyplease v0.2.20

Compiling byte-array-literals v24.0.0 (/Users/celinesantosh/Desktop/sem_5/wasmtime/crates/wasi-preview1-component-adapter/byte-array-literals)

Compiling wit-bindgen-rust-macro v0.27.0

Compiling object v0.36.0

Compiling wasi v0.11.0+wasi-snapshot-preview1

error[E0463]: can't find crate for core

|

= note: the wasm32-unknown-unknown target may not be installed

= help: consider downloading the target with rustup target add wasm32-unknown-unknown

= help: consider building the standard library from source with cargo build -Zbuild-std

For more information about this error, try rustc --explain E0463.

error: could not compile wasi (lib) due to 1 previous error

warning: build failed, waiting for other jobs to finish...

thread 'main' panicked at crates/test-programs/artifacts/build.rs:138:5:

assertion failed: status.success()

note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...**

view this post on Zulip Ryan Levick (rylev) (Jul 15 2024 at 08:15):

The solution is buried a bit in the output, but it's there:

= note: the wasm32-unknown-unknown target may not be installed

= help: consider downloading the target with rustup target add wasm32-unknown-unknown

view this post on Zulip Ryan Levick (rylev) (Jul 15 2024 at 08:16):

If you run that rustup command, that should fix the issue.

view this post on Zulip celine santosh (Jul 15 2024 at 09:46):

that fixed it but still I am encountering issues.

MacBook-Air-2 wasmtime % cargo run --example wasi-async

Compiling wasmtime-cli v24.0.0 (/Users/celinesantosh/Desktop/sem_5/wasmtime)

Finished dev profile [unoptimized + debuginfo] target(s) in 3.81s

Running target/debug/examples/wasi-async

Error: failed to read input file: target/wasm32-wasi/debug/wasi.wasm

Caused by:

No such file or directory (os error 2)

view this post on Zulip Ralph (Jul 15 2024 at 10:11):

I'm going to ask the obvious question: is there such a file or directory?

view this post on Zulip Joel Dice (Jul 15 2024 at 12:11):

I don't think cargo run works for wasm32-wasi binaries. You'll need to use e.g. 'wasmtime run' to run the output, or else consider using https://github.com/bytecodealliance/cargo-wasi

A lightweight Cargo subcommand to build Rust code for the `wasm32-wasi` target - bytecodealliance/cargo-wasi

view this post on Zulip celine santosh (Jul 16 2024 at 12:25):

Hi

thanks a lot for the quick replies.
For the wasi example , in the main.rs file I changed the path to /target/wasm32-wasi/release/wasi.wasm.
I found that the wasi.wasm was being generated at this location. So I changed the main.rs file and now it prints the output.

view this post on Zulip Ralph (Jul 16 2024 at 12:38):

Yay! !


Last updated: Nov 22 2024 at 16:03 UTC