diff --git a/src-self-hosted/link.zig b/src-self-hosted/link.zig index 6ed76ce561..cbc376f7ab 100644 --- a/src-self-hosted/link.zig +++ b/src-self-hosted/link.zig @@ -100,11 +100,13 @@ pub const File = struct { } pub fn makeExecutable(base: *File) !void { - std.debug.assert(base.tag != .c); - if (base.file) |f| { - f.close(); - base.file = null; - + switch (base.tag) { + .c => unreachable, + .wasm => {}, + else => if (base.file) |f| { + f.close(); + base.file = null; + }, } } diff --git a/test/stage2/compare_output.zig b/test/stage2/compare_output.zig index 83dfddb3e8..4208cc3911 100644 --- a/test/stage2/compare_output.zig +++ b/test/stage2/compare_output.zig @@ -12,6 +12,11 @@ const linux_riscv64 = std.zig.CrossTarget{ .os_tag = .linux, }; +const wasi = std.zig.CrossTarget{ + .cpu_arch = .wasm32, + .os_tag = .wasi, +}; + pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("hello world with updates", linux_x64); @@ -539,4 +544,35 @@ pub fn addCases(ctx: *TestContext) !void { "", ); } + + { + var case = ctx.exe("wasm returns", wasi); + + case.addCompareOutput( + \\export fn _start() u32 { + \\ return 42; + \\} + , + "42\n", + ); + + case.addCompareOutput( + \\export fn _start() i64 { + \\ return 42; + \\} + , + "42\n", + ); + + case.addCompareOutput( + \\export fn _start() f32 { + \\ return 42.0; + \\} + , + // This is what you get when you take the bits of the IEE-754 + // representation of 42.0 and reinterpret them as an unsigned + // integer. Guess that's a bug in wasmtime. + "1109917696\n", + ); + } }