Path: blob/main/lang/bun/files/patch-scripts_build_config.ts
49052 views
-- Add BUN_HOST_OS environment variable support to override host OS detection.1-- When building with a Linux bootstrap bun binary on FreeBSD, bun reports2-- host.os = "linux" which triggers cross-compilation mode (dep_cargo_cross,3-- rustup target add, cross-compile clang flags). Setting BUN_HOST_OS=freebsd4-- makes the build treat FreeBSD as native, using dep_cargo (no rustup needed)5-- and native LLVM/clang without cross-compile sysroot flags.6--7-- also inline WEBKIT_VERSION to break a circular ES module dependency:8-- deps/index.ts → deps/webkit.ts → source.ts → config.ts → deps/webkit.ts9-- Bun 1.3.14 enforces strict TDZ for circular ES modules; inlining breaks cycle.10--11-- Add support for explicit CPU target via BUN_CPU environment variable or12-- the 'cpu' config field. This allows respecting FreeBSD's CPUTYPE.131415--- scripts/build/config.ts.orig 2026-05-12 22:12:49 UTC16+++ scripts/build/config.ts17@@ -11,7 +11,9 @@ import { NODEJS_ABI_VERSION, NODEJS_VERSION } from "./18import { homedir, arch as hostArch, platform as hostPlatform } from "node:os";19import { isAbsolute, join, relative, resolve, sep } from "node:path";20import { NODEJS_ABI_VERSION, NODEJS_VERSION } from "./deps/nodejs-headers.ts";21-import { WEBKIT_VERSION } from "./deps/webkit.ts";22+// WEBKIT_VERSION inlined here (was imported from deps/webkit.ts) to break circular module dep:23+// deps/index.ts → deps/webkit.ts → source.ts → config.ts → deps/webkit.ts24+const WEBKIT_VERSION = "bdf6aab38a9c6f99df3fd1486406ab6b74180fbb";25import { assert, BuildError } from "./error.ts";26import { clangTargetArch } from "./tools.ts";27import { cyan, dim, green } from "./tty.ts";28@@ -116,6 +118,8 @@ export interface Config {29logs: boolean;30/** x64-only: target nehalem (no AVX) instead of haswell. */31baseline: boolean;32+ /** Explicit CPU target (e.g. "native", "skylake"). Overrides baseline/default. */33+ cpu: string | undefined;34canary: boolean;35/** MinSizeRel → optimize for size. */36smol: boolean;37@@ -253,6 +257,7 @@ export interface PartialConfig {38assertions?: boolean;39logs?: boolean;40baseline?: boolean;41+ cpu?: string;42canary?: boolean;43staticSqlite?: boolean;44staticLibatomic?: boolean;45@@ -341,9 +346,12 @@ export interface Toolchain {4647/**48* Host platform detection. Only used for picking defaults.49+ * The BUN_HOST_OS environment variable can override the detected OS.50+ * This is needed when using a Linux bun bootstrap binary on FreeBSD.51*/52export function detectHost(): Host {53- const plat = hostPlatform();54+ const envOs = process.env.BUN_HOST_OS;55+ const plat = envOs !== undefined ? envOs : hostPlatform();56const os: OS =57plat === "linux"58? "linux"59@@ -605,6 +613,7 @@ export function resolveConfig(partial: PartialConfig,60const logs = partial.logs ?? debug;6162const baseline = partial.baseline ?? false;63+ const cpu = partial.cpu ?? process.env.BUN_CPU;64const canary = partial.canary ?? true;65const canaryRevision = canary ? "1" : "0";6667@@ -779,6 +788,7 @@ export function resolveConfig(partial: PartialConfig,68assertions,69logs,70baseline,71+ cpu,72canary,73smol,74staticSqlite,757677