Skip to content

Commit

Permalink
Warn at start when using AVX build of Bun without AVX support (#6242)
Browse files Browse the repository at this point in the history
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
  • Loading branch information
Jarred-Sumner and Jarred-Sumner committed Oct 3, 2023
1 parent 63a0079 commit 89bb526
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
29 changes: 28 additions & 1 deletion src/bun.js/bindings/c-bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
// 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>
#include <sys/fcntl.h>
#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);
Expand Down Expand Up @@ -48,4 +75,4 @@ extern "C" ssize_t bun_sysconf__SC_CLK_TCK()
#else
return 0;
#endif
}
}
7 changes: 7 additions & 0 deletions src/cli/upgrade_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
}
Expand Down
17 changes: 6 additions & 11 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");

0 comments on commit 89bb526

Please sign in to comment.