Skip to content

Commit

Permalink
cgen,pref,help: support explicitly passing -subsystem windows or `-…
Browse files Browse the repository at this point in the history
…subsystem console` on Windows, even for non GG apps (#22480)
  • Loading branch information
spytheman authored Oct 10, 2024
1 parent 19a7fbc commit 1458dc3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -2804,6 +2804,11 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
}

fn (mut g Gen) is_gui_app() bool {
match g.pref.subsystem {
.windows { return true }
.console { return false }
.auto {}
}
if g.pref.os == .windows {
if g.force_main_console {
return false
Expand Down
9 changes: 8 additions & 1 deletion vlib/v/help/build/build-c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ see also `v help build`.
b) `int wmain(int ___argc, wchar_t* ___argv[], wchar_t* ___envp[]){`
when you are compiling console apps.

-subsystem <auto|console|windows>
Useful to change the generated main function on Windows.
Ignored on other platforms. The default is `auto`.
When set to `console` V will generate a `wmain` main function.
When set to `windows` V will generate a `wWinMain` main function,
even when you are not compiling `gg` apps.

-showcc
Prints the C command that is used to build the program.

Expand Down Expand Up @@ -353,4 +360,4 @@ see also `v help build`.
See https://en.wikipedia.org/wiki/Floating-point_arithmetic#%22Fast_math%22_optimization
https://learn.microsoft.com/en-us/cpp/build/reference/fp-specify-floating-point-behavior?view=msvc-170&redirectedfrom=MSDN
https://clang.llvm.org/docs/UsersManual.html#cmdoption-ffast-math
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-ffast-math
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-ffast-math
23 changes: 23 additions & 0 deletions vlib/v/pref/pref.v
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ pub enum ColorOutput {
never
}

// Subsystem is needed for modeling passing an explicit `/subsystem:windows` or `/subsystem:console` on Windows.
// By default it is `auto`. It has no effect on platforms != windows.
pub enum Subsystem {
auto
console
windows
}

pub enum Backend {
c // The (default) C backend
golang // Go backend
Expand Down Expand Up @@ -240,6 +248,8 @@ pub mut:
// use_64_int bool
// forwards compatibility settings:
relaxed_gcc14 bool = true // turn on the generated pragmas, that make gcc versions > 14 a lot less pedantic. The default is to have those pragmas in the generated C output, so that gcc-14 can be used on Arch etc.
//
subsystem Subsystem // the type of the window app, that is going to be generated; has no effect on !windows
}

pub struct LineInfo {
Expand Down Expand Up @@ -436,6 +446,19 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.eval_argument = cmdline.option(args[i..], '-e', '')
i++
}
'-subsystem' {
subsystem := cmdline.option(args[i..], '-subsystem', '')
res.subsystem = Subsystem.from(subsystem) or {
mut valid := []string{}
$for x in Subsystem.values {
valid << x.name
}
eprintln('invalid subsystem: ${subsystem}')
eprintln('valid values are: ${valid}')
exit(1)
}
i++
}
'-gc' {
gc_mode := cmdline.option(args[i..], '-gc', '')
match gc_mode {
Expand Down

0 comments on commit 1458dc3

Please sign in to comment.