feat: add loong64 support
This commit is contained in:
parent
a024a39fb5
commit
236d01423e
@ -7,15 +7,16 @@ import { getNodeVersion } from './index';
|
||||
import { version } from '../package.json';
|
||||
import { fetchExtractApply, prepBuildPath } from './build';
|
||||
|
||||
async function applyPatchesOnVersion(nodeRange: string, quietExtraction = false) {
|
||||
async function applyPatchesOnVersion(nodeRange: string, quietExtraction = false, arch = 'x64') {
|
||||
await prepBuildPath();
|
||||
await fetchExtractApply(getNodeVersion(nodeRange), quietExtraction);
|
||||
await fetchExtractApply(getNodeVersion(nodeRange), quietExtraction, arch);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const { argv } = yargs
|
||||
.option('node-range', { alias: 'n', default: 'latest', type: 'string' })
|
||||
.option('quiet-extraction', { alias: 'q', type: 'boolean' })
|
||||
.option('arch', { alias: 'a', default: 'x64', type: 'string' })
|
||||
.version(version)
|
||||
.alias('v', 'version')
|
||||
.help()
|
||||
@ -24,9 +25,10 @@ async function main() {
|
||||
const {
|
||||
'node-range': nodeRange,
|
||||
'quiet-extraction': quietExtraction,
|
||||
arch,
|
||||
} = argv;
|
||||
|
||||
await applyPatchesOnVersion(nodeRange, quietExtraction);
|
||||
await applyPatchesOnVersion(nodeRange, quietExtraction, arch);
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
|
||||
23
lib/build.ts
23
lib/build.ts
@ -158,7 +158,7 @@ async function tarExtract(nodeVersion: string, suppressTarOutput: boolean) {
|
||||
await pipe(source, gunzip, extract);
|
||||
}
|
||||
|
||||
async function applyPatches(nodeVersion: string) {
|
||||
async function applyPatches(nodeVersion: string, targetArch: string) {
|
||||
log.info('Applying patches');
|
||||
|
||||
const storedPatches = patchesJson[nodeVersion as keyof typeof patchesJson] as
|
||||
@ -177,15 +177,29 @@ async function applyPatches(nodeVersion: string) {
|
||||
const args = ['-p1', '-i', patchPath];
|
||||
await spawn('patch', args, { cwd: nodePath, stdio: 'inherit' });
|
||||
}
|
||||
|
||||
// Apply architecture-specific patches
|
||||
const major = getMajor(nodeVersion);
|
||||
if (targetArch === 'loong64' && major >= 24) {
|
||||
const archPatch = 'nodejs.v24.loongarch64.patch';
|
||||
const archPatchPath = path.join(patchesPath, archPatch);
|
||||
const fs = await import('fs');
|
||||
if (fs.existsSync(archPatchPath)) {
|
||||
log.info(`Applying architecture-specific patch: ${archPatch}`);
|
||||
const args = ['-p1', '-i', archPatchPath];
|
||||
await spawn('patch', args, { cwd: nodePath, stdio: 'inherit' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchExtractApply(
|
||||
nodeVersion: string,
|
||||
quietExtraction: boolean
|
||||
quietExtraction: boolean,
|
||||
targetArch: string = 'x64'
|
||||
) {
|
||||
await tarFetch(nodeVersion);
|
||||
await tarExtract(nodeVersion, quietExtraction);
|
||||
await applyPatches(nodeVersion);
|
||||
await applyPatches(nodeVersion, targetArch);
|
||||
}
|
||||
|
||||
async function compileOnWindows(
|
||||
@ -258,6 +272,7 @@ async function compileOnUnix(
|
||||
arm64: 'arm64',
|
||||
ppc64: 'ppc64',
|
||||
s390x: 's390x',
|
||||
loong64: 'loong64',
|
||||
}[targetArch];
|
||||
|
||||
if (cpu) {
|
||||
@ -354,7 +369,7 @@ export default async function build(
|
||||
local: string
|
||||
) {
|
||||
await prepBuildPath();
|
||||
await fetchExtractApply(nodeVersion, false);
|
||||
await fetchExtractApply(nodeVersion, false, targetArch);
|
||||
|
||||
const output = await compile(nodeVersion, targetArch, targetPlatform);
|
||||
const outputHash = await hash(output);
|
||||
|
||||
125226
patches/nodejs.v24.loongarch64.patch
Normal file
125226
patches/nodejs.v24.loongarch64.patch
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user