Skip to content

Commit eda0a00

Browse files
committed
try to resolve TargetSubSystemAuto to actual subsystem
1 parent 31a4b15 commit eda0a00

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/codegen.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7852,7 +7852,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
78527852
{
78537853
buf_appendf(contents,
78547854
"pub const SubSystem = enum {\n"
7855-
" Auto,\n"
78567855
" Console,\n"
78577856
" Windows,\n"
78587857
" Posix,\n"
@@ -7863,7 +7862,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
78637862
" EfiRuntimeDriver,\n"
78647863
"};\n\n");
78657864

7866-
assert(TargetSubsystemAuto == 0);
78677865
assert(TargetSubsystemConsole == 1);
78687866
assert(TargetSubsystemWindows == 2);
78697867
assert(TargetSubsystemPosix == 3);
@@ -7891,7 +7889,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
78917889

78927890
{
78937891
static const char* subsystem_strings[] = {
7894-
"Auto",
78957892
"Console",
78967893
"Windows",
78977894
"Posix",
@@ -7901,7 +7898,19 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
79017898
"EfiRom",
79027899
"EfiRuntimeDriver",
79037900
};
7904-
buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_strings[g->subsystem]);
7901+
7902+
if (g->subsystem == TargetSubsystemAuto) {
7903+
if (g->have_c_main || g->have_pub_main) {
7904+
buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_strings[TargetSubsystemConsole - 1]);
7905+
} else if (g->have_winmain || g->have_winmain_crt_startup) {
7906+
buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_strings[TargetSubsystemWindows - 1]);
7907+
} else if (g->have_dllmain_crt_startup || g->out_type == OutTypeLib) {
7908+
buf_appendf(contents, "pub const subsystem = null;\n");
7909+
}
7910+
} else {
7911+
buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_strings[g->subsystem - 1]);
7912+
}
7913+
79057914
}
79067915

79077916
if (g->is_test_build) {
@@ -7947,7 +7956,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
79477956
cache_bool(&cache_hash, g->have_err_ret_tracing);
79487957
cache_bool(&cache_hash, g->libc_link_lib != nullptr);
79497958
cache_bool(&cache_hash, g->valgrind_support);
7950-
cache_int(&cache_hash, g->subsystem);
7959+
cache_int(&cache_hash, g->subsystem - 1);
79517960

79527961
Buf digest = BUF_INIT;
79537962
buf_resize(&digest, 0);

0 commit comments

Comments
 (0)