Skip to content

Commit 1a3fb91

Browse files
committed
[Breaking] Support multiple src files and compile steps as emcc input
1 parent e171005 commit 1a3fb91

File tree

2 files changed

+24
-43
lines changed

2 files changed

+24
-43
lines changed

README.md

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Add zemscripten's "root" module to your wasm compile target., then create an `em
3939
4040
const emcc_step = @import("zemscripten").emccStep(
4141
b,
42-
.{ .compile_step = wasm },
42+
&.{ }, // src file paths
43+
&.{ wasm }, // src compile steps
4344
.{
4445
.optimize = optimize,
4546
.flags = emcc_flags,
@@ -49,31 +50,14 @@ Add zemscripten's "root" module to your wasm compile target., then create an `em
4950
.preload_paths = &.{},
5051
.out_file_name = null, // emcc output arg will default to {wasm.name}.html if unset
5152
.install_dir = .{ .custom = "web" },
53+
.shell_file_path = null, // set this to override the default html shell
5254
},
5355
);
5456
emcc_step.dependOn(activate_emsdk_step);
5557
5658
b.getInstallStep().dependOn(emcc_step);
5759
```
5860

59-
To use a custom html file emccStep() accepts a shell_file_path option:
60-
```zig
61-
const emcc_step = @import("zemscripten").emccStep(
62-
b,
63-
wasm,
64-
.{
65-
.optimize = optimize,
66-
.flags = emcc_flags,
67-
.settings = emcc_settings,
68-
.use_preload_plugins = true,
69-
.embed_paths = &.{},
70-
.preload_paths = &.{},
71-
.install_dir = .{ .custom = "web" },
72-
.shell_file_path = b.path("path/to/file"),
73-
},
74-
);
75-
```
76-
7761
Now you can use the provided Zig panic and log overrides in your wasm's root module and define the entry point that invoked by the js output of `emcc` (by default it looks for a symbol named `main`). For example:
7862
```zig
7963
const std = @import("std");

build.zig

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,8 @@ pub const StepOptions = struct {
187187

188188
pub fn emccStep(
189189
b: *std.Build,
190-
src_path_or_compile_step: union(enum) {
191-
src_path: std.Build.LazyPath,
192-
compile_step: *std.Build.Step.Compile,
193-
},
190+
src_paths: []const []const u8,
191+
compile_steps: []const *std.Build.Step.Compile,
194192
options: StepOptions,
195193
) *std.Build.Step {
196194
var emcc = b.addSystemCommand(&.{emccPath(b)});
@@ -209,28 +207,27 @@ pub fn emccStep(
209207
) catch unreachable);
210208
}
211209

212-
switch (src_path_or_compile_step) {
213-
.src_path => |src_path| {
214-
emcc.addArg(src_path.getPath(b));
215-
},
216-
.compile_step => |compile_step| {
217-
emcc.addArtifactArg(compile_step);
218-
for (compile_step.root_module.getGraph().modules) |module| {
219-
for (module.link_objects.items) |link_object| {
220-
switch (link_object) {
221-
.other_step => |linked_compile_step| {
222-
switch (linked_compile_step.kind) {
223-
.lib => {
224-
emcc.addArtifactArg(linked_compile_step);
225-
},
226-
else => {},
227-
}
228-
},
229-
else => {},
230-
}
210+
for (src_paths) |src_path| {
211+
emcc.addArg(src_path);
212+
}
213+
214+
for (compile_steps) |compile_step| {
215+
emcc.addArtifactArg(compile_step);
216+
for (compile_step.root_module.getGraph().modules) |module| {
217+
for (module.link_objects.items) |link_object| {
218+
switch (link_object) {
219+
.other_step => |linked_compile_step| {
220+
switch (linked_compile_step.kind) {
221+
.lib => {
222+
emcc.addArtifactArg(linked_compile_step);
223+
},
224+
else => {},
225+
}
226+
},
227+
else => {},
231228
}
232229
}
233-
},
230+
}
234231
}
235232

236233
emcc.addArg("-o");

0 commit comments

Comments
 (0)