-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathmain.zig
76 lines (63 loc) · 2.27 KB
/
main.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const std = @import("std");
const builtin = @import("builtin");
const bun = @import("root").bun;
const Output = bun.Output;
const Environment = bun.Environment;
pub const panic = bun.crash_handler.panic;
pub const std_options = std.Options{
.enable_segfault_handler = false,
};
pub const io_mode = .blocking;
comptime {
bun.assert(builtin.target.cpu.arch.endian() == .little);
}
extern fn bun_warn_avx_missing(url: [*:0]const u8) void;
pub extern "C" var _environ: ?*anyopaque;
pub extern "C" var environ: ?*anyopaque;
pub fn main() void {
bun.crash_handler.init();
// This should appear before we make any calls at all to libuv.
// So it's safest to put it very early in the main function.
if (Environment.isWindows) {
_ = bun.windows.libuv.uv_replace_allocator(
@ptrCast(&bun.Mimalloc.mi_malloc),
@ptrCast(&bun.Mimalloc.mi_realloc),
@ptrCast(&bun.Mimalloc.mi_calloc),
@ptrCast(&bun.Mimalloc.mi_free),
);
environ = @ptrCast(std.os.environ.ptr);
_environ = @ptrCast(std.os.environ.ptr);
}
bun.start_time = std.time.nanoTimestamp();
bun.initArgv(bun.default_allocator) catch |err| {
Output.panic("Failed to initialize argv: {s}\n", .{@errorName(err)});
};
Output.Source.Stdio.init();
defer Output.flush();
if (Environment.isX64 and Environment.enableSIMD and Environment.isPosix) {
bun_warn_avx_missing(@import("./cli/upgrade_command.zig").Version.Bun__githubBaselineURL.ptr);
}
bun.CLI.Cli.start(bun.default_allocator);
bun.Global.exit(0);
}
pub const overrides = struct {
pub const mem = struct {
extern "C" fn wcslen(s: [*:0]const u16) usize;
pub fn indexOfSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]const T) usize {
if (comptime T == u16 and sentinel == 0 and Environment.isWindows) {
return wcslen(p);
}
if (comptime T == u8 and sentinel == 0) {
return bun.C.strlen(p);
}
var i: usize = 0;
while (p[i] != sentinel) {
i += 1;
}
return i;
}
};
};
pub export fn Bun__panic(msg: [*]const u8, len: usize) noreturn {
Output.panic("{s}", .{msg[0..len]});
}