docgen: support wasm and wasi

This commit is contained in:
Shritesh Bhattarai 2019-05-01 17:48:26 -05:00 committed by Andrew Kelley
parent f6937db7d6
commit 5c04c22bcc
2 changed files with 33 additions and 1 deletions

View File

@ -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

View File

@ -8958,6 +8958,33 @@ all your base are belong to us</code></pre>
{#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#}
<p>
Zig supports generating code for all targets that LLVM supports. Here is