# An option to pass rustc arbitrary arguments from the build script

**URL:** <https://internals.rust-lang.org/t/an-option-to-pass-rustc-arbitrary-arguments-from-the-build-script/17089>\
**Category:** cargo\
**Created:** [July 27, 2022, 5:06pm UTC](https://internals.rust-lang.org/t/an-option-to-pass-rustc-arbitrary-arguments-from-the-build-script/17089 "2022-07-27T17:06:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nm17](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nm17/32/9657_2.png) [@nm17](https://internals.rust-lang.org/u/nm17)\
**Post date:** [July 27, 2022, 5:06pm UTC](https://internals.rust-lang.org/t/an-option-to-pass-rustc-arbitrary-arguments-from-the-build-script/17089/1 "2022-07-27T17:06:20Z")

</div>

Hello, I would like to ask the more knowledgeable people in this community why can't Cargo accept arbitrary arguments to rustc on build scripts' behalf?

Currently, it is explictly stated in the code ([cargo/custom\_build.rs at c8c6e339967617bca15195748b0a72a2a73e486d · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/blob/c8c6e339967617bca15195748b0a72a2a73e486d/src/cargo/core/compiler/custom_build.rs#L794-L798)) that only -L and -l flags are allowed for the `rustc-flags` build script output option, but no explanation given as to why is that the case. Also, if there is no objections from others on this topic, I would like to work on making other options available to be passed on as well.

An example of how this might benefit the user is the `linker` and `link-flavor` codegen options, which, in some rare cases, might need to be specified according to the target for which the user is compiling the code to.

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [July 27, 2022, 6:08pm UTC](https://internals.rust-lang.org/t/an-option-to-pass-rustc-arbitrary-arguments-from-the-build-script/17089/2 "2022-07-27T18:08:57Z")

</div>

I don't know about `cargo` in this case, but for these kinds of things, being restrictive and opening up as needed is generally a better policy because otherwise all kinds of things are possible that need to be supported because of backwards compatibility reasons.

Relevant history:

- [cargo/src/cargo/core/compiler/custom\_build.rs at c8c6e339967617bca15195748b0a72a2a73e486d · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/blame/c8c6e339967617bca15195748b0a72a2a73e486d/src/cargo/core/compiler/custom_build.rs#L794-L798)
- [Tracking Issue for `extra-link-arg` · Issue #9426 · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/issues/9426)
- [Add rustc-bin-link-arg and rustc-link-arg custom build options by npmccallum · Pull Request #7811 · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/pull/7811)

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [December 22, 2024, 5:23pm UTC](https://internals.rust-lang.org/t/an-option-to-pass-rustc-arbitrary-arguments-from-the-build-script/17089/3 "2024-12-22T17:23:11Z")

</div>

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.
