diff options
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/Build/Step/Compile.zig | 3 | ||||
| -rw-r--r-- | lib/std/start.zig | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 9ede31c917..18977ac472 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -64,6 +64,8 @@ initial_memory: ?u64 = null, max_memory: ?u64 = null, shared_memory: bool = false, global_base: ?u64 = null, +/// For WebAssembly only. Tells the linker to not output an entry point. +no_entry: ?bool = null, c_std: std.Build.CStd, /// Set via options; intended to be read-only after that. zig_lib_dir: ?LazyPath, @@ -1851,6 +1853,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { if (self.global_base) |global_base| { try zig_args.append(b.fmt("--global-base={d}", .{global_base})); } + try addFlag(&zig_args, "entry", self.no_entry); if (self.code_model != .default) { try zig_args.append("-mcmodel"); diff --git a/lib/std/start.zig b/lib/std/start.zig index 7ed59a4675..29fdb3b031 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -82,11 +82,15 @@ comptime { .reactor => "_initialize", .command => "_start", }; - if (!@hasDecl(root, wasm_start_sym)) { + if (!@hasDecl(root, wasm_start_sym) and @hasDecl(root, "main")) { + // Only call main when defined. For WebAssembly it's allowed to pass `-fno-entry` in which + // case it's not required to provide an entrypoint such as main. @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 }); + // Only call main when defined. For WebAssembly it's allowed to pass `-fno-entry` in which + // case it's not required to provide an entrypoint such as main. + if (!@hasDecl(root, start_sym_name) and @hasDecl(root, "main")) @export(wasm_freestanding_start, .{ .name = start_sym_name }); } else if (native_os != .other and native_os != .freestanding) { if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name }); } |
