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