Skip to content

Commit 7732af7

Browse files
committed
[Breaking] emccStep can take a src file path (C/C++ support)
1 parent f724af6 commit 7732af7

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

build.zig

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,16 @@ pub const StepOptions = struct {
182182
preload_paths: ?[]const EmccFilePath = null,
183183
shell_file_path: ?std.Build.LazyPath = null,
184184
js_library_path: ?std.Build.LazyPath = null,
185-
out_file_name: ?[]const u8 = null,
185+
out_file_name: []const u8,
186186
install_dir: std.Build.InstallDir,
187187
};
188188

189189
pub fn emccStep(
190190
b: *std.Build,
191-
wasm: *std.Build.Step.Compile,
191+
src_path_or_compile_step: union(enum) {
192+
src_path: std.Build.LazyPath,
193+
compile_step: *std.Build.Step.Compile,
194+
},
192195
options: StepOptions,
193196
) *std.Build.Step {
194197
var emcc = b.addSystemCommand(&.{emccPath(b)});
@@ -207,29 +210,32 @@ pub fn emccStep(
207210
) catch unreachable);
208211
}
209212

210-
emcc.addArtifactArg(wasm);
211-
{
212-
for (wasm.root_module.getGraph().modules) |module| {
213-
for (module.link_objects.items) |link_object| {
214-
switch (link_object) {
215-
.other_step => |compile_step| {
216-
switch (compile_step.kind) {
217-
.lib => {
218-
emcc.addArtifactArg(compile_step);
219-
},
220-
else => {},
221-
}
222-
},
223-
else => {},
213+
switch (src_path_or_compile_step) {
214+
.src_path => |src_path| {
215+
emcc.addArg(src_path.getPath(b));
216+
},
217+
.compile_step => |compile_step| {
218+
emcc.addArtifactArg(compile_step);
219+
for (compile_step.root_module.getGraph().modules) |module| {
220+
for (module.link_objects.items) |link_object| {
221+
switch (link_object) {
222+
.other_step => |linked_compile_step| {
223+
switch (linked_compile_step.kind) {
224+
.lib => {
225+
emcc.addArtifactArg(linked_compile_step);
226+
},
227+
else => {},
228+
}
229+
},
230+
else => {},
231+
}
224232
}
225233
}
226-
}
234+
},
227235
}
228236

229237
emcc.addArg("-o");
230-
const out_file = emcc.addOutputFileArg(
231-
options.out_file_name orelse b.fmt("{s}.html", .{wasm.name}),
232-
);
238+
const out_file = emcc.addOutputFileArg(options.out_file_name);
233239

234240
if (options.use_preload_plugins) {
235241
emcc.addArg("--use-preload-plugins");

0 commit comments

Comments
 (0)