feature. See also
. The project being documented here (as the example) is the Zig library itself.
std-docs.serveWasm
fn serveWasm(
request: *std.http.Server.Request,
context: *Context,
optimize_mode: std.builtin.OptimizeMode,
) !void
File
Code
fn serveWasm(
request: *std.http.Server.Request,
context: *Context,
optimize_mode: std.builtin.OptimizeMode,
) !void {
const gpa = context.gpa;
const io = context.io;
var arena_instance = std.heap.ArenaAllocator.init(gpa);
defer arena_instance.deinit();
const arena = arena_instance.allocator();
// and see the changes without restarting the server.
const wasm_base_path = try buildWasmBinary(arena, context, optimize_mode);
const target = std.zig.system.resolveTargetQuery(io, std.Build.parseTargetQuery(.{
.arch_os_abi = autodoc_arch_os_abi,
.cpu_features = autodoc_cpu_features,
}) catch unreachable) catch unreachable;
const bin_name = try std.zig.binNameAlloc(arena, .{
.root_name = autodoc_root_name,
.cpu_arch = target.cpu.arch,
.os_tag = target.os.tag,
.ofmt = target.ofmt,
.abi = target.abi,
.output_mode = .Exe,
});
const bin_path = try wasm_base_path.join(arena, bin_name);
const file_contents = try bin_path.root_dir.handle.readFileAlloc(io, bin_path.sub_path, gpa, .limited(10 * 1024 * 1024));
defer gpa.free(file_contents);
try request.respond(file_contents, .{
.extra_headers = &.{
.{ .name = "content-type", .value = "application/wasm" },
cache_control_header,
},
});
}