Skip to content

Commit 75a8f43

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 75a8f43

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
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/stage1/codegen.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -9912,9 +9912,9 @@ void codegen_build_object(CodeGen *g) {
99129912
auto export_it = g->exported_symbol_names.entry_iterator();
99139913
decltype(g->exported_symbol_names)::Entry *curr_entry = nullptr;
99149914
while ((curr_entry = export_it.next()) != nullptr) {
9915-
if ((err = stage2_append_symbol(&g->stage1, buf_ptr(curr_entry->key)))) {
9916-
fprintf(stderr, "Unable to export symbol '%s': %s\n", buf_ptr(curr_entry->key), err_str(err));
9917-
}
9915+
// if ((err = stage2_append_symbol(&g->stage1, buf_ptr(curr_entry->key)))) {
9916+
// fprintf(stderr, "Unable to export symbol '%s': %s\n", buf_ptr(curr_entry->key), err_str(err));
9917+
// }
99189918
}
99199919
}
99209920
}

0 commit comments

Comments
 (0)