Equivalent of `cargo rustc` in Cargo.toml or .cargo/config


I am trying to experiment with a no-std application. I can get my crate to build by using cargo rustc -- -C link-arg=-nostartfiles. However, I cannot run cargo build, since it doesn’t automatically pass in the -nostartfiles flag. However, if I add it to .cargo/config, then it is also used when compiling my dependencies, which doesn’t work.

Is there a way to add everything I would add after the cargo rustc to .cargo/config (or Cargo.toml) so I don’t have to use that command every time?

1 Like

Here’s a list of everything that you’re able to put in Cargo.toml https://doc.rust-lang.org/cargo/reference/manifest.html

And the answer is “no”. There’s no way to pass arbitrary flags through cargo. That’s intentional. The Cargo team doesn’t want dependencies to be able to build themselves with arbitrary compiler flags, because having different flags for different crates can result in a broken build.


Thanks! I did take a look through the manifest documentation but wanted to make sure I wasn’t missing something.

I think I can understand the concept of not allowing libraries to specify arbitrary flags. However, wouldn’t it make sense for a binary to be able to pass arbitrary flags to the compiler? Or am I missing something?


For your given example, can you just use #![no_start]?