aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-06-09 10:23:46 +0200
committerJakub Konka <kubkon@jakubkonka.com>2021-06-09 11:11:55 +0200
commit9f8de83d931f1f59ffa7010afc52a1bd54778447 (patch)
tree177ff2d1a4a011a47b320f6726bf9ddfd47a9005 /src
parentbf568ec62a06fcea5f09c725529635425f1b8a76 (diff)
downloadzig-9f8de83d931f1f59ffa7010afc52a1bd54778447.tar.gz
zig-9f8de83d931f1f59ffa7010afc52a1bd54778447.zip
cc,wasi: use wasi_libc.CRTFile directly instead of WasiExecModel
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig15
-rw-r--r--src/link.zig2
-rw-r--r--src/link/Wasm.zig12
-rw-r--r--src/main.zig6
-rw-r--r--src/wasi_libc.zig9
5 files changed, 20 insertions, 24 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index e90c635808..5c75caa598 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -603,11 +603,6 @@ pub const ClangPreprocessorMode = enum {
stdout,
};
-pub const WasiExecModel = enum {
- command,
- reactor,
-};
-
pub const InitOptions = struct {
zig_lib_directory: Directory,
local_cache_directory: Directory,
@@ -731,7 +726,7 @@ pub const InitOptions = struct {
test_name_prefix: ?[]const u8 = null,
subsystem: ?std.Target.SubSystem = null,
/// WASI-only. Type of WASI execution model ("command" or "reactor").
- wasi_exec_model: ?WasiExecModel = null,
+ wasi_exec_model: ?wasi_libc.CRTFile = null,
};
fn addPackageTableToCacheHash(
@@ -1449,14 +1444,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.wasi_libc_crt_file = crt_file,
});
}
- const crt_file: wasi_libc.CRTFile = if (comp.bin_file.options.wasi_exec_model) |exec_model| crt_file: {
- switch (exec_model) {
- .command => break :crt_file wasi_libc.CRTFile.crt1_command_o,
- .reactor => break :crt_file wasi_libc.CRTFile.crt1_reactor_o,
- }
- } else .crt1_o;
comp.work_queue.writeAssumeCapacity(&[_]Job{
- .{ .wasi_libc_crt_file = crt_file },
+ .{ .wasi_libc_crt_file = comp.bin_file.options.wasi_exec_model orelse .crt1_o },
.{ .wasi_libc_crt_file = .libc_a },
});
}
diff --git a/src/link.zig b/src/link.zig
index 534b39ebbb..d1508c29cd 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -119,7 +119,7 @@ pub const Options = struct {
libc_installation: ?*const LibCInstallation,
/// WASI-only. Type of WASI execution model ("command" or "reactor").
- wasi_exec_model: ?Compilation.WasiExecModel = null,
+ wasi_exec_model: ?wasi_libc.CRTFile = null,
pub fn effectiveOutputMode(options: Options) std.builtin.OutputMode {
return if (options.use_lld) .Obj else options.output_mode;
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index bfe1902826..8f376e6f0d 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -684,7 +684,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
// Reactor execution model does not have _start so lld doesn't look for it.
if (self.base.options.wasi_exec_model) |exec_model| blk: {
- if (exec_model != .reactor) break :blk;
+ if (exec_model != .crt1_reactor_o) break :blk;
try argv.append("--no-entry");
}
} else {
@@ -698,12 +698,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
});
if (target.os.tag == .wasi) {
- const crt_name = if (self.base.options.wasi_exec_model) |exec_model|
- try std.fmt.allocPrint(arena, "crt1-{s}.o", .{@tagName(exec_model)})
- else
- "crt1.o";
- try argv.append(try comp.get_libc_crt_file(arena, crt_name));
-
const is_exe_or_dyn_lib = self.base.options.output_mode == .Exe or
(self.base.options.output_mode == .Lib and self.base.options.link_mode == .Dynamic);
if (is_exe_or_dyn_lib) {
@@ -727,6 +721,10 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
}
if (self.base.options.link_libc) {
+ try argv.append(try comp.get_libc_crt_file(
+ arena,
+ wasi_libc.crtFileFullName(self.base.options.wasi_exec_model orelse .crt1_o),
+ ));
try argv.append(try comp.get_libc_crt_file(arena, "libc.a"));
}
}
diff --git a/src/main.zig b/src/main.zig
index 8b1c640cfb..149a94dbd0 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -613,7 +613,7 @@ fn buildOutputType(
var subsystem: ?std.Target.SubSystem = null;
var major_subsystem_version: ?u32 = null;
var minor_subsystem_version: ?u32 = null;
- var wasi_exec_model: ?Compilation.WasiExecModel = null;
+ var wasi_exec_model: ?wasi_libc.CRTFile = null;
var system_libs = std.ArrayList([]const u8).init(gpa);
defer system_libs.deinit();
@@ -1257,9 +1257,9 @@ fn buildOutputType(
.strip => strip = true,
.exec_model => {
if (std.mem.eql(u8, it.only_arg, "reactor")) {
- wasi_exec_model = Compilation.WasiExecModel.reactor;
+ wasi_exec_model = .crt1_reactor_o;
} else if (std.mem.eql(u8, it.only_arg, "command")) {
- wasi_exec_model = Compilation.WasiExecModel.command;
+ wasi_exec_model = .crt1_command_o;
}
},
}
diff --git a/src/wasi_libc.zig b/src/wasi_libc.zig
index b61ba5091c..8f62afccba 100644
--- a/src/wasi_libc.zig
+++ b/src/wasi_libc.zig
@@ -45,6 +45,15 @@ pub fn emulatedLibCRFileLibName(crt_file: CRTFile) []const u8 {
};
}
+pub fn crtFileFullName(crt_file: CRTFile) []const u8 {
+ return switch (crt_file) {
+ .crt1_o => "crt1.o",
+ .crt1_reactor_o => "crt1-reactor.o",
+ .crt1_command_o => "crt1-command.o",
+ else => unreachable,
+ };
+}
+
pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
if (!build_options.have_llvm) {
return error.ZigCompilerNotBuiltWithLLVMExtensions;