| author | |
| committer | |
| log | 9d311e9960952838edb19a422e5023c670f9995d |
| tree | c3539c2eb0a5bfcef528ed9d7197ea3efb8d6c02 |
| parent | 2b0d322ea003907dc2111864cea259e5e0043328 |
| parent | bd325d1bd94361024f755c8bac3011a5cdffe573 |
| signature |
wasm: produce static lib by default and rename produced object files to simply .o from .o.wasm5 files changed, 21 insertions(+), 15 deletions(-)
doc/docgen.zig+17| ... | @@ -284,6 +284,7 @@ const Code = struct { | ... | @@ -284,6 +284,7 @@ const Code = struct { |
| 284 | link_objects: []const []const u8, | 284 | link_objects: []const []const u8, |
| 285 | target_str: ?[]const u8, | 285 | target_str: ?[]const u8, |
| 286 | link_libc: bool, | 286 | link_libc: bool, |
| 287 | link_mode: ?std.builtin.LinkMode, | ||
| 287 | disable_cache: bool, | 288 | disable_cache: bool, |
| 288 | 289 | ||
| 289 | const Id = union(enum) { | 290 | const Id = union(enum) { |
| ... | @@ -533,6 +534,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { | ... | @@ -533,6 +534,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 533 | defer link_objects.deinit(); | 534 | defer link_objects.deinit(); |
| 534 | var target_str: ?[]const u8 = null; | 535 | var target_str: ?[]const u8 = null; |
| 535 | var link_libc = false; | 536 | var link_libc = false; |
| 537 | var link_mode: ?std.builtin.LinkMode = null; | ||
| 536 | var disable_cache = false; | 538 | var disable_cache = false; |
| 537 | 539 | ||
| 538 | const source_token = while (true) { | 540 | const source_token = while (true) { |
| ... | @@ -562,6 +564,8 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { | ... | @@ -562,6 +564,8 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 562 | target_str = "wasm32-wasi"; | 564 | target_str = "wasm32-wasi"; |
| 563 | } else if (mem.eql(u8, end_tag_name, "link_libc")) { | 565 | } else if (mem.eql(u8, end_tag_name, "link_libc")) { |
| 564 | link_libc = true; | 566 | link_libc = true; |
| 567 | } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) { | ||
| 568 | link_mode = .Dynamic; | ||
| 565 | } else if (mem.eql(u8, end_tag_name, "code_end")) { | 569 | } else if (mem.eql(u8, end_tag_name, "code_end")) { |
| 566 | _ = try eatToken(tokenizer, Token.Id.BracketClose); | 570 | _ = try eatToken(tokenizer, Token.Id.BracketClose); |
| 567 | break content_tok; | 571 | break content_tok; |
| ... | @@ -585,6 +589,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { | ... | @@ -585,6 +589,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 585 | .link_objects = link_objects.toOwnedSlice(), | 589 | .link_objects = link_objects.toOwnedSlice(), |
| 586 | .target_str = target_str, | 590 | .target_str = target_str, |
| 587 | .link_libc = link_libc, | 591 | .link_libc = link_libc, |
| 592 | .link_mode = link_mode, | ||
| 588 | .disable_cache = disable_cache, | 593 | .disable_cache = disable_cache, |
| 589 | }, | 594 | }, |
| 590 | }); | 595 | }); |
| ... | @@ -1468,6 +1473,18 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any | ... | @@ -1468,6 +1473,18 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any |
| 1468 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); | 1473 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1469 | try out.print(" -target {s}", .{triple}); | 1474 | try out.print(" -target {s}", .{triple}); |
| 1470 | } | 1475 | } |
| 1476 | if (code.link_mode) |link_mode| { | ||
| 1477 | switch (link_mode) { | ||
| 1478 | .Static => { | ||
| 1479 | try test_args.append("-static"); | ||
| 1480 | try out.print(" -static", .{}); | ||
| 1481 | }, | ||
| 1482 | .Dynamic => { | ||
| 1483 | try test_args.append("-dynamic"); | ||
| 1484 | try out.print(" -dynamic", .{}); | ||
| 1485 | }, | ||
| 1486 | } | ||
| 1487 | } | ||
| 1471 | const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{}); | 1488 | const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{}); |
| 1472 | const escaped_stderr = try escapeHtml(allocator, result.stderr); | 1489 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1473 | const escaped_stdout = try escapeHtml(allocator, result.stdout); | 1490 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
doc/langref.html.in+3-2| ... | @@ -10036,10 +10036,11 @@ all your base are belong to us</code></pre> | ... | @@ -10036,10 +10036,11 @@ all your base are belong to us</code></pre> |
| 10036 | {#header_open|WebAssembly#} | 10036 | {#header_open|WebAssembly#} |
| 10037 | <p>Zig supports building for WebAssembly out of the box.</p> | 10037 | <p>Zig supports building for WebAssembly out of the box.</p> |
| 10038 | {#header_open|Freestanding#} | 10038 | {#header_open|Freestanding#} |
| 10039 | <p>For host environments like the web browser and nodejs, build as a library using the freestanding OS target. | 10039 | <p>For host environments like the web browser and nodejs, build as a dynamic library using the freestanding |
| 10040 | Here's an example of running Zig code compiled to WebAssembly with nodejs.</p> | 10040 | OS target. Here's an example of running Zig code compiled to WebAssembly with nodejs.</p> |
| 10041 | {#code_begin|lib|math#} | 10041 | {#code_begin|lib|math#} |
| 10042 | {#target_wasm#} | 10042 | {#target_wasm#} |
| 10043 | {#link_mode_dynamic#} | ||
| 10043 | extern fn print(i32) void; | 10044 | extern fn print(i32) void; |
| 10044 | 10045 | ||
| 10045 | export fn add(a: i32, b: i32) void { | 10046 | export fn add(a: i32, b: i32) void { |
lib/std/target.zig-6| ... | @@ -1259,9 +1259,6 @@ pub const Target = struct { | ... | @@ -1259,9 +1259,6 @@ pub const Target = struct { |
| 1259 | } | 1259 | } |
| 1260 | 1260 | ||
| 1261 | pub fn oFileExt_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 { | 1261 | pub fn oFileExt_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 { |
| 1262 | if (cpu_arch.isWasm()) { | ||
| 1263 | return ".o.wasm"; | ||
| 1264 | } | ||
| 1265 | switch (abi) { | 1262 | switch (abi) { |
| 1266 | .msvc => return ".obj", | 1263 | .msvc => return ".obj", |
| 1267 | else => return ".o", | 1264 | else => return ".o", |
| ... | @@ -1289,9 +1286,6 @@ pub const Target = struct { | ... | @@ -1289,9 +1286,6 @@ pub const Target = struct { |
| 1289 | } | 1286 | } |
| 1290 | 1287 | ||
| 1291 | pub fn staticLibSuffix_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 { | 1288 | pub fn staticLibSuffix_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 { |
| 1292 | if (cpu_arch.isWasm()) { | ||
| 1293 | return ".wasm"; | ||
| 1294 | } | ||
| 1295 | switch (abi) { | 1289 | switch (abi) { |
| 1296 | .msvc => return ".lib", | 1290 | .msvc => return ".lib", |
| 1297 | else => return ".a", | 1291 | else => return ".a", |
src/link/Wasm.zig+1-1| ... | @@ -698,7 +698,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { | ... | @@ -698,7 +698,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 698 | 698 | ||
| 699 | if (link_in_crt) { | 699 | if (link_in_crt) { |
| 700 | // TODO work out if we want standard crt, a reactor or a command | 700 | // TODO work out if we want standard crt, a reactor or a command |
| 701 | try argv.append(try comp.get_libc_crt_file(arena, "crt.o.wasm")); | 701 | try argv.append(try comp.get_libc_crt_file(arena, "crt.o")); |
| 702 | } | 702 | } |
| 703 | 703 | ||
| 704 | if (!is_obj and self.base.options.link_libc) { | 704 | if (!is_obj and self.base.options.link_libc) { |
src/main.zig-6| ... | @@ -1548,12 +1548,6 @@ fn buildOutputType( | ... | @@ -1548,12 +1548,6 @@ fn buildOutputType( |
| 1548 | link_libcpp = true; | 1548 | link_libcpp = true; |
| 1549 | } | 1549 | } |
| 1550 | 1550 | ||
| 1551 | if (cross_target.getCpuArch().isWasm() and output_mode == .Lib and link_mode == null) { | ||
| 1552 | // If link_mode is unspecified, always link as dynamic library when targeting Wasm, | ||
| 1553 | // so that wasm-ld is invoked rather than standard archiver. | ||
| 1554 | link_mode = .Dynamic; | ||
| 1555 | } | ||
| 1556 | |||
| 1557 | // Now that we have target info, we can find out if any of the system libraries | 1551 | // Now that we have target info, we can find out if any of the system libraries |
| 1558 | // are part of libc or libc++. We remove them from the list and communicate their | 1552 | // are part of libc or libc++. We remove them from the list and communicate their |
| 1559 | // existence via flags instead. | 1553 | // existence via flags instead. |