diff options
author | 2023-10-02 17:59:38 -0700 | |
---|---|---|
committer | 2023-10-02 17:59:38 -0700 | |
commit | 89bb526e1467cc53109eee884c5b6b1cffc7b3fc (patch) | |
tree | 7a5101ce80a388d5290a19365ea73bf5fc85b3d6 | |
parent | 63a00791faac5636394f38f540f79d2e452b6b65 (diff) | |
download | bun-89bb526e1467cc53109eee884c5b6b1cffc7b3fc.tar.gz bun-89bb526e1467cc53109eee884c5b6b1cffc7b3fc.tar.zst bun-89bb526e1467cc53109eee884c5b6b1cffc7b3fc.zip |
Warn at start when using AVX build of Bun without AVX support (#6242)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
-rw-r--r-- | src/bun.js/bindings/c-bindings.cpp | 29 | ||||
-rw-r--r-- | src/cli/upgrade_command.zig | 7 | ||||
-rw-r--r-- | src/main.zig | 17 |
3 files changed, 41 insertions, 12 deletions
diff --git a/src/bun.js/bindings/c-bindings.cpp b/src/bun.js/bindings/c-bindings.cpp index ff4c8c4e7..f53ff52cc 100644 --- a/src/bun.js/bindings/c-bindings.cpp +++ b/src/bun.js/bindings/c-bindings.cpp @@ -1,4 +1,5 @@ // when we don't want to use @cInclude, we can just stick wrapper functions here +#include "root.h" #include <sys/resource.h> #include <cstdint> #include <unistd.h> @@ -6,6 +7,32 @@ #include <sys/stat.h> #include <sys/signal.h> +#if CPU(X86_64) +#include <cstring> +#include <cpuid.h> + +extern "C" void bun_warn_avx_missing(const char* url) +{ + __builtin_cpu_init(); + if (__builtin_cpu_supports("avx")) { + return; + } + + static constexpr const char* str = "warn: CPU lacks AVX support, strange crashes may occur. Reinstall Bun or use *-baseline build:\n "; + const size_t len = strlen(str); + + char buf[512]; + strcpy(buf, str); + strcpy(buf + len, url); + strcpy(buf + len + strlen(url), "\n\0"); + write(STDERR_FILENO, buf, strlen(buf)); +} +#else +extern "C" void bun_warn_avx_missing(char* url) +{ +} +#endif + extern "C" int32_t get_process_priority(uint32_t pid) { return getpriority(PRIO_PROCESS, pid); @@ -48,4 +75,4 @@ extern "C" ssize_t bun_sysconf__SC_CLK_TCK() #else return 0; #endif -}
\ No newline at end of file +} diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index 60ae953d3..d865d990d 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -83,7 +83,9 @@ pub const Version = struct { pub const triplet = platform_label ++ "-" ++ arch_label; const suffix = if (Environment.baseline) "-baseline" else ""; pub const folder_name = "bun-" ++ triplet ++ suffix; + pub const baseline_folder_name = "bun-" ++ triplet ++ "-baseline"; pub const zip_filename = folder_name ++ ".zip"; + pub const baseline_zip_filename = baseline_folder_name ++ ".zip"; pub const profile_folder_name = "bun-" ++ triplet ++ suffix ++ "-profile"; pub const profile_zip_filename = profile_folder_name ++ ".zip"; @@ -95,6 +97,11 @@ pub const Version = struct { zip_filename, }); + pub const Bun__githubBaselineURL: [:0]const u8 = std.fmt.comptimePrint("https://github.com/oven-sh/bun/release/bun-v{s}/{s}", .{ + Global.package_json_version, + baseline_zip_filename, + }); + pub fn isCurrent(this: Version) bool { return strings.eqlComptime(this.tag, current_version); } diff --git a/src/main.zig b/src/main.zig index 52cf33d53..ee8b0fb47 100644 --- a/src/main.zig +++ b/src/main.zig @@ -10,6 +10,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, addr } const CrashReporter = @import("./crash_reporter.zig"); +extern fn bun_warn_avx_missing(url: [*:0]const u8) void; pub fn main() void { const bun = @import("root").bun; @@ -24,25 +25,19 @@ pub fn main() void { bun.start_time = std.time.nanoTimestamp(); - // The memory allocator makes a massive difference. - // std.heap.raw_c_allocator and default_allocator perform similarly. - // std.heap.GeneralPurposeAllocator makes this about 3x _slower_ than esbuild. - // var root_alloc = @import("root").bun.ArenaAllocator.init(std.heap.raw_c_allocator); - // var root_alloc_ = &root_alloc.allocator; - var stdout = std.io.getStdOut(); - // var stdout = std.io.bufferedWriter(stdout_file.writer()); var stderr = std.io.getStdErr(); var output_source = Output.Source.init(stdout, stderr); Output.Source.set(&output_source); defer Output.flush(); + if (comptime Environment.isX64) { + if (comptime Environment.enableSIMD) { + bun_warn_avx_missing(@import("./cli/upgrade_command.zig").Version.Bun__githubBaselineURL.ptr); + } + } bun.CLI.Cli.start(bun.default_allocator, stdout, stderr, MainPanicHandler); } -test "panic" { - panic("woah", null); -} - pub const build_options = @import("build_options"); |