Skip to content

Commit dca717d

Browse files
committed
[Breaking] Ensure changes to input files cause rebuild
1 parent 1a3fb91 commit dca717d

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ Add zemscripten's "root" module to your wasm compile target., then create an `em
4848
.use_preload_plugins = true,
4949
.embed_paths = &.{},
5050
.preload_paths = &.{},
51+
.shell_file_path = null, // set this to override the default html shell
52+
.js_library_path = null,
5153
.out_file_name = null, // emcc output arg will default to {wasm.name}.html if unset
5254
.install_dir = .{ .custom = "web" },
53-
.shell_file_path = null, // set this to override the default html shell
5455
},
5556
);
5657
emcc_step.dependOn(activate_emsdk_step);

build.zig

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,28 @@ pub fn emccDefaultSettings(allocator: std.mem.Allocator, options: EmccDefaultSet
167167
return settings;
168168
}
169169

170-
pub const EmccFilePath = struct {
171-
src_path: []const u8,
170+
pub const ResourceFile = struct {
171+
src_path: std.Build.LazyPath,
172172
virtual_path: ?[]const u8 = null,
173+
174+
pub fn get(self: ResourceFile, b: *std.Build) []const u8 {
175+
return if (self.virtual_path) |virtual_path|
176+
b.fmt(
177+
"{s}@{s}",
178+
.{ self.src_path.getPath(b), virtual_path },
179+
)
180+
else
181+
self.src_path.getPath(b);
182+
}
173183
};
174184

175185
pub const StepOptions = struct {
176186
optimize: std.builtin.OptimizeMode,
177187
flags: EmccFlags,
178188
settings: EmccSettings,
179189
use_preload_plugins: bool = false,
180-
embed_paths: ?[]const EmccFilePath = null,
181-
preload_paths: ?[]const EmccFilePath = null,
190+
embed_paths: ?[]const ResourceFile = null,
191+
preload_paths: ?[]const ResourceFile = null,
182192
shell_file_path: ?std.Build.LazyPath = null,
183193
js_library_path: ?std.Build.LazyPath = null,
184194
out_file_name: []const u8,
@@ -187,7 +197,7 @@ pub const StepOptions = struct {
187197

188198
pub fn emccStep(
189199
b: *std.Build,
190-
src_paths: []const []const u8,
200+
src_paths: []const std.Build.LazyPath,
191201
compile_steps: []const *std.Build.Step.Compile,
192202
options: StepOptions,
193203
) *std.Build.Step {
@@ -208,7 +218,7 @@ pub fn emccStep(
208218
}
209219

210220
for (src_paths) |src_path| {
211-
emcc.addArg(src_path);
221+
emcc.addFileArg(src_path);
212222
}
213223

214224
for (compile_steps) |compile_step| {
@@ -239,42 +249,26 @@ pub fn emccStep(
239249

240250
if (options.embed_paths) |embed_paths| {
241251
for (embed_paths) |path| {
242-
const path_arg = if (path.virtual_path) |virtual_path|
243-
std.fmt.allocPrint(
244-
b.allocator,
245-
"{s}@{s}",
246-
.{ path.src_path, virtual_path },
247-
) catch unreachable
248-
else
249-
path.src_path;
250-
emcc.addArgs(&.{ "--embed-file", path_arg });
252+
emcc.addArg("--embed-file");
253+
emcc.addFileArg(path.src_path);
251254
}
252255
}
253256

254257
if (options.preload_paths) |preload_paths| {
255258
for (preload_paths) |path| {
256-
const path_arg = if (path.virtual_path) |virtual_path|
257-
std.fmt.allocPrint(
258-
b.allocator,
259-
"{s}@{s}",
260-
.{ path.src_path, virtual_path },
261-
) catch unreachable
262-
else
263-
path.src_path;
264-
emcc.addArgs(&.{ "--preload-file", path_arg });
259+
emcc.addArg("--preload-file");
260+
emcc.addFileArg(path.src_path);
265261
}
266262
}
267263

268264
if (options.shell_file_path) |shell_file_path| {
269265
emcc.addArg("--shell-file");
270266
emcc.addFileArg(shell_file_path);
271-
emcc.addFileInput(shell_file_path);
272267
}
273268

274269
if (options.js_library_path) |js_library_path| {
275270
emcc.addArg("--js-library");
276271
emcc.addFileArg(js_library_path);
277-
emcc.addFileInput(js_library_path);
278272
}
279273

280274
const install_step = b.addInstallDirectory(.{

0 commit comments

Comments
 (0)