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 {...@@ -115,6 +115,7 @@ pub fn build(b: *Builder) !void {
115 if (target.isWindows() and target.getAbi() == .gnu) {115 if (target.isWindows() and target.getAbi() == .gnu) {
116 // LTO is currently broken on mingw, this can be removed when it's fixed.116 // LTO is currently broken on mingw, this can be removed when it's fixed.
117 exe.want_lto = false;117 exe.want_lto = false;
118 test_stage2.want_lto = false;
118 }119 }
119120
120 const exe_options = b.addOptions();121 const exe_options = b.addOptions();
...@@ -501,6 +502,7 @@ fn addStaticLlvmOptionsToExe(...@@ -501,6 +502,7 @@ fn addStaticLlvmOptionsToExe(
501 if (exe.target.getOs().tag == .windows) {502 if (exe.target.getOs().tag == .windows) {
502 exe.linkSystemLibrary("version");503 exe.linkSystemLibrary("version");
503 exe.linkSystemLibrary("uuid");504 exe.linkSystemLibrary("uuid");
505 exe.linkSystemLibrary("ole32");
504 }506 }
505}507}
506508
lib/std/start.zig+12
...@@ -28,6 +28,8 @@ comptime {...@@ -28,6 +28,8 @@ comptime {
28 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {28 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
29 @export(main2, .{ .name = "main" });29 @export(main2, .{ .name = "main" });
30 }30 }
31 } else if (builtin.os.tag == .windows) {
32 @export(wWinMainCRTStartup2, .{ .name = "wWinMainCRTStartup" });
31 } else {33 } else {
32 if (!@hasDecl(root, "_start")) {34 if (!@hasDecl(root, "_start")) {
33 @export(_start2, .{ .name = "_start" });35 @export(_start2, .{ .name = "_start" });
...@@ -96,6 +98,11 @@ fn callMain2() noreturn {...@@ -96,6 +98,11 @@ fn callMain2() noreturn {
96 exit2(0);98 exit2(0);
97}99}
98100
101fn wWinMainCRTStartup2() callconv(.C) noreturn {
102 root.main();
103 exit2(0);
104}
105
99fn exit2(code: usize) noreturn {106fn exit2(code: usize) noreturn {
100 switch (native_os) {107 switch (native_os) {
101 .linux => switch (builtin.stage2_arch) {108 .linux => switch (builtin.stage2_arch) {
...@@ -148,11 +155,16 @@ fn exit2(code: usize) noreturn {...@@ -148,11 +155,16 @@ fn exit2(code: usize) noreturn {
148 },155 },
149 else => @compileError("TODO"),156 else => @compileError("TODO"),
150 },157 },
158 .windows => {
159 ExitProcess(@truncate(u32, code));
160 },
151 else => @compileError("TODO"),161 else => @compileError("TODO"),
152 }162 }
153 unreachable;163 unreachable;
154}164}
155165
166extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.C) noreturn;
167
156////////////////////////////////////////////////////////////////////////////////168////////////////////////////////////////////////////////////////////////////////
157169
158fn _DllMainCRTStartup(170fn _DllMainCRTStartup(
src/Module.zig-7
...@@ -3758,13 +3758,6 @@ pub fn clearDecl(...@@ -3758,13 +3758,6 @@ pub fn clearDecl(
3758 dep.removeDependency(decl);3758 dep.removeDependency(decl);
3759 if (outdated_decls) |map| {3759 if (outdated_decls) |map| {
3760 map.putAssumeCapacity(dep, {});3760 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));
3768 }3761 }
3769 }3762 }
3770 decl.dependants.clearRetainingCapacity();3763 decl.dependants.clearRetainingCapacity();
src/type.zig+2-4
...@@ -1336,6 +1336,8 @@ pub const Type = extern union {...@@ -1336,6 +1336,8 @@ pub const Type = extern union {
1336 }1336 }
1337 }1337 }
13381338
1339 /// For structs and unions, if the type does not have their fields resolved
1340 /// this will return `false`.
1339 pub fn hasCodeGenBits(self: Type) bool {1341 pub fn hasCodeGenBits(self: Type) bool {
1340 return switch (self.tag()) {1342 return switch (self.tag()) {
1341 .u1,1343 .u1,
...@@ -1400,14 +1402,10 @@ pub const Type = extern union {...@@ -1400,14 +1402,10 @@ pub const Type = extern union {
1400 => true,1402 => true,
14011403
1402 .@"struct" => {1404 .@"struct" => {
1403 // TODO introduce lazy value mechanism
1404 const struct_obj = self.castTag(.@"struct").?.data;1405 const struct_obj = self.castTag(.@"struct").?.data;
1405 if (struct_obj.known_has_bits) {1406 if (struct_obj.known_has_bits) {
1406 return true;1407 return true;
1407 }1408 }
1408 assert(struct_obj.status == .have_field_types or
1409 struct_obj.status == .layout_wip or
1410 struct_obj.status == .have_layout);
1411 for (struct_obj.fields.values()) |value| {1409 for (struct_obj.fields.values()) |value| {
1412 if (value.ty.hasCodeGenBits())1410 if (value.ty.hasCodeGenBits())
1413 return true;1411 return true;
test/cases.zig+1-1
...@@ -26,7 +26,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -26,7 +26,7 @@ pub fn addCases(ctx: *TestContext) !void {
26 var case = ctx.exe("hello world with updates", linux_x64);26 var case = ctx.exe("hello world with updates", linux_x64);
2727
28 case.addError("", &[_][]const u8{28 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'",
30 });30 });
3131
32 // Incorrect return type32 // Incorrect return type
test/stage2/darwin.zig+1-1
...@@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void {
14 {14 {
15 var case = ctx.exe("darwin hello world with updates", target);15 var case = ctx.exe("darwin hello world with updates", target);
16 case.addError("", &[_][]const u8{16 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'",
18 });18 });
1919
20 // Incorrect return type20 // Incorrect return type