hide console window on Windows in release
#409
You can try to write this in Cargo.toml, i am not sure it can work well on 2024 edition.
[[bin]]
name = "package_name"
path = "src/main.rs"
windows_subsystem = "windows"
For cfg_attr(not(debug_assertions) still stay in main, i dont know how to seperate it.
Thanks! This is certainly an improvement that we should make. However, one of the rules of Robrix's implementation is that we must not contain any platform-specific code, as one of the goals of Robrix is to demonstrate that an app dev can write a fully-complex app without any platform-specific code considerations.
Overall, I think this change should happen within Makepad itself. This would allow others to use it too.
Also, the visibility of the console window should not be tied to whether we're building in debug mode or release mode, as we very frequently test Robrix using a release build (for performance reasons), and we still want to see the console log then.
This should probably be a --cfg option offered by Makepad, such that we can specifically choose when to disable the console window, e.g., when building a release package of Robrix for Windows.
@yangcancai I added more context above, kindly take a look.
Change it to something like this?
#![cfg_attr(target_os = "windows", windows_subsystem = "windows")]
@kevinaboos use --cfg or --feature to pass whether to display the console window. In Windows systems, the mainstream method is to control it through --feature. However, I have studied cargo-package and found no good way to pass --feature to robrix. So I can only use RUSTFLAGS="--cfg hide_windows_console" cargo packager --release to pass it. Do you have any good suggestions for this?
The RUSTFLAGS solution doesn't feel very elegant, since it will override the rustflags in .cargo/config.toml.
Change it to something like this?
#![cfg_attr(target_os = "windows", windows_subsystem = "windows")]
Maybe to use either the --cfg flag or a --feature to enable or disable whether the window should be hidden like below
// --cfg hide_windows_console
#![cfg_attr(all(hide_windows_console, target_os = "windows"), windows_subsystem = "windows")]
// --feature hide_windows_console
#![cfg_attr(all(feature="hide_windows_console", target_os = "windows"), windows_subsystem = "windows")]
However, the RUSTFLAGS="--cfg hide_windows_console" flag overrides settings in .cargo/config.toml, and --feature hide_windows_consolecannot be passed when using cargo packager --release
yes, that's the correct way to do cfg in a cargo invocation, using RUSTFLAGS.
IMO, cargo features are not appropriate for this kind of thing because we don't need cargo-level knowledge of this feature. We could make it be a cargo feature, but it's not necessary because it doesn't affect any build-time behavior or dependency selection.
I still maintain that the correct place to do this is in Makepad itself, as a special addition to the MAKEPAD environment variable that we would only activate when building a release bundle for Windows.