I tried to make 'Hello World' in Rust using this tutorial, but the build command is a bit verbose:
cargo +nightly build --target wasm32-unknown-unknown --release
Is it possible to set the default target for cargo build
?
I tried to make 'Hello World' in Rust using this tutorial, but the build command is a bit verbose:
cargo +nightly build --target wasm32-unknown-unknown --release
Is it possible to set the default target for cargo build
?
You could use a Cargo configuration file to specify a default target-triple for your project. In your project's root, create a .cargo
directory and a config.toml
file in it with the following contents:
[build]
target = "wasm32-unknown-unknown"
As listed in the Cargo documentation, you can create a .cargo/config
and specify the target:
[build]
target = "my-custom-target"
If you're able to use unstable features, following documentation and especially per-package-target
feature add this to you crate manifest that usually named Cargo.toml
cargo-features = ["per-package-target"]
[package]
forced-target = "wasm32-unknown-unknown"
# and/or:
default-target = "wasm32-unknown-unknown"
This requires nightly toolchain.