Passing target feature flag to rustc via cargo config file

When compiling a WASM module with the multivalue target feature flag, I'd like to use Cargo rather than rustc directly.

However, I can't get cargo to pass this target feature flag to rustc.

I've tried creating a .cargo/config.toml file in the project with the following contents:

[build]
rustflags = ["target-feature=+multivalue"]

But that gets me the following error:

cargo build --target wasm32-unknown-unknown
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names target-feature=+multivalue --target wasm32-unknown-unknown --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit code: 1)
  --- stderr
  error: multiple input filenames provided (first two filenames are `-` and `target-feature=+multivalue`)

The only command I have got to work successfully is by invoking rustc:

cargo rustc -v --crate-type=cdylib --target wasm32-unknown-unknown -- -C target-feature=+multivalue

I really would like the config file to work so that I can use the bog standard cargo build --target command. What am I doing wrong?

[build]
- rustflags = ["target-feature=+multivalue"]
+ rustflags = ["-C", "target-feature=+multivalue"] 

It might also be wise to put this under a target-specific header:

[target."wasm32-unknown-unknown"]
rustflags = ["-C", ...]
1 Like

Thank you. Didn't realise I still needed the -C but it makes total sense!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.