# Cargo: Passing a RUSTFLAGS and specifying a target

**URL:** <https://users.rust-lang.org/t/cargo-passing-a-rustflags-and-specifying-a-target/18673>\
**Category:** help\
**Created:** [July 11, 2018, 2:33am UTC](https://users.rust-lang.org/t/cargo-passing-a-rustflags-and-specifying-a-target/18673 "2018-07-11T02:33:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbalicki2](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/rbalicki2/32/4272_2.png) [@rbalicki2](https://users.rust-lang.org/u/rbalicki2)\
**Post date:** [July 11, 2018, 2:33am UTC](https://users.rust-lang.org/t/cargo-passing-a-rustflags-and-specifying-a-target/18673/1 "2018-07-11T02:33:47Z")

</div>

Hi folks,

I'm not sure if there's a better place to ask, but happy to re-ask there if there's a better place. I'm attempting to use cargo to do something like

```rust
RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo +nightly build --verbose --target wasm32-unknown-unknown

```

A dependency of mine must be compiled with the `procmacro2_semver_exempt` flag. However, if I run the above, that flag gets lost.

If I run

```rust
RUSTFLAGS='--cfg procmacro2_semver_exempt --target wasm32-unknown-unknown' cargo +nightly build --verbose

```

It complains that

```rust
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --cfg procmacro2_semver_exempt --target wasm32-unknown-unknown --target x86_64-apple-darwin --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro` (exit code: 101)
--- stderr
error: Option 'target' given more than once

```

Is there any way pass the RUSTFLAGS and also specify a target? Any help is appreciated!

Thank you!  
Robert

Edit: From the cargo book, it seems like using RUSTFLAGS the way I did should work:

```rust
RUSTFLAGS — A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast with cargo rustc, this is useful for passing a flag to all compiler instances.

```

Edit2: This also doesn't appear to work with .cargo/config 😕

Edit3: 😭 [https://github.com/rust-lang/cargo/issues/4423](https://github.com/rust-lang/cargo/issues/4423)

---

<div class="post-metadata">

**Author:** ![Michael-F-Bryan](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/michael-f-bryan/32/28749_2.png) [@Michael-F-Bryan](https://users.rust-lang.org/u/Michael-F-Bryan)\
**Post date:** [July 11, 2018, 4:27am UTC](https://users.rust-lang.org/t/cargo-passing-a-rustflags-and-specifying-a-target/18673/2 "2018-07-11T04:27:03Z")

</div>

Can't you just update your `Cargo.toml` to explicitly use the `procmacro2_semver_exempt` feature? That means you'd write something like `some-library = { version = "1.2.3", features = ["procmacro2_semver_exempt "] }` under the `[dependencies]` table ([manifest docs](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#choosing-features)).

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steffahn/32/47569_2.png) [@steffahn](https://users.rust-lang.org/u/steffahn)\
**Post date:** [January 12, 2023, 8:48am UTC](https://users.rust-lang.org/t/cargo-passing-a-rustflags-and-specifying-a-target/18673/3 "2023-01-12T08:48:41Z")

</div>


