[Solved] Rust project how build like gcc -mwindow?


I have no command window needs to be compiled into the application.

Just like in GCC compile using -mwindow option.


You have to pass -C "link-args=-mwindows" to rustc. Before you ask: no, you can’t configure Cargo to do this as part of cargo build.


Oh no !!
I can’t use rustc to compile the project.


If you’re writing a project in Rust, how are you not using rustc? I’m pretty sure that’s impossible.

If you’re not aware, you can invoke rustc via Cargo using:




I see cargo parameters description to compile the target.


the cargo command: cargo rustc --release – -C link-args=-mwindows


You can: http://doc.crates.io/config.html#configuration-keys
Search for rustflags.


I didn’t know that had been added, but it’s still kinda blunt.

First of all, it requires that you reconfigure Cargo itself, as opposed to setting something in the manifest. I’m not sure checking .cargo/config files into a repo is a good practice. Secondly, it applies to all builds, meaning that you can’t have debug builds with a connected console, which makes debugging more of a pain. Third, it doesn’t allow you to only pass that flag for Windows builds (so you can’t build a cross-platform GUI package).

I’m still counting that as “not supported”. :slight_smile:


That’s the same way as checking-in .gitignore

cargo 0.9(currently Rust beta):

[target.'cfg(feature = "do-stuff")']
rustflags = ["..."]

There are also other ways.

rustflags = ["..."]

That’s exactly how I make cargo build for my custom iMX6 ARM target(thanks to ogeon):

ar = "arm-montavista-linux-gnueabi-ar"
linker = "gcc-sysroot"


Yes, I know you can, but .gitignore doesn’t let you override remote URLs or clear auth tokens.

But rustflags is in the build section, not the target section. So far as I can see, there’s nothing about per-target overrides for that section.

And anyway, I don’t count anything until it’s in stable.


Indeed, I looked at my ar definition and thought that may be it can set the other flags, but it can’t.
Anyway, if you want to compile something specific on a specific platform, you can still pass --features "windows-feature" only on that platform. As for the flag, you might not be able to do it currently in Cargo.toml(might be we didn’t put much thought into this), but you do it in Cargo's build script.

I think there are a few solutions even with current stable Rust. Another option could be to do the gcc-sysroot-like trick.

Passing rustflags for only target-specific release builsd