diff --git a/.github/actions/build-vscode-extension/action.yml b/.github/actions/build-vscode-extension/action.yml index b465bf478..c09479697 100644 --- a/.github/actions/build-vscode-extension/action.yml +++ b/.github/actions/build-vscode-extension/action.yml @@ -111,8 +111,11 @@ runs: - name: Prepackage the extension shell: bash + env: + CONTINUE_VSCODE_TARGET: ${{ steps.set-target.outputs.target }} run: | cd extensions/vscode + export CONTINUE_VSCODE_TARGET="${{ steps.set-target.outputs.target }}" npm run prepackage -- --target ${{ steps.set-target.outputs.target }} - name: Re-install esbuild @@ -146,14 +149,20 @@ runs: - name: Package extension (build artifacts) shell: bash + env: + CONTINUE_VSCODE_TARGET: ${{ steps.set-target.outputs.target }} run: | cd extensions/vscode - npm run package + export CONTINUE_VSCODE_TARGET="${{ steps.set-target.outputs.target }}" + npm run package -- --target ${{ steps.set-target.outputs.target }} - name: Package extension (.vsix files) shell: bash + env: + CONTINUE_VSCODE_TARGET: ${{ steps.set-target.outputs.target }} run: | cd extensions/vscode + export CONTINUE_VSCODE_TARGET="${{ steps.set-target.outputs.target }}" if [ "${{ inputs.pre-release }}" = "true" ]; then npx vsce package --pre-release --no-dependencies --target ${{ steps.set-target.outputs.target }} else diff --git a/extensions/vscode/scripts/install-copy-nodemodule.js b/extensions/vscode/scripts/install-copy-nodemodule.js index 1ce65327a..9f32e91d8 100644 --- a/extensions/vscode/scripts/install-copy-nodemodule.js +++ b/extensions/vscode/scripts/install-copy-nodemodule.js @@ -7,6 +7,7 @@ const fs = require("fs"); const path = require("path"); const ncp = require("ncp").ncp; +const { rimrafSync } = require("rimraf"); const { execCmdSync } = require("../../../scripts/util"); @@ -64,7 +65,11 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { }); } finally { // Clean up the temporary directory - // rimrafSync(tempDir); + try { + rimrafSync(tempDir); + } catch (err) { + console.warn("[warn] Failed to remove temp directory", tempDir, err); + } // Return to the original directory process.chdir(currentDir); diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index 6085dc19c..dff54eab6 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -35,6 +35,15 @@ const args = process.argv; if (args[2] === "--target") { target = args[3]; } +if (!target) { + const envTarget = + process.env.CONTINUE_VSCODE_TARGET || + process.env.CONTINUE_BUILD_TARGET || + process.env.VSCODE_TARGET; + if (envTarget && typeof envTarget === "string") { + target = envTarget.trim(); + } +} let os; let arch; @@ -55,11 +64,6 @@ console.log("[info] Using target: ", target); const exe = os === "win32" ? ".exe" : ""; -const isArmTarget = - target === "darwin-arm64" || - target === "linux-arm64" || - target === "win32-arm64"; - const isWinTarget = target?.startsWith("win"); const isLinuxTarget = target?.startsWith("linux"); const isMacTarget = target?.startsWith("darwin"); @@ -288,25 +292,53 @@ void (async () => { ); }); - if (!skipInstalls) { - // GitHub Actions doesn't support ARM, so we need to download pre-saved binaries - // 02/07/25 - the above comment is out of date, there is now support for ARM runners on GitHub Actions - if (isArmTarget) { - // lancedb binary - const packageToInstall = { - "darwin-arm64": "@lancedb/vectordb-darwin-arm64", - "linux-arm64": "@lancedb/vectordb-linux-arm64-gnu", - "win32-arm64": "@lancedb/vectordb-win32-arm64-msvc", - }[target]; - console.log( - "[info] Downloading pre-built lancedb binary: " + packageToInstall, - ); + const lancedbPackagesByTarget = { + "darwin-arm64": "@lancedb/vectordb-darwin-arm64", + "darwin-x64": "@lancedb/vectordb-darwin-x64", + "linux-arm64": "@lancedb/vectordb-linux-arm64-gnu", + "linux-x64": "@lancedb/vectordb-linux-x64-gnu", + "win32-x64": "@lancedb/vectordb-win32-x64-msvc", + "win32-arm64": "@lancedb/vectordb-win32-arm64-msvc", + }; - await Promise.all([ - copySqlite(target), - installAndCopyNodeModules(packageToInstall, "@lancedb"), - ]); + const packageToInstall = lancedbPackagesByTarget[target]; + let packageDirName; + let expectedPackagePath; + if (packageToInstall) { + packageDirName = packageToInstall.split("/").pop(); + expectedPackagePath = path.join( + __dirname, + "..", + "node_modules", + "@lancedb", + packageDirName, + ); + + if (!fs.existsSync(expectedPackagePath)) { + console.log( + `[info] Installing LanceDB binary for ${target}: ${packageToInstall}`, + ); + await installAndCopyNodeModules(packageToInstall, "@lancedb"); + if (!fs.existsSync(expectedPackagePath)) { + throw new Error( + `Failed to install LanceDB binary at ${expectedPackagePath}`, + ); + } + } else { + console.log( + `[info] LanceDB binary already present for ${target} at ${expectedPackagePath}`, + ); } + } else { + console.warn( + `[warn] No LanceDB package mapping found for target ${target}`, + ); + } + + if (!skipInstalls) { + await copySqlite(target); + } else { + console.log("[info] Skipping sqlite download because SKIP_INSTALLS=true"); } console.log("[info] Copying sqlite node binding from core"); @@ -373,6 +405,34 @@ void (async () => { console.log(`[info] Copied ${NODE_MODULES_TO_COPY.join(", ")}`); + if (packageDirName && expectedPackagePath) { + const expectedOutPackagePath = path.join( + __dirname, + "..", + "out", + "node_modules", + "@lancedb", + packageDirName, + ); + const expectedOutIndexPath = path.join( + expectedOutPackagePath, + "index.node", + ); + if (!fs.existsSync(expectedOutIndexPath)) { + rimrafSync(expectedOutPackagePath); + fs.mkdirSync(expectedOutPackagePath, { recursive: true }); + fs.cpSync(expectedPackagePath, expectedOutPackagePath, { + recursive: true, + dereference: true, + }); + console.log(`[info] Copied LanceDB binary to ${expectedOutPackagePath}`); + } else { + console.log( + `[info] LanceDB binary already copied at ${expectedOutIndexPath}`, + ); + } + } + // Copy over any worker files fs.cpSync( "node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js",