| ... | ... | @@ -1,13 +1,16 @@ |
| 1 | 1 | // This file is included in the compilation unit when exporting an executable. |
| 2 | 2 | |
| 3 | | const root = @import("root"); |
| 4 | | const std = @import("std.zig"); |
| 5 | 3 | const builtin = @import("builtin"); |
| 4 | const native_arch = builtin.cpu.arch; |
| 5 | const native_os = builtin.os.tag; |
| 6 | const is_wasm = native_arch.isWasm(); |
| 7 | |
| 8 | const std = @import("std.zig"); |
| 6 | 9 | const assert = std.debug.assert; |
| 7 | 10 | const uefi = std.os.uefi; |
| 8 | 11 | const elf = std.elf; |
| 9 | | const native_arch = builtin.cpu.arch; |
| 10 | | const native_os = builtin.os.tag; |
| 12 | |
| 13 | const root = @import("root"); |
| 11 | 14 | |
| 12 | 15 | const start_sym_name = if (native_arch.isMIPS()) "__start" else "_start"; |
| 13 | 16 | |
| ... | ... | @@ -22,7 +25,7 @@ comptime { |
| 22 | 25 | } |
| 23 | 26 | } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) { |
| 24 | 27 | if (builtin.link_libc and @hasDecl(root, "main")) { |
| 25 | | if (native_arch.isWasm()) { |
| 28 | if (is_wasm) { |
| 26 | 29 | @export(&mainWithoutEnv, .{ .name = "__main_argc_argv" }); |
| 27 | 30 | } else if (!@typeInfo(@TypeOf(root.main)).@"fn".calling_convention.eql(.c)) { |
| 28 | 31 | @export(&main, .{ .name = "main" }); |
| ... | ... | @@ -57,7 +60,7 @@ comptime { |
| 57 | 60 | // case it's not required to provide an entrypoint such as main. |
| 58 | 61 | @export(&startWasi, .{ .name = wasm_start_sym }); |
| 59 | 62 | } |
| 60 | | } else if (native_arch.isWasm() and native_os == .freestanding) { |
| 63 | } else if (is_wasm and native_os == .freestanding) { |
| 61 | 64 | // Only call main when defined. For WebAssembly it's allowed to pass `-fno-entry` in which |
| 62 | 65 | // case it's not required to provide an entrypoint such as main. |
| 63 | 66 | if (!@hasDecl(root, start_sym_name) and @hasDecl(root, "main")) @export(&wasm_freestanding_start, .{ .name = start_sym_name }); |
| ... | ... | @@ -660,7 +663,7 @@ fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.c) c_int { |
| 660 | 663 | /// General error message for a malformed return type |
| 661 | 664 | const bad_main_ret = "expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'"; |
| 662 | 665 | |
| 663 | | const use_debug_allocator = !native_arch.isWasm() and switch (builtin.mode) { |
| 666 | const use_debug_allocator = !is_wasm and switch (builtin.mode) { |
| 664 | 667 | .Debug => true, |
| 665 | 668 | .ReleaseSafe => !builtin.link_libc, // Not ideal, but the best we have for now. |
| 666 | 669 | .ReleaseFast, .ReleaseSmall => !builtin.link_libc and builtin.single_threaded, // Also not ideal. |
| ... | ... | @@ -675,12 +678,12 @@ inline fn callMain(args: std.process.Args.Vector, environ: std.process.Environ.B |
| 675 | 678 | .environ = .{ .block = environ }, |
| 676 | 679 | })); |
| 677 | 680 | |
| 678 | | const gpa = if (native_arch.isWasm()) |
| 679 | | std.heap.wasm_allocator |
| 680 | | else if (use_debug_allocator) |
| 681 | const gpa = if (use_debug_allocator) |
| 681 | 682 | debug_allocator.allocator() |
| 682 | 683 | else if (builtin.link_libc) |
| 683 | 684 | std.heap.c_allocator |
| 685 | else if (is_wasm) |
| 686 | std.heap.wasm_allocator |
| 684 | 687 | else if (!builtin.single_threaded) |
| 685 | 688 | std.heap.smp_allocator |
| 686 | 689 | else |
| ... | ... | @@ -690,7 +693,9 @@ inline fn callMain(args: std.process.Args.Vector, environ: std.process.Environ.B |
| 690 | 693 | _ = debug_allocator.deinit(); // Leaks do not affect return code. |
| 691 | 694 | }; |
| 692 | 695 | |
| 693 | | var arena_allocator = std.heap.ArenaAllocator.init(std.heap.page_allocator); |
| 696 | const arena_backing_allocator = if (is_wasm) gpa else std.heap.page_allocator; |
| 697 | |
| 698 | var arena_allocator = std.heap.ArenaAllocator.init(arena_backing_allocator); |
| 694 | 699 | defer arena_allocator.deinit(); |
| 695 | 700 | |
| 696 | 701 | var threaded: std.Io.Threaded = .init(gpa, .{ |