64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
import fs from 'fs';
|
|
|
|
function getHostAbi () {
|
|
return 'm' + process.versions.modules;
|
|
}
|
|
|
|
export function abiToNodeRange (abi) {
|
|
if (/^m?14/.test(abi)) return '0.12';
|
|
if (/^m?46/.test(abi)) return '4';
|
|
if (/^m?47/.test(abi)) return '5';
|
|
if (/^m?48/.test(abi)) return '6';
|
|
return abi;
|
|
}
|
|
|
|
export function toFancyPlatform (platform) {
|
|
if (platform === 'darwin') return 'osx';
|
|
if (platform === 'win32') return 'win';
|
|
return platform;
|
|
}
|
|
|
|
function getHostPlatform () {
|
|
const { platform } = process;
|
|
return toFancyPlatform(platform);
|
|
}
|
|
|
|
export function toFancyArch (arch) {
|
|
if (arch === 'ia32') return 'x86';
|
|
if (arch === 'x86_64') return 'x64';
|
|
return arch;
|
|
}
|
|
|
|
function getArmHostArch () {
|
|
const cpu = fs.readFileSync('/proc/cpuinfo', 'utf8');
|
|
if (cpu.indexOf('vfpv3') >= 0) return 'armv7';
|
|
let name = cpu.split('model name')[1];
|
|
if (name) name = name.split(':')[1];
|
|
if (name) name = name.split('\n')[0];
|
|
if (name && name.indexOf('ARMv7') >= 0) return 'armv7';
|
|
return 'armv6';
|
|
}
|
|
|
|
function getHostArch () {
|
|
const { arch } = process;
|
|
if (arch === 'arm') return getArmHostArch();
|
|
return toFancyArch(arch);
|
|
}
|
|
|
|
function getTargetArchs () {
|
|
const arch = getHostArch();
|
|
if (arch === 'x64') return [ 'x64', 'x86' ];
|
|
// TODO find a way to crosscompile for armv6 on armv7
|
|
return [ arch ];
|
|
}
|
|
|
|
function getKnownArchs () {
|
|
return [ 'x64', 'x86', 'armv6', 'armv7' ];
|
|
}
|
|
|
|
export const hostAbi = getHostAbi();
|
|
export const hostPlatform = getHostPlatform();
|
|
export const hostArch = getHostArch();
|
|
export const targetArchs = getTargetArchs();
|
|
export const knownArchs = getKnownArchs();
|