| author | |
| committer | |
| log | 9f8de83d931f1f59ffa7010afc52a1bd54778447 |
| tree | 177ff2d1a4a011a47b320f6726bf9ddfd47a9005 |
| parent | bf568ec62a06fcea5f09c725529635425f1b8a76 |
5 files changed, 20 insertions(+), 24 deletions(-)
src/Compilation.zig+2-13| ... | ... | @@ -603,11 +603,6 @@ pub const ClangPreprocessorMode = enum { |
| 603 | 603 | stdout, |
| 604 | 604 | }; |
| 605 | 605 | |
| 606 | pub const WasiExecModel = enum { | |
| 607 | command, | |
| 608 | reactor, | |
| 609 | }; | |
| 610 | ||
| 611 | 606 | pub const InitOptions = struct { |
| 612 | 607 | zig_lib_directory: Directory, |
| 613 | 608 | local_cache_directory: Directory, |
| ... | ... | @@ -731,7 +726,7 @@ pub const InitOptions = struct { |
| 731 | 726 | test_name_prefix: ?[]const u8 = null, |
| 732 | 727 | subsystem: ?std.Target.SubSystem = null, |
| 733 | 728 | /// WASI-only. Type of WASI execution model ("command" or "reactor"). |
| 734 | wasi_exec_model: ?WasiExecModel = null, | |
| 729 | wasi_exec_model: ?wasi_libc.CRTFile = null, | |
| 735 | 730 | }; |
| 736 | 731 | |
| 737 | 732 | fn addPackageTableToCacheHash( |
| ... | ... | @@ -1449,14 +1444,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1449 | 1444 | .wasi_libc_crt_file = crt_file, |
| 1450 | 1445 | }); |
| 1451 | 1446 | } |
| 1452 | const crt_file: wasi_libc.CRTFile = if (comp.bin_file.options.wasi_exec_model) |exec_model| crt_file: { | |
| 1453 | switch (exec_model) { | |
| 1454 | .command => break :crt_file wasi_libc.CRTFile.crt1_command_o, | |
| 1455 | .reactor => break :crt_file wasi_libc.CRTFile.crt1_reactor_o, | |
| 1456 | } | |
| 1457 | } else .crt1_o; | |
| 1458 | 1447 | comp.work_queue.writeAssumeCapacity(&[_]Job{ |
| 1459 | .{ .wasi_libc_crt_file = crt_file }, | |
| 1448 | .{ .wasi_libc_crt_file = comp.bin_file.options.wasi_exec_model orelse .crt1_o }, | |
| 1460 | 1449 | .{ .wasi_libc_crt_file = .libc_a }, |
| 1461 | 1450 | }); |
| 1462 | 1451 | } |
src/link.zig+1-1| ... | ... | @@ -119,7 +119,7 @@ pub const Options = struct { |
| 119 | 119 | libc_installation: ?*const LibCInstallation, |
| 120 | 120 | |
| 121 | 121 | /// WASI-only. Type of WASI execution model ("command" or "reactor"). |
| 122 | wasi_exec_model: ?Compilation.WasiExecModel = null, | |
| 122 | wasi_exec_model: ?wasi_libc.CRTFile = null, | |
| 123 | 123 | |
| 124 | 124 | pub fn effectiveOutputMode(options: Options) std.builtin.OutputMode { |
| 125 | 125 | return if (options.use_lld) .Obj else options.output_mode; |
src/link/Wasm.zig+5-7| ... | ... | @@ -684,7 +684,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 684 | 684 | |
| 685 | 685 | // Reactor execution model does not have _start so lld doesn't look for it. |
| 686 | 686 | if (self.base.options.wasi_exec_model) |exec_model| blk: { |
| 687 | if (exec_model != .reactor) break :blk; | |
| 687 | if (exec_model != .crt1_reactor_o) break :blk; | |
| 688 | 688 | try argv.append("--no-entry"); |
| 689 | 689 | } |
| 690 | 690 | } else { |
| ... | ... | @@ -698,12 +698,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 698 | 698 | }); |
| 699 | 699 | |
| 700 | 700 | if (target.os.tag == .wasi) { |
| 701 | const crt_name = if (self.base.options.wasi_exec_model) |exec_model| | |
| 702 | try std.fmt.allocPrint(arena, "crt1-{s}.o", .{@tagName(exec_model)}) | |
| 703 | else | |
| 704 | "crt1.o"; | |
| 705 | try argv.append(try comp.get_libc_crt_file(arena, crt_name)); | |
| 706 | ||
| 707 | 701 | const is_exe_or_dyn_lib = self.base.options.output_mode == .Exe or |
| 708 | 702 | (self.base.options.output_mode == .Lib and self.base.options.link_mode == .Dynamic); |
| 709 | 703 | if (is_exe_or_dyn_lib) { |
| ... | ... | @@ -727,6 +721,10 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 727 | 721 | } |
| 728 | 722 | |
| 729 | 723 | if (self.base.options.link_libc) { |
| 724 | try argv.append(try comp.get_libc_crt_file( | |
| 725 | arena, | |
| 726 | wasi_libc.crtFileFullName(self.base.options.wasi_exec_model orelse .crt1_o), | |
| 727 | )); | |
| 730 | 728 | try argv.append(try comp.get_libc_crt_file(arena, "libc.a")); |
| 731 | 729 | } |
| 732 | 730 | } |
src/main.zig+3-3| ... | ... | @@ -613,7 +613,7 @@ fn buildOutputType( |
| 613 | 613 | var subsystem: ?std.Target.SubSystem = null; |
| 614 | 614 | var major_subsystem_version: ?u32 = null; |
| 615 | 615 | var minor_subsystem_version: ?u32 = null; |
| 616 | var wasi_exec_model: ?Compilation.WasiExecModel = null; | |
| 616 | var wasi_exec_model: ?wasi_libc.CRTFile = null; | |
| 617 | 617 | |
| 618 | 618 | var system_libs = std.ArrayList([]const u8).init(gpa); |
| 619 | 619 | defer system_libs.deinit(); |
| ... | ... | @@ -1257,9 +1257,9 @@ fn buildOutputType( |
| 1257 | 1257 | .strip => strip = true, |
| 1258 | 1258 | .exec_model => { |
| 1259 | 1259 | if (std.mem.eql(u8, it.only_arg, "reactor")) { |
| 1260 | wasi_exec_model = Compilation.WasiExecModel.reactor; | |
| 1260 | wasi_exec_model = .crt1_reactor_o; | |
| 1261 | 1261 | } else if (std.mem.eql(u8, it.only_arg, "command")) { |
| 1262 | wasi_exec_model = Compilation.WasiExecModel.command; | |
| 1262 | wasi_exec_model = .crt1_command_o; | |
| 1263 | 1263 | } |
| 1264 | 1264 | }, |
| 1265 | 1265 | } |
src/wasi_libc.zig+9| ... | ... | @@ -45,6 +45,15 @@ pub fn emulatedLibCRFileLibName(crt_file: CRTFile) []const u8 { |
| 45 | 45 | }; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | pub fn crtFileFullName(crt_file: CRTFile) []const u8 { | |
| 49 | return switch (crt_file) { | |
| 50 | .crt1_o => "crt1.o", | |
| 51 | .crt1_reactor_o => "crt1-reactor.o", | |
| 52 | .crt1_command_o => "crt1-command.o", | |
| 53 | else => unreachable, | |
| 54 | }; | |
| 55 | } | |
| 56 | ||
| 48 | 57 | pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 49 | 58 | if (!build_options.have_llvm) { |
| 50 | 59 | return error.ZigCompilerNotBuiltWithLLVMExtensions; |