Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions scripts/ensure-native-deps.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ function printFailures(failures) {
}
}

function tryRebuild() {
const { execSync } = require("node:child_process");
const packages = nativePackages.join(" ");
try {
log(`native binaries incompatible, rebuilding from source: npm rebuild ${packages} --build-from-source`);
execSync(`npm rebuild ${packages} --build-from-source`, {
cwd: rootDir,
stdio: "inherit",
});
return true;
} catch (err) {
warn(`rebuild failed: ${err && err.message ? err.message : String(err)}`);
return false;
}
}

function main() {
const initialFailures = verifyNativePackages();
if (initialFailures.length === 0) {
Expand All @@ -49,9 +65,22 @@ function main() {
}

printFailures(initialFailures);
warn("native dependency verification failed");
warn("install build tools first, then run: npm rebuild better-sqlite3 sqlite-vec --build-from-source");
warn("Debian/Ubuntu example: apt-get update && apt-get install -y python3 make gcc g++");

if (!tryRebuild()) {
warn("install build tools first, then reinstall the plugin");
warn("Debian/Ubuntu: apt-get update && apt-get install -y python3 make gcc g++");
process.exit(1);
}

const afterFailures = verifyNativePackages();
if (afterFailures.length === 0) {
log("native dependencies rebuilt and verified");
return;
}

printFailures(afterFailures);
warn("rebuild succeeded but native packages still fail to load");
warn("Debian/Ubuntu: apt-get update && apt-get install -y python3 make gcc g++");
process.exit(1);
}

Expand Down
Loading