From 84af4e118c3f28ec8e5dca8fd208e74a6db2aacf Mon Sep 17 00:00:00 2001 From: iddev5 Date: Thu, 26 May 2022 18:42:32 +0530 Subject: [PATCH] mach: build: install additional files (html, js) in case of wasm Install the files template.html (renamed to application.html) and mach.js in case of WASM. Also changed the install directory to {prefix}/www. --- build.zig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/build.zig b/build.zig index 613ac983..92326946 100644 --- a/build.zig +++ b/build.zig @@ -121,6 +121,8 @@ const Packages = struct { }; }; +const web_install_dir = std.build.InstallDir{ .custom = "www" }; + pub const App = struct { b: *std.build.Builder, name: []const u8, @@ -172,6 +174,27 @@ pub const App = struct { pub fn install(app: *const App) void { app.step.install(); + + // Install additional files (src/mach.js and template.html) + // in case of wasm + if (app.step.target.toTarget().cpu.arch == .wasm32) { + // Set install directory to '{prefix}/www' + app.step.install_step.?.dest_dir = web_install_dir; + + const install_mach_js = app.b.addInstallFileWithDir( + .{ .path = thisDir() ++ "/src/mach.js" }, + web_install_dir, + "mach.js", + ); + app.step.install_step.?.step.dependOn(&install_mach_js.step); + + const install_template_html = app.b.addInstallFileWithDir( + .{ .path = thisDir() ++ "/www/template.html" }, + web_install_dir, + "application.html", + ); + app.step.install_step.?.step.dependOn(&install_template_html.step); + } } pub fn link(app: *const App, options: Options) void {