Skip to content

Add hide_windows_console cfg option to hide the Windows command prompt #410

Merged
kevinaboos merged 5 commits intoproject-robius:mainfrom
yangcancai:fix_hidden_console_window
Jun 13, 2025
Merged

Add hide_windows_console cfg option to hide the Windows command prompt #410
kevinaboos merged 5 commits intoproject-robius:mainfrom
yangcancai:fix_hidden_console_window

Conversation

@yangcancai
Copy link
Contributor

No description provided.

@yangcancai
Copy link
Contributor Author

#409

@emmettlu
Copy link
Contributor

emmettlu commented Feb 27, 2025

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.

@ZhangHanDong ZhangHanDong added the waiting-on-review This issue is waiting to be reviewed label Feb 28, 2025
@kevinaboos
Copy link
Member

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.

Copy link
Member

@kevinaboos kevinaboos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This attribute shouldn't be enabled based on whether debug_assertions are enabled, because we typically do want the console log to be visible when running Robrix in release mode on Windows.

Instead, we need to check for a custom --cfg options (such as hide_windows_console), and enable this attribute only if:

  1. Robrix is built using that --cfg hide_windows_console configuration, and
  2. if we're building for Windows (target_os = "windows").

That way, we can enable the --cfg hide_windows_console option when we're building a distributed package of Robrix for Windows (an installable app bundle), and not just when we're building Robrix in --release mode for regular testing on Windows.

@kevinaboos kevinaboos added waiting-on-author This issue is waiting on the original author for a response and removed waiting-on-review This issue is waiting to be reviewed labels May 30, 2025
@kevinaboos
Copy link
Member

@yangcancai I added more context above, kindly take a look.

@sanri
Copy link

sanri commented Jun 13, 2025

Change it to something like this?

#![cfg_attr(target_os = "windows", windows_subsystem = "windows")]

@yangcancai
Copy link
Contributor Author

@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?

@yangcancai
Copy link
Contributor Author

The RUSTFLAGS solution doesn't feel very elegant, since it will override the rustflags in .cargo/config.toml.

@yangcancai
Copy link
Contributor Author

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

@yangcancai yangcancai force-pushed the fix_hidden_console_window branch from 992a754 to f8f61e0 Compare June 13, 2025 09:43
@kevinaboos
Copy link
Member

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.

@kevinaboos kevinaboos changed the title hide console window on Windows in release Add hide_windows_console cfg option to hide the Windows command prompt Jun 13, 2025
Copy link
Member

@kevinaboos kevinaboos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some changes and can now accept this PR. Thanks! In the future, I'll move it into Makepad itself, as discussed earlier.

@kevinaboos kevinaboos merged commit 6b3181d into project-robius:main Jun 13, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on-author This issue is waiting on the original author for a response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants