Skip to content

Commit dce5c0b

Browse files
committed
build.zig: Try adding a wait in activate SDK step on Windows
Maybe it would be better to flush file system changes but that is more complicated.
1 parent d2d1261 commit dce5c0b

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

build.zig

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const builtin = @import("builtin");
2+
const host_os = builtin.target.os.tag;
3+
24
const std = @import("std");
35

46
pub const emsdk_ver_major = "4";
@@ -15,7 +17,7 @@ pub fn emccPath(b: *std.Build) []const u8 {
1517
b.dependency("emsdk", .{}).path("").getPath(b),
1618
"upstream",
1719
"emscripten",
18-
switch (builtin.target.os.tag) {
20+
switch (host_os) {
1921
.windows => "emcc.bat",
2022
else => "emcc",
2123
},
@@ -27,7 +29,7 @@ pub fn emrunPath(b: *std.Build) []const u8 {
2729
b.dependency("emsdk", .{}).path("").getPath(b),
2830
"upstream",
2931
"emscripten",
30-
switch (builtin.target.os.tag) {
32+
switch (host_os) {
3133
.windows => "emrun.bat",
3234
else => "emrun",
3335
},
@@ -47,15 +49,15 @@ pub fn htmlPath(b: *std.Build) []const u8 {
4749
pub fn activateEmsdkStep(b: *std.Build) *std.Build.Step {
4850
const emsdk_script_path = std.fs.path.join(b.allocator, &.{
4951
b.dependency("emsdk", .{}).path("").getPath(b),
50-
switch (builtin.target.os.tag) {
52+
switch (host_os) {
5153
.windows => "emsdk.bat",
5254
else => "emsdk",
5355
},
5456
}) catch unreachable;
5557

5658
var emsdk_install = b.addSystemCommand(&.{ emsdk_script_path, "install", emsdk_version });
5759

58-
switch (builtin.target.os.tag) {
60+
switch (host_os) {
5961
.linux, .macos => {
6062
emsdk_install.step.dependOn(&b.addSystemCommand(&.{ "chmod", "+x", emsdk_script_path }).step);
6163
},
@@ -78,7 +80,7 @@ pub fn activateEmsdkStep(b: *std.Build) *std.Build.Step {
7880
}.make,
7981
});
8082

81-
switch (builtin.target.os.tag) {
83+
switch (host_os) {
8284
.linux, .macos => {
8385
const chmod_emcc = b.addSystemCommand(&.{ "chmod", "+x", emccPath(b) });
8486
chmod_emcc.step.dependOn(&emsdk_activate.step);
@@ -89,12 +91,25 @@ pub fn activateEmsdkStep(b: *std.Build) *std.Build.Step {
8991
step.dependOn(&chmod_emrun.step);
9092
},
9193
.windows => {
94+
const windows_wait_step = b.allocator.create(std.Build.Step) catch unreachable;
95+
windows_wait_step.* = std.Build.Step.init(.{
96+
.id = .custom,
97+
.name = "Wait for a sceond",
98+
.owner = b,
99+
.makeFn = &struct {
100+
fn make(_: *std.Build.Step, _: std.Build.Step.MakeOptions) anyerror!void {
101+
std.time.sleep(std.time.ns_per_s * 1);
102+
}
103+
}.make,
104+
});
105+
windows_wait_step.dependOn(&emsdk_activate.step);
106+
92107
const takeown_emcc = b.addSystemCommand(&.{ "takeown", "/f", emccPath(b) });
93-
takeown_emcc.step.dependOn(&emsdk_activate.step);
108+
takeown_emcc.step.dependOn(windows_wait_step);
94109
step.dependOn(&takeown_emcc.step);
95110

96111
const takeown_emrun = b.addSystemCommand(&.{ "takeown", "/f", emrunPath(b) });
97-
takeown_emrun.step.dependOn(&emsdk_activate.step);
112+
takeown_emrun.step.dependOn(windows_wait_step);
98113
step.dependOn(&takeown_emrun.step);
99114
},
100115
else => {},

0 commit comments

Comments
 (0)