Skip to content

Commit e80b041

Browse files
committed
Force user to specify where emsdk dependency is coming from
emsdk might be a nested dependency that can be retrieved with: `b.dependency(...).builder.dependency(...)`
1 parent 70bdafc commit e80b041

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

build.zig

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,45 @@ pub fn build(b: *std.Build) void {
1010
_ = b.addModule("root", .{ .root_source_file = b.path("src/zemscripten.zig") });
1111
}
1212

13-
pub fn emccPath(b: *std.Build) []const u8 {
14-
return std.fs.path.join(b.allocator, &.{
15-
b.dependency("emsdk", .{}).path("").getPath(b),
13+
pub fn emccPath(b: *std.Build, emsdk_dep: *std.Build.Dependency) []const u8 {
14+
return b.pathJoin(&.{
15+
emsdk_dep.path("").getPath(b),
1616
"upstream",
1717
"emscripten",
1818
"emcc.py",
19-
}) catch unreachable;
19+
});
2020
}
2121

22-
pub fn emrunPath(b: *std.Build) []const u8 {
23-
return std.fs.path.join(b.allocator, &.{
24-
b.dependency("emsdk", .{}).path("").getPath(b),
22+
pub fn emrunPath(b: *std.Build, emsdk_dep: *std.Build.Dependency) []const u8 {
23+
return b.pathJoin(&.{
24+
emsdk_dep.path("").getPath(b),
2525
"upstream",
2626
"emscripten",
2727
switch (builtin.target.os.tag) {
2828
.windows => "emrun.bat",
2929
else => "emrun",
3030
},
31-
}) catch unreachable;
31+
});
3232
}
3333

34-
pub fn htmlPath(b: *std.Build) []const u8 {
35-
return std.fs.path.join(b.allocator, &.{
36-
b.dependency("emsdk", .{}).path("").getPath(b),
34+
pub fn htmlPath(b: *std.Build, emsdk_dep: *std.Build.Dependency) []const u8 {
35+
return b.pathJoin(&.{
36+
emsdk_dep.path("").getPath(b),
3737
"upstream",
3838
"emscripten",
3939
"src",
4040
"shell.html",
41-
}) catch unreachable;
41+
});
4242
}
4343

44-
pub fn activateEmsdkStep(b: *std.Build) *std.Build.Step {
45-
const emsdk_script_path = std.fs.path.join(b.allocator, &.{
46-
b.dependency("emsdk", .{}).path("").getPath(b),
44+
pub fn activateEmsdkStep(b: *std.Build, emsdk_dep: *std.Build.Dependency) *std.Build.Step {
45+
const emsdk_script_path = b.pathJoin(&.{
46+
emsdk_dep.path("").getPath(b),
4747
switch (builtin.target.os.tag) {
4848
.windows => "emsdk.bat",
4949
else => "emsdk",
5050
},
51-
}) catch unreachable;
51+
});
5252

5353
var emsdk_update = b.addSystemCommand(&.{ emsdk_script_path, "update" });
5454

@@ -80,11 +80,11 @@ pub fn activateEmsdkStep(b: *std.Build) *std.Build.Step {
8080

8181
switch (builtin.target.os.tag) {
8282
.linux, .macos => {
83-
const chmod_emcc = b.addSystemCommand(&.{ "chmod", "a+x", emccPath(b) });
83+
const chmod_emcc = b.addSystemCommand(&.{ "chmod", "a+x", emccPath(b, emsdk_dep) });
8484
chmod_emcc.step.dependOn(&emsdk_activate.step);
8585
step.dependOn(&chmod_emcc.step);
8686

87-
const chmod_emrun = b.addSystemCommand(&.{ "chmod", "a+x", emrunPath(b) });
87+
const chmod_emrun = b.addSystemCommand(&.{ "chmod", "a+x", emrunPath(b, emsdk_dep) });
8888
chmod_emrun.step.dependOn(&emsdk_activate.step);
8989
step.dependOn(&chmod_emrun.step);
9090
},
@@ -197,11 +197,12 @@ pub const StepOptions = struct {
197197

198198
pub fn emccStep(
199199
b: *std.Build,
200+
emsdk_dep: *std.Build.Dependency,
200201
src_paths: []const std.Build.LazyPath,
201202
compile_steps: []const *std.Build.Step.Compile,
202203
options: StepOptions,
203204
) *std.Build.Step {
204-
var emcc = b.addSystemCommand(&.{emccPath(b)});
205+
var emcc = b.addSystemCommand(&.{emccPath(b, emsdk_dep)});
205206

206207
var iterFlags = options.flags.iterator();
207208
while (iterFlags.next()) |kvp| {
@@ -283,10 +284,11 @@ pub fn emccStep(
283284

284285
pub fn emrunStep(
285286
b: *std.Build,
287+
emsdk_dep: *std.Build.Dependency,
286288
html_path: []const u8,
287289
extra_args: []const []const u8,
288290
) *std.Build.Step {
289-
var emrun = b.addSystemCommand(&.{emrunPath(b)});
291+
var emrun = b.addSystemCommand(&.{emrunPath(b, emsdk_dep)});
290292
emrun.addArgs(extra_args);
291293
emrun.addArg(html_path);
292294
// emrun.addArg("--");

0 commit comments

Comments
 (0)