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
?
Cargo stores the output of a build into the "target" directory. By default, this is the directory named target in the root of your workspace.
Cargo can also be configured through environment variables in addition to the TOML configuration files. For each configuration key of the form foo. bar the environment variable CARGO_FOO_BAR can also be used to define the value.
cargo build --release puts the resulting binary in target/release instead of target/debug . Compiling in debug mode is the default for development-- compilation time is shorter since the compiler doesn't do optimizations, but the code will run slower. Release mode takes longer to compile, but the code will run faster.
Cargo resolves all dependencies of your project, downloads missing dependencies, and compiles it using the rustc compiler. By default, projects are built and compiled in debug mode. For information on compiling your project in release mode, see Building a Rust project in release mode. An existing Rust project.
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
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With