mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-08 06:44:27 +00:00
fix start code for WebAssembly
This commit is contained in:
parent
d606811f55
commit
acf2e8fe64
3 changed files with 24 additions and 19 deletions
|
|
@ -65,9 +65,16 @@ comptime {
|
||||||
}
|
}
|
||||||
} else if (native_os == .uefi) {
|
} else if (native_os == .uefi) {
|
||||||
if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" });
|
if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" });
|
||||||
} else if (native_arch.isWasm()) {
|
} else if (native_os == .wasi) {
|
||||||
const wasm_start_sym = if (builtin.wasi_exec_model == .reactor) "_initialize" else "_start";
|
const wasm_start_sym = switch (builtin.wasi_exec_model) {
|
||||||
if (!@hasDecl(root, wasm_start_sym)) @export(wasm_start, .{ .name = wasm_start_sym });
|
.reactor => "_initialize",
|
||||||
|
.command => "_start",
|
||||||
|
};
|
||||||
|
if (!@hasDecl(root, wasm_start_sym)) {
|
||||||
|
@export(wasi_start, .{ .name = wasm_start_sym });
|
||||||
|
}
|
||||||
|
} else if (native_arch.isWasm() and native_os == .freestanding) {
|
||||||
|
if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name });
|
||||||
} else if (native_os != .other and native_os != .freestanding) {
|
} else if (native_os != .other and native_os != .freestanding) {
|
||||||
if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name });
|
if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name });
|
||||||
}
|
}
|
||||||
|
|
@ -136,21 +143,19 @@ fn _DllMainCRTStartup(
|
||||||
return std.os.windows.TRUE;
|
return std.os.windows.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wasm_start() callconv(.C) void {
|
fn wasm_freestanding_start() callconv(.C) void {
|
||||||
// The entrypoint is marked inline because for some reason LLVM in release mode fails to inline it,
|
// This is marked inline because for some reason LLVM in
|
||||||
// and we want fewer call frames in stack traces.
|
// release mode fails to inline it, and we want fewer call frames in stack traces.
|
||||||
switch (native_os) {
|
|
||||||
.freestanding => {
|
|
||||||
_ = @call(.{ .modifier = .always_inline }, callMain, .{});
|
_ = @call(.{ .modifier = .always_inline }, callMain, .{});
|
||||||
},
|
}
|
||||||
.wasi => {
|
|
||||||
|
fn wasi_start() callconv(.C) void {
|
||||||
|
// The function call is marked inline because for some reason LLVM in
|
||||||
|
// release mode fails to inline it, and we want fewer call frames in stack traces.
|
||||||
switch (builtin.wasi_exec_model) {
|
switch (builtin.wasi_exec_model) {
|
||||||
.reactor => _ = @call(.{ .modifier = .always_inline }, callMain, .{}),
|
.reactor => _ = @call(.{ .modifier = .always_inline }, callMain, .{}),
|
||||||
.command => std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{})),
|
.command => std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{})),
|
||||||
}
|
}
|
||||||
},
|
|
||||||
else => @compileError("unsupported OS"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.C) usize {
|
fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.C) usize {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||||
{
|
{
|
||||||
var case = ctx.exe("hello world with updates", target);
|
var case = ctx.exe("hello world with updates", target);
|
||||||
case.addError("", &[_][]const u8{
|
case.addError("", &[_][]const u8{
|
||||||
":86:9: error: struct 'test_case.test_case' has no member named 'main'",
|
":93:9: error: struct 'test_case.test_case' has no member named 'main'",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Incorrect return type
|
// Incorrect return type
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||||
var case = ctx.exe("hello world with updates", linux_x64);
|
var case = ctx.exe("hello world with updates", linux_x64);
|
||||||
|
|
||||||
case.addError("", &[_][]const u8{
|
case.addError("", &[_][]const u8{
|
||||||
":86:9: error: struct 'test_case.test_case' has no member named 'main'",
|
":93:9: error: struct 'test_case.test_case' has no member named 'main'",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Incorrect return type
|
// Incorrect return type
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue