diff --git a/doc/docgen.zig b/doc/docgen.zig index e2a5348614..b7c3f1e21c 100644 --- a/doc/docgen.zig +++ b/doc/docgen.zig @@ -512,6 +512,10 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { target_str = "x86_64-windows"; } else if (mem.eql(u8, end_tag_name, "target_linux_x86_64")) { target_str = "x86_64-linux"; + } else if (mem.eql(u8, end_tag_name, "target_wasm")) { + target_str = "wasm32-freestanding"; + } else if (mem.eql(u8, end_tag_name, "target_wasi")) { + target_str = "wasm32-wasi"; } else if (mem.eql(u8, end_tag_name, "link_libc")) { link_libc = true; } else if (mem.eql(u8, end_tag_name, "code_end")) { @@ -1101,7 +1105,8 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile"); if (code.target_str) |triple| { - if (mem.startsWith(u8, triple, "x86_64-linux") and + if (mem.startsWith(u8, triple, "wasm32") or + mem.startsWith(u8, triple, "x86_64-linux") and (builtin.os != builtin.Os.linux or builtin.arch != builtin.Arch.x86_64)) { // skip execution diff --git a/doc/langref.html.in b/doc/langref.html.in index b8a774290c..d11204f619 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -8958,6 +8958,33 @@ all your base are belong to us {#see_also|Targets|Zig Build System#} {#header_close#} {#header_close#} + {#header_open|WebAssembly#} + {#header_open|Freestanding#} + {#code_begin|exe|wasm#} + {#target_wasm#} +extern fn print(i32) void; + +export fn add(a: i32, b: i32) void { + print(a + b); +} + {#code_end#} + {#header_close#} + {#header_open|WASI#} + {#code_begin|exe|wasi#} + {#target_wasi#} +const std = @import("std"); + +pub fn main() !void { + const args = try std.os.argsAlloc(std.heap.wasm_allocator); + defer std.os.argsFree(std.heap.wasm_allocator, args); + + for (args) |arg, i| { + std.debug.warn("{}: {}\n", i, arg); + } +} + {#code_end#} + {#header_close#} + {#header_close#} {#header_open|Targets#}

Zig supports generating code for all targets that LLVM supports. Here is