# How do I specify parameters to pass to \`rustc\` when building using dfx?

**URL:** <https://forum.dfinity.org/t/how-do-i-specify-parameters-to-pass-to-rustc-when-building-using-dfx/15385>\
**Category:** Rust\
**Created:** [September 12, 2022, 4:51pm UTC](https://forum.dfinity.org/t/how-do-i-specify-parameters-to-pass-to-rustc-when-building-using-dfx/15385 "2022-09-12T16:51:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [September 12, 2022, 4:51pm UTC](https://forum.dfinity.org/t/how-do-i-specify-parameters-to-pass-to-rustc-when-building-using-dfx/15385/1 "2022-09-12T16:51:49Z")

</div>

I want to use the `cfg!` [macro](https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-macro) to conditionally inject values depending on whether I’m running on dev or mainnet.

I imagine using `cfg` would be the best way to do this as environment variables are not available for the `wasm32-unknown-unknown` target as far as I’m able to figure out trying out the `std::env::var` module.

What’s the easiest way to execute conditional code depending on what environment canisters are being run on? Thoughts?

---

<div class="post-metadata">

**Author:** ![ericswanson](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ericswanson/32/622_2.png) [@ericswanson](https://forum.dfinity.org/u/ericswanson)\
**Post date:** [September 13, 2022, 8:49am UTC](https://forum.dfinity.org/t/how-do-i-specify-parameters-to-pass-to-rustc-when-building-using-dfx/15385/2 "2022-09-13T08:49:59Z")

</div>

You should be able to use the `env!` macro, which is evaluated at compile time. The `DFX_NETWORK` environment variable will always be set, typically to either `local` or `ic`.

---

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [September 13, 2022, 10:18am UTC](https://forum.dfinity.org/t/how-do-i-specify-parameters-to-pass-to-rustc-when-building-using-dfx/15385/3 "2022-09-13T10:18:05Z")

</div>

Thank you. Will try this and report findings.

---

<div class="post-metadata">

**Author:** ![AdamS](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/adams/32/5248_2.png) [@AdamS](https://forum.dfinity.org/u/AdamS)\
**Post date:** [September 13, 2022, 4:51pm UTC](https://forum.dfinity.org/t/how-do-i-specify-parameters-to-pass-to-rustc-when-building-using-dfx/15385/4 "2022-09-13T16:51:54Z")

</div>

If you would like to create a cfg that corresponds to this environment variable, you can use a build script that prints `cargo:rustc-cfg=mainnet` (or `cargo:rustc-cfg=network=ic`, or similar) if the environment variable is set to `ic`.

[https://doc.rust-lang.org/cargo/reference/build-scripts.html](https://doc.rust-lang.org/cargo/reference/build-scripts.html)

---

<div class="post-metadata">

**Author:** ![arifpateldpk](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/arifpateldpk/32/7062_2.png) [@arifpateldpk](https://forum.dfinity.org/u/arifpateldpk)\
**Post date:** [September 14, 2022, 8:15am UTC](https://forum.dfinity.org/t/how-do-i-specify-parameters-to-pass-to-rustc-when-building-using-dfx/15385/5 "2022-09-14T08:15:50Z")

</div>

NYC\< Thanks We Will Try Thisss

---

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [September 17, 2022, 5:41pm UTC](https://forum.dfinity.org/t/how-do-i-specify-parameters-to-pass-to-rustc-when-building-using-dfx/15385/6 "2022-09-17T17:41:36Z")

</div>

Adding to this answer, using the `env!` macro will not work as that will lead to a compiler error as shown below

![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/2/28b0fe45c4c720e271f529694f70c182718adf74.png)

You will need to use the `option_env!` macro for this to work. Like this

![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/e/e62d41ebdbef113a3f3d799be9688a98956349d4.png)
