Building Rust functions for Node.js to take advantage of Rust's performance, WebAssembly's security and portability, and JavaScript's ease-of-use. Demo code and recipes.
The error log will be very confusing if someone forgets to add the target before building for the first time.
root@TW59:~/wasm-learning/cli/hello# cargo build --target wasm32-wasi
Compiling hello v0.1.0 (/root/wasm-learning/cli/hello)
error[E0463]: can't find crate for `std`
|
= note: the `wasm32-wasi` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-wasi`
error[E0463]: can't find crate for `std`
--> src/main.rs:1:5
|
1 | use std::env;
| ^^^ can't find crate
|
= note: the `wasm32-wasi` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-wasi`
error: cannot find macro `println` in this scope
--> src/main.rs:6:5
|
6 | println!("{}", argument);
| ^^^^^^^
error: cannot find macro `println` in this scope
--> src/main.rs:4:3
|
4 | println!("hello");
| ^^^^^^^
error[E0433]: failed to resolve: use of undeclared crate or module `env`
--> src/main.rs:5:19
|
5 | for argument in env::args().skip(1) {
| ^^^ use of undeclared crate or module `env`
error: requires `sized` lang_item
Some errors have detailed explanations: E0433, E0463.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `hello` due to 6 previous errors
Reference:
WASI-tutorial.md this file gives an shell example with add target.
The
hello
file does not mentionrustup target add wasm32-wasi
before building as a beginner example. I believe it is better for newcomers.https://github.com/second-state/wasm-learning/blob/191de35732458d017f3c26b31f9df02aba822c45/cli/hello/README.md?plain=1#L11-L16
The error log will be very confusing if someone forgets to add the target before building for the first time.
Reference:
WASI-tutorial.md this file gives an shell example with
add target
.