From 72a23fc761dde713dfe2cbee48ed913f646d8347 Mon Sep 17 00:00:00 2001 From: weishu Date: Mon, 2 Mar 2026 13:11:06 +0800 Subject: [PATCH] build baseline variant for linux x64. --- cli/scripts/build-executable.ts | 45 +++++++++++++++++++++++++---- cli/scripts/prepare-npm-packages.ts | 2 +- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/cli/scripts/build-executable.ts b/cli/scripts/build-executable.ts index 7c3a9635..76a48502 100644 --- a/cli/scripts/build-executable.ts +++ b/cli/scripts/build-executable.ts @@ -5,12 +5,13 @@ import { fileURLToPath } from 'node:url'; const DEFAULT_TARGETS = [ 'bun-darwin-x64', 'bun-darwin-arm64', - 'bun-linux-x64', + 'bun-linux-x64-baseline', 'bun-linux-arm64', 'bun-windows-x64' ]; const SUPPORTED_PLATFORMS = new Set(['darwin', 'linux', 'windows']); const SUPPORTED_ARCHES = new Set(['x64', 'arm64']); +const SUPPORTED_LINUX_X64_VARIANTS = new Set(['baseline', 'modern']); function getArg(args: string[], name: string): string | undefined { const idx = args.indexOf(name); @@ -37,13 +38,22 @@ function resolveHostArch(): string { throw new Error(`Unsupported host arch: ${process.arch}`); } +function resolveDefaultTarget(): string { + const platform = resolveHostPlatform(); + const arch = resolveHostArch(); + if (platform === 'linux' && arch === 'x64') { + return 'bun-linux-x64-baseline'; + } + return `bun-${platform}-${arch}`; +} + function resolveTarget(target?: string): string { if (!target) { - return `bun-${resolveHostPlatform()}-${resolveHostArch()}`; + return resolveDefaultTarget(); } const parts = target.split('-'); - if (parts.length < 2 || parts.length > 3 || parts[0] !== 'bun') { + if (parts.length < 2 || parts.length > 4 || parts[0] !== 'bun') { throw new Error(`Invalid target: ${target}`); } @@ -57,12 +67,25 @@ function resolveTarget(target?: string): string { throw new Error(`Unsupported arch in target: ${target}`); } - return `bun-${platformPart}-${archPart}`; + const variantPart = parts[3]; + if (!variantPart) { + return `bun-${platformPart}-${archPart}`; + } + + if (platformPart !== 'linux' || archPart !== 'x64') { + throw new Error(`Unsupported variant in target: ${target}`); + } + + if (!SUPPORTED_LINUX_X64_VARIANTS.has(variantPart)) { + throw new Error(`Unsupported linux x64 variant in target: ${target}`); + } + + return `bun-${platformPart}-${archPart}-${variantPart}`; } function parseTarget(target: string): { platform: string; arch: string } { const parts = target.split('-'); - if (parts.length !== 3 || parts[0] !== 'bun') { + if ((parts.length !== 3 && parts.length !== 4) || parts[0] !== 'bun') { throw new Error(`Invalid target: ${target}`); } @@ -77,6 +100,16 @@ function parseTarget(target: string): { platform: string; arch: string } { throw new Error(`Unsupported arch in target: ${target}`); } + const variantPart = parts[3]; + if (variantPart) { + if (platformPart !== 'linux' || archPart !== 'x64') { + throw new Error(`Unsupported variant in target: ${target}`); + } + if (!SUPPORTED_LINUX_X64_VARIANTS.has(variantPart)) { + throw new Error(`Unsupported linux x64 variant in target: ${target}`); + } + } + return { platform: platformPart === 'windows' ? 'win32' : platformPart, arch: archPart @@ -215,7 +248,7 @@ async function main(): Promise { const includeWebAssets = args.includes('--with-web-assets'); if (args.includes('--target') && !target) { - console.error('Usage: bun run scripts/build-executable.ts [--target ] [--outdir dist-exe] [--name hapi] [--with-web-assets]'); + console.error('Usage: bun run scripts/build-executable.ts [--target ] [--outdir dist-exe] [--name hapi] [--with-web-assets]'); console.error(' or: bun run scripts/build-executable.ts --all [--outdir dist-exe] [--name hapi] [--with-web-assets]'); process.exit(1); } diff --git a/cli/scripts/prepare-npm-packages.ts b/cli/scripts/prepare-npm-packages.ts index 68262ffd..528a72c8 100644 --- a/cli/scripts/prepare-npm-packages.ts +++ b/cli/scripts/prepare-npm-packages.ts @@ -46,7 +46,7 @@ const PLATFORMS = [ name: 'linux-x64', os: 'linux', cpu: 'x64', - buildTarget: 'bun-linux-x64', + buildTarget: 'bun-linux-x64-baseline', binName: 'hapi' }, {