Use targets in hak environment for cross-compiling

This arranges the hak environment target info around target IDs that come from
the builder, which simplifies cross-compiling. The `target.js` module is a
generated copy of the builder's `target.ts`.
This commit is contained in:
J. Ryan Stinnett
2021-06-23 16:18:09 +01:00
parent a171fa417b
commit 997f2c21bf
3 changed files with 53 additions and 29 deletions
+25 -26
View File
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Matrix.org Foundation C.I.C.
Copyright 2020-2021 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ const path = require('path');
const os = require('os');
const nodePreGypVersioning = require('node-pre-gyp/lib/util/versioning');
const { TARGETS, getHost, isHostId } = require('./target');
function getElectronVersion(packageJson) {
// should we pick the version of an installed electron
@@ -42,30 +43,24 @@ function getRuntimeVersion(packageJson) {
}
}
function detectArch() {
if (process.platform === 'win32') {
// vcvarsall.bat (the script that sets up the environment for
// visual studio build tools) sets an env var to tell us what
// architecture the active build tools target, so we auto-detect
// this.
const targetArch = process.env.VSCMD_ARG_TGT_ARCH;
if (targetArch === 'x86') {
return 'ia32';
} else if (targetArch === 'x64') {
return 'x64';
}
}
return process.arch;
}
module.exports = class HakEnv {
constructor(prefix, packageJson) {
constructor(prefix, packageJson, targetId) {
let target;
if (targetId) {
target = TARGETS[targetId];
} else {
target = getHost();
}
if (!target) {
throw new Error(`Unknown target ${targetId}!`);
}
Object.assign(this, {
// what we're targeting
runtime: getRuntime(packageJson),
runtimeVersion: getRuntimeVersion(packageJson),
platform: process.platform,
arch: detectArch(),
target,
// paths
projectRoot: prefix,
@@ -82,25 +77,29 @@ module.exports = class HakEnv {
// {node_abi}-{platform}-{arch}
getNodeTriple() {
return this.getRuntimeAbi() + '-' + this.platform + '-' + this.arch;
return this.getRuntimeAbi() + '-' + this.target.platform + '-' + this.target.arch;
}
isWin() {
return this.platform === 'win32';
return this.target.platform === 'win32';
}
isMac() {
return this.platform === 'darwin';
return this.target.platform === 'darwin';
}
isLinux() {
return this.platform === 'linux';
return this.target.platform === 'linux';
}
isHost() {
return isHostId(this.target.id);
}
makeGypEnv() {
return Object.assign({}, process.env, {
npm_config_arch: this.arch,
npm_config_target_arch: this.arch,
npm_config_arch: this.target.arch,
npm_config_target_arch: this.target.arch,
npm_config_disturl: 'https://atom.io/download/electron',
npm_config_runtime: this.runtime,
npm_config_target: this.runtimeVersion,