fix: restore locked build tools for the ARMv6 migration bridge

This commit is contained in:
whyour
2026-10-23 12:16:28 +08:00
parent 1623e89a71
commit dce4f60c47
2 changed files with 27 additions and 45 deletions
+12 -28
View File
@@ -7,6 +7,7 @@ const { createRequire } = require('node:module');
const { execFile } = require('node:child_process');
const { promisify } = require('node:util');
const bundle = require('../cli/src/internal/maintenance/platformBundle.cjs');
const { repairDependencies } = require('../cli/src/internal/maintenance/upgradePrestart.cjs');
function assertArmv6Addon(attributes) {
if (
@@ -21,17 +22,13 @@ async function rebuildMigrationSqlite(root, {
target,
run = promisify(execFile),
runtime = process,
repair = repairDependencies,
} = {}) {
target ||= await bundle.runtimeTarget();
if (target.arch !== 'armv6' || target.libc !== 'musl') return false;
const pkg = JSON.parse(await fs.readFile(path.join(root, 'package.json')));
if (!pkg.qinglongMigrationBridge || !pkg.dependencies?.sqlite3)
throw new Error('Only a legacy migration bridge may rebuild SQLite');
const r = createRequire(path.join(root, 'package.json'));
const sqlite = path.dirname(r.resolve('sqlite3/package.json'));
const fromSqlite = createRequire(path.join(sqlite, 'package.json'));
const preGyp = fromSqlite.resolve('@mapbox/node-pre-gyp/bin/node-pre-gyp');
const nodeGyp = fromSqlite.resolve('node-gyp/bin/node-gyp.js');
const prefix = path.resolve(path.dirname(runtime.execPath), '..');
const header = await fs.readFile(path.join(prefix, 'include/node/node_version.h'), 'utf8');
const version = ['MAJOR', 'MINOR', 'PATCH'].map((part) =>
@@ -40,33 +37,20 @@ async function rebuildMigrationSqlite(root, {
if (version !== runtime.versions.node)
throw new Error('Migration SQLite requires headers matching the existing Node');
const lock = await fs.readFile(path.join(root, 'pnpm-lock.yaml'));
await run(runtime.execPath, [
'--jitless', preGyp, 'rebuild', '--build-from-source',
'--napi_build_version=6', `--nodedir=${prefix}`, '--jobs=1',
'--arm_version=6', '--arm_fpu=vfp', '--arm_float_abi=hard',
], {
cwd: sqlite,
timeout: 1800000,
maxBuffer: 4 * 1024 * 1024,
env: {
PATH: runtime.env.PATH,
NODE_PATH: '',
NODE_OPTIONS: '--jitless --max-old-space-size=256',
npm_config_node_gyp: nodeGyp,
npm_config_build_from_source: 'true',
npm_config_force_process_config: 'true',
npm_config_nodedir: prefix,
npm_config_jobs: '1',
MAKEFLAGS: '-j1',
CFLAGS: '-march=armv6 -mfpu=vfp -mfloat-abi=hard',
CXXFLAGS: '-march=armv6 -mfpu=vfp -mfloat-abi=hard',
},
});
const addon = path.join(sqlite, 'lib/binding/napi-v6-linux-arm/node_sqlite3.node');
// The Node 18 legacy builder skipped node-gyp 12's optional dependency.
// The existing frozen repair installs that locked graph using the current
// Node, then forces an ARMv6 source build with local headers and one job.
await repair(root, { target, env: runtime.env });
// Repair replaces node_modules, so resolve its new layout after completion.
const rebuilt = path.dirname(createRequire(path.join(root, 'package.json')).resolve('sqlite3/package.json'));
const addon = path.join(rebuilt, 'lib/binding/napi-v6-linux-arm/node_sqlite3.node');
const { stdout } = await run('readelf', ['-A', addon], { timeout: 30000 });
assertArmv6Addon(stdout);
if (!lock.equals(await fs.readFile(path.join(root, 'pnpm-lock.yaml'))))
throw new Error('Migration SQLite rebuild changed the frozen lockfile');
// node-pre-gyp copied the addon to lib/binding; compiler objects are not
// needed on the small target device or in the transition download.
await fs.rm(path.join(rebuilt, 'build'), { recursive: true, force: true });
console.log('Legacy bridge SQLite rebuilt and verified for ARMv6 hard-float');
return true;
}