Skip to content

added subsystem to builtin.zig #2462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7849,6 +7849,28 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
//assert(EndianBig == 0);
//assert(EndianLittle == 1);
}
{
buf_appendf(contents,
"pub const SubSystem = enum {\n"
" Console,\n"
" Windows,\n"
" Posix,\n"
" Native,\n"
" EfiApplication,\n"
" EfiBootServiceDriver,\n"
" EfiRom,\n"
" EfiRuntimeDriver,\n"
"};\n\n");

assert(TargetSubsystemConsole == 1);
assert(TargetSubsystemWindows == 2);
assert(TargetSubsystemPosix == 3);
assert(TargetSubsystemNative == 4);
assert(TargetSubsystemEfiApplication == 5);
assert(TargetSubsystemEfiBootServiceDriver == 6);
assert(TargetSubsystemEfiRom == 7);
assert(TargetSubsystemEfiRuntimeDriver == 8);
}
{
const char *endian_str = g->is_big_endian ? "Endian.Big" : "Endian.Little";
buf_appendf(contents, "pub const endian = %s;\n", endian_str);
Expand All @@ -7865,6 +7887,32 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
buf_appendf(contents, "pub const valgrind_support = %s;\n", bool_to_str(want_valgrind_support(g)));
buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic));

{
static const char* subsystem_strings[] = {
"Console",
"Windows",
"Posix",
"Native",
"EfiApplication",
"EfiBootServiceDriver",
"EfiRom",
"EfiRuntimeDriver",
};

if (g->zig_target->os != OsWindows || g->zig_target->os != OsUefi || g->have_dllmain_crt_startup || g->out_type == OutTypeLib) {
buf_appendf(contents, "pub const subsystem = null;\n");
} else if (g->subsystem == TargetSubsystemAuto) {
if (g->have_c_main || g->have_pub_main) {
buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_strings[TargetSubsystemConsole - 1]);
} else if (g->have_winmain || g->have_winmain_crt_startup) {
buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_strings[TargetSubsystemWindows - 1]);
}
} else {
buf_appendf(contents, "pub const subsystem = SubSystem.%s;\n", subsystem_strings[g->subsystem - 1]);
}

}

if (g->is_test_build) {
buf_appendf(contents,
"const TestFn = struct {\n"
Expand Down Expand Up @@ -7908,6 +7956,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
cache_bool(&cache_hash, g->have_err_ret_tracing);
cache_bool(&cache_hash, g->libc_link_lib != nullptr);
cache_bool(&cache_hash, g->valgrind_support);
cache_int(&cache_hash, g->subsystem - 1);

Buf digest = BUF_INIT;
buf_resize(&digest, 0);
Expand Down