I want to compile two binaries for different target architectures (eg. Skylake and Sandy Bridge). These are usually two lengthy cargo commands:
RUSTFLAGS="-C target-cpu=skylake" cargo build --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?
Ideally in either the config.toml or the Cargo.toml so I can add it to a repository.
You can add the following text to your 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.
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