How can I set default build target for Cargo?

22,735

Solution 1

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"

Solution 2

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

[build]
target = "my-custom-target"
Share:
22,735

Related videos on Youtube

antono
Author by

antono

Ruby, JavaScript, Linux,

Updated on July 09, 2022

Comments

  • antono
    antono almost 2 years

    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?

  • Usagi Ito
    Usagi Ito over 3 years
    Is it work expectedly too now? I got the warning: warning: unused manifest key: build using 1.47.0-nightly.
  • Jeff Muizelaar
    Jeff Muizelaar over 3 years
    Are you putting it in Cargo.toml?. You need to use .cargo/config
  • C. Dunn
    C. Dunn over 3 years
    Thank you! And for others reading this in the future, you can see what targets Rust supports using rustc --print target-list.
  • Peter Hansen
    Peter Hansen about 2 years
    @C.Dunn And if using rustup, you can do rustup target list as well.