2020-02-17 16:44:06 +01:00
|
|
|
/*
|
2021-06-22 14:37:33 +02:00
|
|
|
Copyright 2020-2021 The Matrix.org Foundation C.I.C.
|
2020-02-17 16:44:06 +01:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-12-14 15:32:27 +01:00
|
|
|
import childProcess from 'child_process';
|
|
|
|
import fsProm from 'fs/promises';
|
2020-02-17 16:44:06 +01:00
|
|
|
|
2021-12-14 15:32:27 +01:00
|
|
|
import HakEnv from '../../scripts/hak/hakEnv';
|
|
|
|
import { DependencyInfo } from '../../scripts/hak/dep';
|
|
|
|
|
|
|
|
export default async function(hakEnv: HakEnv, moduleInfo: DependencyInfo): Promise<void> {
|
2020-02-17 16:44:06 +01:00
|
|
|
// of course tcl doesn't have a --version
|
2022-04-19 17:59:37 +02:00
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
|
|
const proc = childProcess.spawn('tclsh', [], {
|
|
|
|
stdio: ['pipe', 'ignore', 'ignore'],
|
2020-02-17 16:44:06 +01:00
|
|
|
});
|
2022-04-19 17:59:37 +02:00
|
|
|
proc.on('exit', (code) => {
|
|
|
|
if (code !== 0) {
|
|
|
|
reject("Can't find tclsh - have you installed TCL?");
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
proc.stdin.end();
|
|
|
|
});
|
2020-02-17 16:44:06 +01:00
|
|
|
|
2021-06-22 14:37:33 +02:00
|
|
|
const tools = [
|
|
|
|
['rustc', '--version'],
|
|
|
|
['python', '--version'], // node-gyp uses python for reasons beyond comprehension
|
|
|
|
];
|
2020-02-17 16:44:06 +01:00
|
|
|
if (hakEnv.isWin()) {
|
2020-02-17 16:59:55 +01:00
|
|
|
tools.push(['perl', '--version']); // for openssl configure
|
2022-04-25 19:58:34 +02:00
|
|
|
tools.push(['nasm', '-v']); // for openssl building
|
2020-02-18 12:05:32 +01:00
|
|
|
tools.push(['patch', '--version']); // to patch sqlcipher Makefile.msc
|
2020-02-17 16:59:55 +01:00
|
|
|
tools.push(['nmake', '/?']);
|
2020-02-17 16:44:06 +01:00
|
|
|
} else {
|
2020-02-17 16:59:55 +01:00
|
|
|
tools.push(['make', '--version']);
|
2020-02-17 16:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const tool of tools) {
|
2021-12-14 15:32:27 +01:00
|
|
|
await new Promise<void>((resolve, reject) => {
|
2020-02-17 16:59:55 +01:00
|
|
|
const proc = childProcess.spawn(tool[0], tool.slice(1), {
|
2020-02-17 16:44:06 +01:00
|
|
|
stdio: ['ignore'],
|
|
|
|
});
|
|
|
|
proc.on('exit', (code) => {
|
|
|
|
if (code !== 0) {
|
|
|
|
reject("Can't find " + tool);
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2021-06-22 14:37:33 +02:00
|
|
|
|
2021-07-06 20:01:34 +02:00
|
|
|
// Ensure Rust target exists (nb. we avoid depending on rustup)
|
2021-06-22 14:37:33 +02:00
|
|
|
await new Promise((resolve, reject) => {
|
2021-07-06 20:06:58 +02:00
|
|
|
const rustc = childProcess.execFile('rustc', [
|
|
|
|
'--target', hakEnv.getTargetId(), '-o', 'tmp', '-',
|
|
|
|
], (err, out) => {
|
2021-06-22 14:37:33 +02:00
|
|
|
if (err) {
|
2021-07-06 20:06:58 +02:00
|
|
|
reject(
|
|
|
|
"rustc can't build for target " + hakEnv.getTargetId() +
|
2021-07-07 11:58:54 +02:00
|
|
|
": ensure target is installed via `rustup target add " + hakEnv.getTargetId() + "` " +
|
|
|
|
"or your package manager if not using `rustup`",
|
2021-07-06 20:06:58 +02:00
|
|
|
);
|
2021-06-22 14:37:33 +02:00
|
|
|
}
|
2021-07-06 20:01:34 +02:00
|
|
|
fsProm.unlink('tmp').then(resolve);
|
2021-06-22 14:37:33 +02:00
|
|
|
});
|
2021-07-06 20:01:34 +02:00
|
|
|
rustc.stdin.write('fn main() {}');
|
|
|
|
rustc.stdin.end();
|
2021-06-22 14:37:33 +02:00
|
|
|
});
|
2021-12-14 15:32:27 +01:00
|
|
|
}
|