简体   繁体   English

Rust Cargo 为特定 CPU 构建和交叉编译

[英]Rust Cargo build and crosscompile for specific CPU

I want to compile two binaries for different target architectures (eg. Skylake and Sandy Bridge).我想为不同的目标架构(例如 Skylake 和 Sandy Bridge)编译两个二进制文件。 These are usually two lengthy cargo commands:这些通常是两个冗长的货物命令:

RUSTFLAGS="-C target-cpu=skylake" cargo build --target x86_64-unknown-linux-gnu --release RUSTFLAGS="-C target-cpu=skylake" 货物构建 --target x86_64-unknown-linux-gnu --release

How can I set up cargo to build both binaries (with different names) from the same main.rs automatically?如何设置货物以自动从同一个 main.rs 构建两个二进制文件(具有不同名称)? Ideally in either the config.toml or the Cargo.toml so I can add it to a repository.理想情况下在config.tomlCargo.toml以便我可以将其添加到存储库中。

You can add the following text to your config.toml :您可以将以下文本添加到config.toml

[build]
target = x86_64-unknown-linux-gnu
rustflags = ["-C","target-cpu=skylake"]

[profile.dev]   #do not need to add `--release` now
opt-level = 3
debug = false
debug-assertions = false
overflow-checks = false
lto = false
panic = 'unwind'
incremental = false
codegen-units = 16
rpath = false

But it seems like it can't compile for two different target architectures with one config.toml , so you may have to create two config.toml and use cargo --manifest-path PATH/TO/CONFIG to compile two binaries separately.但是它似乎无法使用一个config.toml为两个不同的目标架构进行编译,因此您可能必须创建两个config.toml并使用cargo --manifest-path PATH/TO/CONFIG来分别编译两个二进制文件。

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

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