Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set default build target for Cargo?

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?

like image 955
antono Avatar asked Mar 23 '18 15:03

antono


People also ask

Where does cargo build output to?

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.

How do you set up cargo?

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.

What does cargo build -- Release do?

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.

What cargo build does?

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.


2 Answers

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"
like image 145
mexus Avatar answered Oct 17 '22 08:10

mexus


As listed in the Cargo documentation, you can create a .cargo/config and specify the target:

[build]
target = "my-custom-target"
like image 28
Shepmaster Avatar answered Oct 17 '22 10:10

Shepmaster