Pass --allow-unknown-exports to wasmtime

Also skip exporting non-function symbols when we're building a WASI command using the stage2 llvm backend.
This commit is contained in:
Luuk de Gram
2022-01-06 20:18:24 +01:00
parent 6d951aff7e
commit 247b638ccf
7 changed files with 17 additions and 12 deletions

View File

@@ -2659,6 +2659,8 @@ pub const LibExeObjStep = struct {
try zig_args.append(bin_name);
try zig_args.append("--test-cmd");
try zig_args.append("--dir=.");
try zig_args.append("--test-cmd");
try zig_args.append("--allow-unknown-exports"); // TODO: Remove when stage2 is default compiler
try zig_args.append("--test-cmd-bin");
} else {
try zig_args.append("--test-no-exec");

View File

@@ -1882,9 +1882,9 @@ pub fn destroy(self: *Compilation) void {
self.astgen_wait_group.deinit();
for (self.export_symbol_names.items) |symbol_name| {
self.gpa.free(symbol_name);
gpa.free(symbol_name);
}
self.export_symbol_names.deinit(self.gpa);
self.export_symbol_names.deinit(gpa);
// This destroys `self`.
self.arena_state.promote(gpa).deinit();

View File

@@ -1256,8 +1256,15 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
try argv.append(try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name}));
}
} else {
const skip_export_non_fn = target.os.tag == .wasi and
self.base.options.wasi_exec_model == .command;
for (module.decl_exports.values()) |exports| {
for (exports) |exprt| {
if (skip_export_non_fn and exprt.exported_decl.ty.zigTypeTag() != .Fn) {
// skip exporting symbols when we're building a WASI command
// and the symbol is not a function
continue;
}
const symbol_name = exprt.exported_decl.name;
const arg = try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name});
try argv.append(arg);

View File

@@ -468,13 +468,9 @@ export fn stage2_fetch_file(
return contents.ptr;
}
export fn stage2_append_symbol(stage1: *Module, name_ptr: ?[*:0]const u8) Error {
export fn stage2_append_symbol(stage1: *Module, name_ptr: [*c]const u8, name_len: usize) Error {
if (name_len == 0) return Error.None;
const comp = @intToPtr(*Compilation, stage1.userdata);
if (name_ptr) |unwrapped_name| {
const symbol_name = std.mem.sliceTo(unwrapped_name, 0);
if (symbol_name.len == 0) return Error.None;
comp.export_symbol_names.append(comp.gpa, symbol_name) catch return Error.OutOfMemory;
}
comp.export_symbol_names.append(comp.gpa, name_ptr[0..name_len]) catch return Error.OutOfMemory;
return Error.None;
}

View File

@@ -9912,7 +9912,7 @@ void codegen_build_object(CodeGen *g) {
auto export_it = g->exported_symbol_names.entry_iterator();
decltype(g->exported_symbol_names)::Entry *curr_entry = nullptr;
while ((curr_entry = export_it.next()) != nullptr) {
if ((err = stage2_append_symbol(&g->stage1, buf_ptr(curr_entry->key)))) {
if ((err = stage2_append_symbol(&g->stage1, buf_ptr(curr_entry->key), buf_len(curr_entry->key)))) {
fprintf(stderr, "Unable to export symbol '%s': %s\n", buf_ptr(curr_entry->key), err_str(err));
}
}

View File

@@ -183,6 +183,6 @@ ZIG_EXTERN_C const char *stage2_add_link_lib(struct ZigStage1 *stage1,
const char *symbol_name_ptr, size_t symbol_name_len);
// ABI warning
ZIG_EXTERN_C enum Error stage2_append_symbol(struct ZigStage1 *stage1, const char *name_ptr);
ZIG_EXTERN_C enum Error stage2_append_symbol(struct ZigStage1 *stage1, const char *name_ptr, size_t name_len);
#endif

View File

@@ -555,7 +555,7 @@ struct Stage2SemVer stage2_version(void) {
return {ZIG_VERSION_MAJOR, ZIG_VERSION_MINOR, ZIG_VERSION_PATCH};
}
Error stage2_append_symbol(struct ZigStage1 *stage1, const char *name_ptr)
Error stage2_append_symbol(struct ZigStage1 *stage1, const char *name_ptr, size_t name_len)
{
return ErrorNone;
}