authorgravatar for shritesh@shritesh.comShritesh Bhattarai <shritesh@shritesh.com> 2019-05-01 17:48:26-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-03 15:56:33-04:00
log5c04c22bcc04fba8f84fa8e5ec57482c13d0a488
tree6626d4d0865d4940904c74bc0f4e286e5fd27f35
parentf6937db7d610163f9dac6f69b76bc38e62580a0d

docgen: support wasm and wasi


2 files changed, 33 insertions(+), 1 deletions(-)

doc/docgen.zig+6-1
......@@ -512,6 +512,10 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
512512 target_str = "x86_64-windows";
513513 } else if (mem.eql(u8, end_tag_name, "target_linux_x86_64")) {
514514 target_str = "x86_64-linux";
515 } else if (mem.eql(u8, end_tag_name, "target_wasm")) {
516 target_str = "wasm32-freestanding";
517 } else if (mem.eql(u8, end_tag_name, "target_wasi")) {
518 target_str = "wasm32-wasi";
515519 } else if (mem.eql(u8, end_tag_name, "link_libc")) {
516520 link_libc = true;
517521 } 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
11011105 _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile");
11021106
11031107 if (code.target_str) |triple| {
1104 if (mem.startsWith(u8, triple, "x86_64-linux") and
1108 if (mem.startsWith(u8, triple, "wasm32") or
1109 mem.startsWith(u8, triple, "x86_64-linux") and
11051110 (builtin.os != builtin.Os.linux or builtin.arch != builtin.Arch.x86_64))
11061111 {
11071112 // skip execution
doc/langref.html.in+27
......@@ -8958,6 +8958,33 @@ all your base are belong to us</code></pre>
89588958 {#see_also|Targets|Zig Build System#}
89598959 {#header_close#}
89608960 {#header_close#}
8961 {#header_open|WebAssembly#}
8962 {#header_open|Freestanding#}
8963 {#code_begin|exe|wasm#}
8964 {#target_wasm#}
8965extern fn print(i32) void;
8966
8967export fn add(a: i32, b: i32) void {
8968 print(a + b);
8969}
8970 {#code_end#}
8971 {#header_close#}
8972 {#header_open|WASI#}
8973 {#code_begin|exe|wasi#}
8974 {#target_wasi#}
8975const std = @import("std");
8976
8977pub fn main() !void {
8978 const args = try std.os.argsAlloc(std.heap.wasm_allocator);
8979 defer std.os.argsFree(std.heap.wasm_allocator, args);
8980
8981 for (args) |arg, i| {
8982 std.debug.warn("{}: {}\n", i, arg);
8983 }
8984}
8985 {#code_end#}
8986 {#header_close#}
8987 {#header_close#}
89618988 {#header_open|Targets#}
89628989 <p>
89638990 Zig supports generating code for all targets that LLVM supports. Here is