-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Conversation
This code looks good, but there's one tricky thing I want to understand. When you use Does the linker choose a default subsystem if you don't specify one? |
is my understanding of this correct? bool have_pub_main; // pub fn main()
bool have_c_main; // export fn main(argc: c_int, argv: **u8)
bool have_winmain; // export fn WinMain(...)
bool have_winmain_crt_startup; // extern fn WinMainCRTStartup() noreturn
bool have_dllmain_crt_startup; // stdcallcc fn _DllMainCRTStartup(...) |
Yes |
@Sahnvour if you're around do you have any insight into these questions? |
@andrewrk I'm not very knownledgeable on this, but it seems the subsystem and the entry point are two different things, even if the former is usually deduced from the latter by The auto mode would probably be resolved by the linker as the docs say, but we could also choose to have a hardcoded default one, and still support As per the practical differences between console and windows (the two mainly used ones), I don't know if it does something more than juste having or not a console launch at startup. |
according to here
though that may just be for the msvc linker. |
I started to merge this, and I committed some cleanups here: https://github.com/ziglang/zig/compare/emekoi-builtin-subsystem But I don't think this can work without substantial changes. builtin.zig is created before the root source file is scanned, so the builtin.zig file would have the incorrect value for subsystem. const std = @import("std");
pub fn main() !void {
std.debug.warn("{}\n", @import("builtin").subsystem);
}
If you do |
One possible solution would be to implement the subsystem in builtin.zig as a userland function that could take advantage of #2189 and do the logic, like this: const root = @import("root");
pub const subsystem = blk: {
if (@hasDecl(root, "main")) break :blk SubSystem.Console;
if (@hasDecl(root, "WinMain")) break :blk SubSystem.Windows;
// etc...
}; |
In fact, bootstrap.zig already has access to the root source file, so if we merged this PR - in which builtin.zig has subsystem missing unless explicitly provided - bootstrap.zig would have enough information to do the correct thing. |
the problem with that is what if the user passes |
When the subsystem is explicitly provided, then it would be present in
I did answer this question in the docs, but maybe it could be made clearer. |
closes #2455.