feat: add platform-specific native package installation for vectordb in build process
Some checks failed
Release Electron App / release-desktop (push) Failing after 8m7s
Some checks failed
Release Electron App / release-desktop (push) Failing after 8m7s
This commit is contained in:
@@ -69,6 +69,44 @@ const config: ForgeConfig = {
|
|||||||
env: { ...process.env, npm_config_nodedir: '' },
|
env: { ...process.env, npm_config_nodedir: '' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// vectordb uses platform-specific optional deps (@lancedb/vectordb-<platform>-<arch>-*).
|
||||||
|
// npm install on Linux only pulls the Linux variant. Force-install the target's.
|
||||||
|
const platformNativePackages: Record<string, Record<string, string>> = {
|
||||||
|
'win32-x64': {
|
||||||
|
'@lancedb/vectordb-win32-x64-msvc': '',
|
||||||
|
},
|
||||||
|
'linux-x64': {
|
||||||
|
'@lancedb/vectordb-linux-x64-gnu': '',
|
||||||
|
},
|
||||||
|
'darwin-x64': {
|
||||||
|
'@lancedb/vectordb-darwin-x64': '',
|
||||||
|
},
|
||||||
|
'darwin-arm64': {
|
||||||
|
'@lancedb/vectordb-darwin-arm64': '',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const targetKey = `${platform}-${arch}`;
|
||||||
|
const nativePkgs = platformNativePackages[targetKey];
|
||||||
|
if (nativePkgs) {
|
||||||
|
// Remove wrong-platform lancedb native packages
|
||||||
|
const nmPath = path.join(buildPath, 'node_modules', '@lancedb');
|
||||||
|
if (fs.existsSync(nmPath)) {
|
||||||
|
for (const entry of fs.readdirSync(nmPath)) {
|
||||||
|
if (entry.startsWith('vectordb-') && !Object.keys(nativePkgs).includes(`@lancedb/${entry}`)) {
|
||||||
|
fs.rmSync(path.join(nmPath, entry), { recursive: true, force: true });
|
||||||
|
console.log(`[forge] Removed non-target native package: @lancedb/${entry}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Install correct platform packages
|
||||||
|
const pkgsToInstall = Object.keys(nativePkgs).join(' ');
|
||||||
|
console.log(`[forge] Installing platform-specific packages for ${targetKey}: ${pkgsToInstall}`);
|
||||||
|
execSync(`npm install ${pkgsToInstall} --omit=dev --no-save`, {
|
||||||
|
cwd: buildPath,
|
||||||
|
stdio: 'inherit',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Remove cross-platform prebuilt binaries that don't match the target.
|
// Remove cross-platform prebuilt binaries that don't match the target.
|
||||||
// Packages like @github/copilot ship prebuilds for all platforms;
|
// Packages like @github/copilot ship prebuilds for all platforms;
|
||||||
// keeping foreign-arch .node files breaks rpmbuild's strip step.
|
// keeping foreign-arch .node files breaks rpmbuild's strip step.
|
||||||
|
|||||||
Reference in New Issue
Block a user