From a8a8607456263d45c01bd3f217454491af09a9f4 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 21 Feb 2025 11:17:23 -0800 Subject: [PATCH] quick build --- binary/package.json | 1 + binary/quick-build.js | 86 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 binary/quick-build.js diff --git a/binary/package.json b/binary/package.json index 426127922..66da7f05c 100644 --- a/binary/package.json +++ b/binary/package.json @@ -23,6 +23,7 @@ "scripts": { "test": "jest", "build": "node build.js", + "quick-build": "node build.js --target darwin-arm64", "build:darwin-x64": "node build.js --os darwin-x64" }, "license": "Apache-2.0", diff --git a/binary/quick-build.js b/binary/quick-build.js new file mode 100644 index 000000000..a9a2e57d0 --- /dev/null +++ b/binary/quick-build.js @@ -0,0 +1,86 @@ +const esbuild = require("esbuild"); +const fs = require("fs"); +const path = require("path"); +const { + execCmdSync, + validateFilesPresent, + autodetectPlatformAndArch, +} = require("../scripts/util"); + +// Paths +const bin = path.join(__dirname, "bin"); +const esbuildOutputFile = "out/index.js"; +let targets = [ + "darwin-x64", + "darwin-arm64", + "linux-x64", + "linux-arm64", + "win32-x64", +]; + +for (let i = 2; i < process.argv.length; i++) { + if (process.argv[i - 1] === "--target") { + targets = [process.argv[i]]; + } +} + +// Cleanup +for (const target of targets) { + const exe = target.startsWith("win") ? ".exe" : ""; + const targetDir = path.join(bin, target); + fs.rmSync(path.join(targetDir, `continue-binary${exe}`), { force: true }); +} + +// Validate files to ensure prerequisites are available +const filesToValidate = [ + "src/index.ts", + "../core/node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js", + "../core/llm/tiktokenWorkerPool.mjs", + "../core/llm/llamaTokenizerWorkerPool.mjs", +]; +validateFilesPresent(filesToValidate); + +// Quick Build +(async () => { + console.log("[info] Building with esbuild..."); + await esbuild.build({ + entryPoints: ["src/index.ts"], + bundle: true, + outfile: esbuildOutputFile, + external: [ + "esbuild", + "./xhr-sync-worker.js", + "llamaTokenizerWorkerPool.mjs", + "tiktokenWorkerPool.mjs", + "vscode", + "./index.node", + ], + format: "cjs", + platform: "node", + sourcemap: true, + minify: true, + treeShaking: true, + loader: { ".node": "file" }, + inject: ["./importMetaUrl.js"], + define: { "import.meta.url": "importMetaUrl" }, + }); + + console.log("[info] Building binaries with pkg..."); + for (const target of targets) { + const targetDir = path.join(bin, target); + fs.mkdirSync(targetDir, { recursive: true }); + console.log(`[info] Building ${target}...`); + execCmdSync( + `npx pkg --no-bytecode --public-packages "*" --public pkgJson/${target} --out-path ${targetDir}`, + ); + } + + // Validate only continue-binary files + const pathsToVerify = targets.map((target) => { + const exe = target.startsWith("win") ? ".exe" : ""; + return path.join(bin, target, `continue-binary${exe}`); + }); + validateFilesPresent(pathsToVerify); + + console.log("[info] Quick build completed!"); +})();