perf(tui): shrink standalone builds and target native bindings (#6432)
* perf(tui): shrink standalone builds without dropping features * fix(tui): resolve macOS diagram fonts through CoreText * fix(webui): preserve history pagination at the page boundary * docs(tui): streamline release preflight guidance --------- Co-authored-by: Xubin Ren <52506698+Re-bin@users.noreply.github.com>
This commit is contained in:
1 parent
0e0df327c8
commit
ae7fed88e2
21 files changed
+424
-82
No files matched your search
+28
-23
@@ -1,36 +1,24 @@
|
||||
import { chmod, mkdir } from "node:fs/promises"
|
||||
import { basename, join } from "node:path"
|
||||
import { targetBindings } from "./target-bindings"
|
||||
import { nativePackages, targetPlan } from "./targets"
|
||||
|
||||
const target = process.argv[2] || `${process.platform}-${process.arch}`
|
||||
const [platform, arch] = target.split("-")
|
||||
const supportedTargets = new Set([
|
||||
"darwin-arm64",
|
||||
"darwin-x64",
|
||||
"linux-arm64",
|
||||
"linux-x64",
|
||||
"win32-x64",
|
||||
])
|
||||
|
||||
if (!platform || !arch || !supportedTargets.has(target)) {
|
||||
throw new Error(`unsupported target: ${target}`)
|
||||
}
|
||||
|
||||
const bunPlatform = platform === "win32" ? "windows" : platform
|
||||
// Wheels cannot select a CPU feature level: avoid the default AVX2-only x64 runtime.
|
||||
const cpuVariant = arch === "x64" ? "-baseline" : ""
|
||||
const extension = platform === "win32" ? ".exe" : ""
|
||||
const outputDir = join(import.meta.dir, "..", "dist")
|
||||
const output = join(outputDir, `nanobot-tui-${platform}-${arch}${extension}`)
|
||||
const plan = targetPlan(process.argv[2] || `${process.platform}-${process.arch}`)
|
||||
const root = join(import.meta.dir, "..")
|
||||
const outputDir = join(root, "dist")
|
||||
const output = join(outputDir, plan.executable)
|
||||
|
||||
await mkdir(outputDir, { recursive: true })
|
||||
const result = await Bun.build({
|
||||
entrypoints: [join(import.meta.dir, "..", "src", "index.ts")],
|
||||
define: { NANOBOT_COMPILED: "true" },
|
||||
bytecode: true,
|
||||
// Standalone files retain JS; the optional precompiled cache costs another ~22 MiB on x64.
|
||||
bytecode: false,
|
||||
format: "esm",
|
||||
plugins: [await targetBindings(plan, root)],
|
||||
minify: { whitespace: true, syntax: true, identifiers: true, keepNames: true },
|
||||
compile: {
|
||||
target: `bun-${bunPlatform}-${arch}${cpuVariant}` as Bun.Build.CompileTarget,
|
||||
target: plan.bunTarget,
|
||||
outfile: output,
|
||||
},
|
||||
})
|
||||
@@ -39,9 +27,26 @@ if (!result.success) {
|
||||
for (const log of result.logs) console.error(log)
|
||||
process.exit(1)
|
||||
}
|
||||
if (platform !== "win32") await chmod(output, 0o755)
|
||||
if (plan.platform !== "win32") await chmod(output, 0o755)
|
||||
const bytes = Bun.file(output).size
|
||||
const digest = new Bun.CryptoHasher("sha256")
|
||||
.update(await Bun.file(output).arrayBuffer())
|
||||
.digest("hex")
|
||||
await Bun.write(`${output}.sha256`, `${digest} ${basename(output)}\n`)
|
||||
await Bun.write(`${output}.size.json`, JSON.stringify({
|
||||
phase: "compiled", // macOS signing happens later; the archive manifest owns final hashes.
|
||||
target: plan.id,
|
||||
bunTarget: plan.bunTarget,
|
||||
bunVersion: Bun.version,
|
||||
bunRevision: Bun.revision,
|
||||
bytecode: false,
|
||||
executable: basename(output),
|
||||
bytes,
|
||||
sha256: digest,
|
||||
budgetBytes: plan.executableBudgetBytes,
|
||||
expectedNativePackages: nativePackages(plan),
|
||||
}, null, 2) + "\n")
|
||||
if (bytes > plan.executableBudgetBytes) {
|
||||
throw new Error(`${plan.id} executable is ${bytes} bytes; budget is ${plan.executableBudgetBytes}`)
|
||||
}
|
||||
console.log(output)
|
||||
Reference in new issue
Block a user