The windows subsystem detection did not properly work, because the exported WinMain function was not defined with the pub keyword. This caused the @hasDecl builtin to not find the WinMain function and caused the subsystem detection to be wrong. The following example is relevant:
const std = @import("std");
const builtin = @import("builtin");
usingnamespace std.os.windows;
extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int;
export fn WinMain(hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) INT {
_ = MessageBoxA(null, c"test", c"title", 0);
@compileLog(subsystem);
return 0;
}
Without the pub in front of export fn WinMain(... this showed that the subsystem was .Console, whereas with the pub it correctly showed .Windows.
pub keyword.@hasDecl to also return true for exported functions.I would like to implement the fix for this, once I know which solution is the best.
I vote for option 3 as export and pub have AFAIK different semantics: pub means that the symbol is visible to importers and export means that the symbol is visible to extern declarations and the linker. It seems most appropriate to change @hasDecl as conflating extern and pub isn't a good idea.
Most helpful comment
I vote for option 3 as
exportandpubhave AFAIK different semantics:pubmeans that the symbol is visible to importers andexportmeans that the symbol is visible toexterndeclarations and the linker. It seems most appropriate to change@hasDeclas conflatingexternandpubisn't a good idea.