简体   繁体   English

如何为 Cargo 设置默认构建目标?

[英]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:我尝试使用 本教程在 Rust 中制作“Hello World”,但构建命令有点冗长:

cargo +nightly build --target wasm32-unknown-unknown --release

Is it possible to set the default target for cargo build ?是否可以为cargo build设置默认目标?

You could use a Cargo configuration file to specify a default target-triple for your project.您可以使用Cargo 配置文件为您的项目指定一个默认的目标三元组。 In your project's root, create a .cargo directory and a config file in it with the following contents:在项目的根目录中,创建一个.cargo目录和一个包含以下内容的config文件:

[build]
target = "wasm32-unknown-unknown"

As listed in the Cargo documentation , you can create a .cargo/config and specify the target:正如Cargo 文档中所列,您可以创建一个.cargo/config并指定目标:

[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如果您能够使用不稳定的功能,请遵循文档,尤其是per-package-target功能,将其添加到通常名为 Cargo.toml 的板条箱清单中

cargo-features = ["per-package-target"]

[package]
forced-target = "wasm32-unknown-unknown"
# and/or:
default-target = "wasm32-unknown-unknown"

This requires nightly toolchain.这需要夜间工具链。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM