authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-22 22:08:34-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-09-22 22:08:34-04:00
log0ec01e58b429e96d50411f74a0005076c24dda0c
tree5981b50b570382137f1cf4c1eb2f528cc6962f21
parent3b09262c1252de0d9f946630e701be65bc5b2fc7
parente03095f167cf0cd8c1424bff0de3c0a7b5f66b18
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #9717 from SpexGuy/stage2-start-windows

Make stage2 start.zig work on Windows

6 files changed, 18 insertions(+), 13 deletions(-)

build.zig+2
......@@ -115,6 +115,7 @@ pub fn build(b: *Builder) !void {
115115 if (target.isWindows() and target.getAbi() == .gnu) {
116116 // LTO is currently broken on mingw, this can be removed when it's fixed.
117117 exe.want_lto = false;
118 test_stage2.want_lto = false;
118119 }
119120
120121 const exe_options = b.addOptions();
......@@ -501,6 +502,7 @@ fn addStaticLlvmOptionsToExe(
501502 if (exe.target.getOs().tag == .windows) {
502503 exe.linkSystemLibrary("version");
503504 exe.linkSystemLibrary("uuid");
505 exe.linkSystemLibrary("ole32");
504506 }
505507}
506508
lib/std/start.zig+12
......@@ -28,6 +28,8 @@ comptime {
2828 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
2929 @export(main2, .{ .name = "main" });
3030 }
31 } else if (builtin.os.tag == .windows) {
32 @export(wWinMainCRTStartup2, .{ .name = "wWinMainCRTStartup" });
3133 } else {
3234 if (!@hasDecl(root, "_start")) {
3335 @export(_start2, .{ .name = "_start" });
......@@ -96,6 +98,11 @@ fn callMain2() noreturn {
9698 exit2(0);
9799}
98100
101fn wWinMainCRTStartup2() callconv(.C) noreturn {
102 root.main();
103 exit2(0);
104}
105
99106fn exit2(code: usize) noreturn {
100107 switch (native_os) {
101108 .linux => switch (builtin.stage2_arch) {
......@@ -148,11 +155,16 @@ fn exit2(code: usize) noreturn {
148155 },
149156 else => @compileError("TODO"),
150157 },
158 .windows => {
159 ExitProcess(@truncate(u32, code));
160 },
151161 else => @compileError("TODO"),
152162 }
153163 unreachable;
154164}
155165
166extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.C) noreturn;
167
156168////////////////////////////////////////////////////////////////////////////////
157169
158170fn _DllMainCRTStartup(
src/Module.zig-7
......@@ -3758,13 +3758,6 @@ pub fn clearDecl(
37583758 dep.removeDependency(decl);
37593759 if (outdated_decls) |map| {
37603760 map.putAssumeCapacity(dep, {});
3761 } else if (std.debug.runtime_safety) {
3762 // If `outdated_decls` is `null`, it means we're being called from
3763 // `Compilation` after `performAllTheWork` and we cannot queue up any
3764 // more work. `dep` must necessarily be another Decl that is no longer
3765 // being referenced, and will be in the `deletion_set`. Otherwise,
3766 // something has gone wrong.
3767 assert(mod.deletion_set.contains(dep));
37683761 }
37693762 }
37703763 decl.dependants.clearRetainingCapacity();
src/type.zig+2-4
......@@ -1336,6 +1336,8 @@ pub const Type = extern union {
13361336 }
13371337 }
13381338
1339 /// For structs and unions, if the type does not have their fields resolved
1340 /// this will return `false`.
13391341 pub fn hasCodeGenBits(self: Type) bool {
13401342 return switch (self.tag()) {
13411343 .u1,
......@@ -1400,14 +1402,10 @@ pub const Type = extern union {
14001402 => true,
14011403
14021404 .@"struct" => {
1403 // TODO introduce lazy value mechanism
14041405 const struct_obj = self.castTag(.@"struct").?.data;
14051406 if (struct_obj.known_has_bits) {
14061407 return true;
14071408 }
1408 assert(struct_obj.status == .have_field_types or
1409 struct_obj.status == .layout_wip or
1410 struct_obj.status == .have_layout);
14111409 for (struct_obj.fields.values()) |value| {
14121410 if (value.ty.hasCodeGenBits())
14131411 return true;
test/cases.zig+1-1
......@@ -26,7 +26,7 @@ pub fn addCases(ctx: *TestContext) !void {
2626 var case = ctx.exe("hello world with updates", linux_x64);
2727
2828 case.addError("", &[_][]const u8{
29 ":95:9: error: struct 'tmp.tmp' has no member named 'main'",
29 ":97:9: error: struct 'tmp.tmp' has no member named 'main'",
3030 });
3131
3232 // Incorrect return type
test/stage2/darwin.zig+1-1
......@@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void {
1414 {
1515 var case = ctx.exe("darwin hello world with updates", target);
1616 case.addError("", &[_][]const u8{
17 ":95:9: error: struct 'tmp.tmp' has no member named 'main'",
17 ":97:9: error: struct 'tmp.tmp' has no member named 'main'",
1818 });
1919
2020 // Incorrect return type