Working seshat building on Windows

This commit is contained in:
David Baker
2020-02-15 16:52:41 +00:00
parent 337ccf02aa
commit a0d9359ef0
9 changed files with 219 additions and 29 deletions

View File

@@ -17,18 +17,158 @@ limitations under the License.
const path = require('path');
const child_process = require('child_process');
const mkdirp = require('mkdirp');
const fsExtra = require('fs-extra');
module.exports = async function(hakEnv, moduleInfo) {
if (hakEnv.isWin()) await buildOpenSsl(hakEnv, moduleInfo);
await buildSqlCipher(hakEnv, moduleInfo);
if (hakEnv.isWin()) {
await buildOpenSslWin(hakEnv, moduleInfo);
await buildSqlCipherWin(hakEnv, moduleInfo);
} else {
await buildSqlCipherUnix(hakEnv, moduleInfo);
}
await buildMatrixSeshat(hakEnv, moduleInfo);
}
async function buildOpenSsl(hakEnv, moduleInfo) {
const openSslDir = path.join(moduleInfo.moduleHakDir, 'openssl-1.1.1d');
async function buildOpenSslWin(hakEnv, moduleInfo) {
const openSslDir = path.join(moduleInfo.moduleDotHakDir, 'openssl-1.1.1d');
const openSslArch = hakEnv.arch === 'x64' ? 'VC-WIN64A' : 'VC-WIN32';
console.log("Building openssl in " + openSslDir);
await new Promise((resolve, reject) => {
const proc = child_process.spawn(
'perl',
[
'Configure',
'--prefix=' + moduleInfo.depPrefix,
// sqlcipher only uses about a tiny part of openssl. We link statically
// so will only pull in the symbols we use, but we may as well turn off
// as much as possible to save on build time.
'no-afalgeng',
'no-capieng',
'no-cms',
'no-ct',
'no-deprecated',
'no-dgram',
'no-dso',
'no-ec',
'no-ec2m',
'no-gost',
'no-nextprotoneg',
'no-ocsp',
'no-sock',
'no-srp',
'no-srtp',
'no-tests',
'no-ssl',
'no-tls',
'no-dtls',
'no-shared',
'no-aria',
'no-camellia',
'no-cast',
'no-chacha',
'no-cmac',
'no-des',
'no-dh',
'no-dsa',
'no-ecdh',
'no-ecdsa',
'no-idea',
'no-md4',
'no-mdc2',
'no-ocb',
'no-poly1305',
'no-rc2',
'no-rc4',
'no-rmd160',
'no-scrypt',
'no-seed',
'no-siphash',
'no-sm2',
'no-sm3',
'no-sm4',
'no-whirlpool',
openSslArch,
],
{
cwd: openSslDir,
stdio: 'inherit',
},
);
proc.on('exit', (code) => {
code ? reject(code) : resolve();
});
});
await new Promise((resolve, reject) => {
const proc = child_process.spawn(
'nmake',
['build_libs'],
{
cwd: openSslDir,
stdio: 'inherit',
},
);
proc.on('exit', (code) => {
code ? reject(code) : resolve();
});
});
await new Promise((resolve, reject) => {
const proc = child_process.spawn(
'nmake',
['install_dev'],
{
cwd: openSslDir,
stdio: 'inherit',
},
);
proc.on('exit', (code) => {
code ? reject(code) : resolve();
});
});
}
async function buildSqlCipher(hakEnv, moduleInfo) {
const sqlCipherDir = path.join(moduleInfo.moduleHakDir, 'sqlcipher-4.3.0');
async function buildSqlCipherWin(hakEnv, moduleInfo) {
const sqlCipherDir = path.join(moduleInfo.moduleDotHakDir, 'sqlcipher-4.3.0');
const buildDir = path.join(sqlCipherDir, 'bld');
await mkdirp(buildDir);
await new Promise((resolve, reject) => {
const proc = child_process.spawn(
'nmake',
['/f', path.join('..', 'Makefile.msc'), 'libsqlite3.lib', 'TOP=..'],
{
cwd: buildDir,
stdio: 'inherit',
env: Object.assign({}, process.env, {
CCOPTS: "-DSQLITE_HAS_CODEC -I" + path.join(moduleInfo.depPrefix, 'include'),
LTLIBPATHS: "/LIBPATH:" + path.join(moduleInfo.depPrefix, 'lib'),
LTLIBS: "libcrypto.lib",
}),
},
);
proc.on('exit', (code) => {
code ? reject(code) : resolve();
});
});
await fsExtra.copy(
path.join(buildDir, 'libsqlite3.lib'),
path.join(moduleInfo.depPrefix, 'lib', 'sqlcipher.lib'),
);
await fsExtra.copy(
path.join(buildDir, 'sqlite3.h'),
path.join(moduleInfo.depPrefix, 'include', 'sqlcipher.h'),
);
}
async function buildSqlCipherUnix(hakEnv, moduleInfo) {
const sqlCipherDir = path.join(moduleInfo.moduleDotHakDir, 'sqlcipher-4.3.0');
const args = [
'--prefix=' + moduleInfo.depPrefix + '',
@@ -88,17 +228,24 @@ async function buildSqlCipher(hakEnv, moduleInfo) {
}
async function buildMatrixSeshat(hakEnv, moduleInfo) {
await new Promise((resolve) => {
const env = Object.assign({
SQLCIPHER_STATIC: 1,
SQLCIPHER_LIB_DIR: path.join(moduleInfo.depPrefix, 'lib'),
SQLCIPHER_INCLUDE_DIR: path.join(moduleInfo.depPrefix, 'include'),
}, hakEnv.makeGypEnv());
if (hakEnv.isWin()) {
env.RUSTFLAGS = '-Ctarget-feature=+crt-static -Clink-args=libcrypto.lib';
}
console.log("Running neon with env", env);
await new Promise((resolve, reject) => {
const proc = child_process.spawn(
path.join(moduleInfo.nodeModuleBinDir, 'neon'),
path.join(moduleInfo.nodeModuleBinDir, 'neon' + (hakEnv.isWin() ? '.cmd' : '')),
['build', '--release'],
{
cwd: moduleInfo.moduleBuildDir,
env: Object.assign({
SQLCIPHER_STATIC: 1,
SQLCIPHER_LIB_DIR: path.join(moduleInfo.depPrefix, 'lib'),
SQLCIPHER_INCLUDE_DIR: path.join(moduleInfo.depPrefix, 'include'),
}, hakEnv.makeGypEnv()),
env,
stdio: 'inherit',
},
);

View File

@@ -15,7 +15,9 @@ limitations under the License.
*/
const path = require('path');
const child_process = require('child_process');
const fs = require('fs');
const fsProm = require('fs').promises;
const needle = require('needle');
const tar = require('tar');
@@ -29,7 +31,7 @@ module.exports = async function(hakEnv, moduleInfo) {
}
async function getSqlCipher(hakEnv, moduleInfo) {
const sqlCipherDir = path.join(moduleInfo.moduleHakDir, 'sqlcipher-4.3.0');
const sqlCipherDir = path.join(moduleInfo.moduleDotHakDir, 'sqlcipher-4.3.0');
let haveSqlcipher;
try {
@@ -41,7 +43,7 @@ async function getSqlCipher(hakEnv, moduleInfo) {
if (haveSqlcipher) return;
const sqlCipherTarball = path.join(moduleInfo.moduleHakDir, 'sqlcipher-4.3.0.tar.gz');
const sqlCipherTarball = path.join(moduleInfo.moduleDotHakDir, 'sqlcipher-4.3.0.tar.gz');
let haveSqlcipherTar;
try {
await fsProm.stat(sqlCipherTarball);
@@ -59,12 +61,36 @@ async function getSqlCipher(hakEnv, moduleInfo) {
await tar.x({
file: sqlCipherTarball,
cwd: moduleInfo.moduleHakDir,
cwd: moduleInfo.moduleDotHakDir,
});
if (hakEnv.isWin()) {
// On Windows, we need to patch the makefile because it forces TEMP_STORE to
// default to files (1) but the README specifically says you '*must*' set it
// set it to 2 (default to memory).
const patchFile = path.join(moduleInfo.moduleHakDir, 'sqlcipher-4.3.0-win.patch');
await new Promise((resolve, reject) => {
const readStream = fs.createReadStream(patchFile);
const proc = child_process.spawn(
'patch',
['-p1'],
{
cwd: sqlCipherDir,
stdio: ['pipe', 'inherit', 'inherit'],
},
);
proc.on('exit', (code) => {
code ? reject(code) : resolve();
});
readStream.pipe(proc.stdin);
});
}
}
async function getOpenSsl(hakEnv, moduleInfo) {
const openSslDir = path.join(moduleInfo.moduleHakDir, 'openssl-1.1.1d');
const openSslDir = path.join(moduleInfo.moduleDotHakDir, 'openssl-1.1.1d');
let haveOpenSsl;
try {
@@ -76,7 +102,7 @@ async function getOpenSsl(hakEnv, moduleInfo) {
if (haveOpenSsl) return;
const openSslTarball = path.join(moduleInfo.depDir, 'openssl-1.1.1d.tar.gz');
const openSslTarball = path.join(moduleInfo.moduleDotHakDir, 'openssl-1.1.1d.tar.gz');
let haveOpenSslTar;
try {
await fsProm.stat(openSslTarball);
@@ -91,8 +117,9 @@ async function getOpenSsl(hakEnv, moduleInfo) {
});
}
console.log("extracting " + openSslTarball + " in " + moduleInfo.moduleDotHakDir);
await tar.x({
file: openSslTarball,
cwd: moduleInfo.depDir,
cwd: moduleInfo.moduleDotHakDir,
});
}