feature. See also
. The project being documented here (as the example) is the Zig library itself.
WebServer.buildClientWasm
fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.OptimizeMode) !Cache.Path
File
Code
fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.OptimizeMode) !Cache.Path {
const root_name = "build-web";
const arch_os_abi = "wasm32-freestanding";
const cpu_features = "baseline+atomics+bulk_memory+multivalue+mutable_globals+nontrapping_fptoint+reference_types+sign_ext";
const graph = ws.graph;
const gpa = graph.cache.gpa;
const io = graph.io;
const main_src_path: Cache.Path = .{
.root_dir = graph.zig_lib_directory,
.sub_path = "build-web/main.zig",
};
const walk_src_path: Cache.Path = .{
.root_dir = graph.zig_lib_directory,
.sub_path = "docs/wasm/Walk.zig",
};
const html_render_src_path: Cache.Path = .{
.root_dir = graph.zig_lib_directory,
.sub_path = "docs/wasm/html_render.zig",
};
var argv: std.ArrayList([]const u8) = .empty;
try argv.appendSlice(arena, &.{
graph.zig_exe, "build-exe",
"-fno-entry",
"-O", @tagName(optimize),
"-target", arch_os_abi,
"-mcpu", cpu_features,
"--cache-dir", graph.global_cache_root.path orelse ".",
"--global-cache-dir", graph.global_cache_root.path orelse ".",
"--zig-lib-dir", graph.zig_lib_directory.path orelse ".",
"--name", root_name,
"-rdynamic",
"-fsingle-threaded",
"--dep", "Walk",
"--dep", "html_render",
try std.fmt.allocPrint(arena, "-Mroot={f}", .{main_src_path}),
try std.fmt.allocPrint(arena, "-MWalk={f}", .{walk_src_path}),
"--dep", "Walk",
try std.fmt.allocPrint(arena, "-Mhtml_render={f}", .{html_render_src_path}),
"--listen=-",
});
const compile_prog_node = ws.root_prog_node.start("Compile WebAssembly Component", 0);
defer compile_prog_node.end();
const result = try std.zig.buildExeSubprocess(gpa, io, .{
.argv = argv.items,
.cache_root = graph.global_cache_root,
.root_name = root_name,
.arch_os_abi = arch_os_abi,
.cpu_features = cpu_features,
.progress_node = compile_prog_node,
});
if (!result.cache_hit) log.info("source changes detected; rebuilt wasm component", .{});
return result.path;
}