authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-09 10:23:46+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-09 11:11:55+02:00
log9f8de83d931f1f59ffa7010afc52a1bd54778447
tree177ff2d1a4a011a47b320f6726bf9ddfd47a9005
parentbf568ec62a06fcea5f09c725529635425f1b8a76

cc,wasi: use wasi_libc.CRTFile directly instead of WasiExecModel


5 files changed, 20 insertions(+), 24 deletions(-)

src/Compilation.zig+2-13
......@@ -603,11 +603,6 @@ pub const ClangPreprocessorMode = enum {
603603 stdout,
604604};
605605
606pub const WasiExecModel = enum {
607 command,
608 reactor,
609};
610
611606pub const InitOptions = struct {
612607 zig_lib_directory: Directory,
613608 local_cache_directory: Directory,
......@@ -731,7 +726,7 @@ pub const InitOptions = struct {
731726 test_name_prefix: ?[]const u8 = null,
732727 subsystem: ?std.Target.SubSystem = null,
733728 /// WASI-only. Type of WASI execution model ("command" or "reactor").
734 wasi_exec_model: ?WasiExecModel = null,
729 wasi_exec_model: ?wasi_libc.CRTFile = null,
735730};
736731
737732fn addPackageTableToCacheHash(
......@@ -1449,14 +1444,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
14491444 .wasi_libc_crt_file = crt_file,
14501445 });
14511446 }
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;
14581447 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 },
14601449 .{ .wasi_libc_crt_file = .libc_a },
14611450 });
14621451 }
src/link.zig+1-1
......@@ -119,7 +119,7 @@ pub const Options = struct {
119119 libc_installation: ?*const LibCInstallation,
120120
121121 /// 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,
123123
124124 pub fn effectiveOutputMode(options: Options) std.builtin.OutputMode {
125125 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 {
684684
685685 // Reactor execution model does not have _start so lld doesn't look for it.
686686 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;
688688 try argv.append("--no-entry");
689689 }
690690 } else {
......@@ -698,12 +698,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
698698 });
699699
700700 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
707701 const is_exe_or_dyn_lib = self.base.options.output_mode == .Exe or
708702 (self.base.options.output_mode == .Lib and self.base.options.link_mode == .Dynamic);
709703 if (is_exe_or_dyn_lib) {
......@@ -727,6 +721,10 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
727721 }
728722
729723 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 ));
730728 try argv.append(try comp.get_libc_crt_file(arena, "libc.a"));
731729 }
732730 }
src/main.zig+3-3
......@@ -613,7 +613,7 @@ fn buildOutputType(
613613 var subsystem: ?std.Target.SubSystem = null;
614614 var major_subsystem_version: ?u32 = null;
615615 var minor_subsystem_version: ?u32 = null;
616 var wasi_exec_model: ?Compilation.WasiExecModel = null;
616 var wasi_exec_model: ?wasi_libc.CRTFile = null;
617617
618618 var system_libs = std.ArrayList([]const u8).init(gpa);
619619 defer system_libs.deinit();
......@@ -1257,9 +1257,9 @@ fn buildOutputType(
12571257 .strip => strip = true,
12581258 .exec_model => {
12591259 if (std.mem.eql(u8, it.only_arg, "reactor")) {
1260 wasi_exec_model = Compilation.WasiExecModel.reactor;
1260 wasi_exec_model = .crt1_reactor_o;
12611261 } else if (std.mem.eql(u8, it.only_arg, "command")) {
1262 wasi_exec_model = Compilation.WasiExecModel.command;
1262 wasi_exec_model = .crt1_command_o;
12631263 }
12641264 },
12651265 }
src/wasi_libc.zig+9
......@@ -45,6 +45,15 @@ pub fn emulatedLibCRFileLibName(crt_file: CRTFile) []const u8 {
4545 };
4646}
4747
48pub 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
4857pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
4958 if (!build_options.have_llvm) {
5059 return error.ZigCompilerNotBuiltWithLLVMExtensions;