Skip to content

Commit da6da66

Browse files
committed
Pass --allow-unknown-exports to wasmtime
Also skip exporting non-function symbols when we're building a WASI command using the stage2 llvm backend.
1 parent 6d951af commit da6da66

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

lib/std/build.zig

+2
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,8 @@ pub const LibExeObjStep = struct {
26592659
try zig_args.append(bin_name);
26602660
try zig_args.append("--test-cmd");
26612661
try zig_args.append("--dir=.");
2662+
try zig_args.append("--test-cmd");
2663+
try zig_args.append("--allow-unknown-exports"); // TODO: Remove when stage2 is default compiler
26622664
try zig_args.append("--test-cmd-bin");
26632665
} else {
26642666
try zig_args.append("--test-no-exec");

src/Compilation.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -1882,9 +1882,9 @@ pub fn destroy(self: *Compilation) void {
18821882
self.astgen_wait_group.deinit();
18831883

18841884
for (self.export_symbol_names.items) |symbol_name| {
1885-
self.gpa.free(symbol_name);
1885+
gpa.free(symbol_name);
18861886
}
1887-
self.export_symbol_names.deinit(self.gpa);
1887+
self.export_symbol_names.deinit(gpa);
18881888

18891889
// This destroys `self`.
18901890
self.arena_state.promote(gpa).deinit();

src/link/Wasm.zig

+7
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,15 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
12561256
try argv.append(try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name}));
12571257
}
12581258
} else {
1259+
const skip_export_non_fn = target.os.tag == .wasi and
1260+
self.base.options.wasi_exec_model == .command;
12591261
for (module.decl_exports.values()) |exports| {
12601262
for (exports) |exprt| {
1263+
if (skip_export_non_fn and exprt.exported_decl.ty.zigTypeTag() != .Fn) {
1264+
// skip exporting symbols when we're building a WASI command
1265+
// and the symbol is not a function
1266+
continue;
1267+
}
12611268
const symbol_name = exprt.exported_decl.name;
12621269
const arg = try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name});
12631270
try argv.append(arg);

src/test.zig

+1
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ pub const TestContext = struct {
11761176

11771177
.wasmtime => |wasmtime_bin_name| if (enable_wasmtime) {
11781178
try argv.append(wasmtime_bin_name);
1179+
try argv.append("--allow-unknown-exports"); // TODO: Remove this when we stage2 is default compiler
11791180
try argv.append("--dir=.");
11801181
try argv.append(exe_path);
11811182
} else {

0 commit comments

Comments
 (0)