Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build & performance fixes #353

Merged
merged 14 commits into from
Jan 2, 2019
Prev Previous commit
Next Next commit
Reduced verbosity of build failures
  • Loading branch information
texodus committed Dec 30, 2018
commit f25bdb99351aeae6fb6a6afc084726b75baea61b
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"build,test": "npm run --silent build && npm run --silent test",
"build,test,bench": "npm run --silent build && npm run --silent test && npm run --silent bench",
"build,bench": "npm run --silent build && npm run --silent bench",
"build": "bash -c '[[ -z \"${PSP_DOCKER}\" ]] && npm run --silent _build || npm run --silent _emsdk -- npm run --silent _build'",
"build": "node scripts/build.js",
"build_cpp": "lerna run build:cpp ${PACKAGE:+--scope=@jpmorganchase/perspective} --stream",
"bench": "node scripts/bench.js",
"docs": "lerna run docs --silent --stream",
Expand All @@ -56,9 +56,7 @@
"fix:less": "prettier --tab-width 4 --write packages/**/src/less/*.less",
"fix:html": "html-beautify packages/**/src/html/*.html -r",
"fix:json": "prettier --tab-width 4 --write **/package.json",
"fix": "npm-run-all --silent fix:*",
"_build": "lerna run build ${PACKAGE:+--scope=@jpmorganchase/${PACKAGE}} --stream",
"_emsdk": "docker run --rm -it ${PSP_CPU_COUNT:+--cpus=\"${PSP_CPU_COUNT}.0\"} -v $(pwd):/src -e PACKAGE=${PACKAGE} perspective/emsdk"
"fix": "npm-run-all --silent fix:*"
},
"jest": {
"roots": [
Expand Down
2 changes: 0 additions & 2 deletions packages/perspective/.npmignore

This file was deleted.

5 changes: 1 addition & 4 deletions packages/perspective/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
"typings": "index.d.ts",
"scripts": {
"bench": "node ../../scripts/bench.js",
"prebuild": "mkdir -p build && CLICOLOR_FORCE=1 yarn compile",
"precompile": "mkdir -p obj && mkdir -p ../../obj/",
"compile": "cd ../../obj/ && emcmake cmake ../ && emmake make -j${PSP_CPU_COUNT-8}",
"prebuild": "mkdir -p build && mkdir -p obj",
"compile:cpp": "mkdir -p ../../cppbuild && cd ../../cppbuild && cmake ../ -DPSP_WASM_BUILD=0 -DPSP_CPP_BUILD=1 -DPSP_CPP_BUILD_TESTS=1 && make -j${PSP_CPU_COUNT-8}",
"cpp": "npm-run-all build:cpp test:cpp",
"postcompile": "node ../../scripts/compile",
"build": "npm-run-all build:webpack",
"build:cpp": "npm-run-all compile:cpp",
"build:webpack": "npm-run-all -p build:webpack:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/perspective/src/loader/file_worker_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exports.default = function loader(content) {
var inputPath = this.resourcePath;
if (!options.inline) {
inputPath = inputPath
.replace("build", "")
.replace(path.join("perspective", "build"), "perspective")
.replace(/\.js/, ".worker.js")
.replace(/(src\/js)/, "build");
}
Expand Down
72 changes: 61 additions & 11 deletions scripts/compile.js → scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/

const fs = require("fs");
const path = require("path");
const mkdirp = require("mkdirp");
const prettier = require("prettier");

const execSync = require("child_process").execSync;
const argv = require("minimist")(process.argv.slice(2));
const minimatch = require("minimatch");
const os = require("os");

const execute = cmd => execSync(cmd, {stdio: "inherit"});

/**
* ASMJS Output Options
Expand All @@ -21,7 +34,7 @@ const WEB_ASMJS_OPTIONS = {
const WEB_WASM_OPTIONS = {
inputFile: "psp.async.js",
inputWasmFile: "psp.async.wasm",
format: true,
format: false,
packageName: "perspective",
build: !!argv.wasm // flag as to whether to build
};
Expand All @@ -32,7 +45,7 @@ const WEB_WASM_OPTIONS = {
const NODE_OPTIONS = {
inputFile: "psp.sync.js",
inputWasmFile: "psp.sync.wasm",
format: true,
format: false,
packageName: "perspective",
build: !!argv.node // flag as to whether to build the node version
};
Expand All @@ -46,7 +59,8 @@ const AVAILABLE_RUNTIMES = [WEB_ASMJS_OPTIONS, WEB_WASM_OPTIONS, NODE_OPTIONS];
const RUNTIMES = AVAILABLE_RUNTIMES.filter(runtime => runtime.build).length ? AVAILABLE_RUNTIMES.filter(runtime => runtime.build) : AVAILABLE_RUNTIMES;

// Directory of Emscripten output
const BASE_DIRECTORY = path.join(__dirname, "..", "obj", "build");
const BASE_DIRECTORY = path.join(__dirname, "..", "obj");
const BUILD_DIRECTORY = path.join(BASE_DIRECTORY, "build");
const getOuputDir = packageName => path.join(__dirname, "..", "packages", packageName);

const templateSource = source => `
Expand All @@ -58,21 +72,21 @@ exports.load_perspective = function (Module) {
};`;

function compileRuntime({inputFile, inputWasmFile, format, packageName}) {
console.log("Building %s", inputFile);
console.log("-- Building %s", inputFile);

const OUTPUT_DIRECTORY = getOuputDir(packageName);

mkdirp.sync(path.join(OUTPUT_DIRECTORY, "obj"));
mkdirp.sync(path.join(OUTPUT_DIRECTORY, "build"));

if (inputWasmFile) {
console.log("Copying WASM file %s", inputWasmFile);
fs.copyFileSync(path.join(BASE_DIRECTORY, inputWasmFile), path.join(path.join(OUTPUT_DIRECTORY, "build"), inputWasmFile));
console.log("-- Copying WASM file %s", inputWasmFile);
fs.copyFileSync(path.join(BUILD_DIRECTORY, inputWasmFile), path.join(path.join(OUTPUT_DIRECTORY, "build"), inputWasmFile));
}

console.debug("Creating wrapped js runtime");
console.debug("-- Creating wrapped js runtime");
const runtimeText = String(
fs.readFileSync(path.join(BASE_DIRECTORY, inputFile), {
fs.readFileSync(path.join(BUILD_DIRECTORY, inputFile), {
encoding: "utf8"
})
);
Expand All @@ -88,7 +102,43 @@ function compileRuntime({inputFile, inputWasmFile, format, packageName}) {
}

fs.writeFileSync(path.join(path.join(OUTPUT_DIRECTORY, "obj"), inputFile), source);
console.log("Completed runtime %s", inputFile);
}

RUNTIMES.map(compileRuntime);
function emsdk() {
console.log("-- Creating emsdk docker image");
let cmd = "docker run --rm -it";
if (process.env.PSP_CPU_COUNT) {
cmd += ` --cpus="${parseInt(process.env.PSP_CPU_COUNT)}.0"`;
}
cmd += " -v $(pwd):/src -e PACKAGE=${PACKAGE} perspective/emsdk";
return cmd;
}

function compileCPP() {
let cmd = `emcmake cmake ../ && emmake make -j${process.env.PSP_CPU_COUNT || os.cpus().length}`;
if (process.env.PSP_DOCKER) {
cmd = `${emsdk()} bash -c 'cd obj && ${cmd}'`;
} else {
cmd = `cd ${BASE_DIRECTORY} && ${cmd}`;
}
execute(cmd);
}

function lerna() {
let cmd = `lerna run build --loglevel silent --stream `;
if (process.env.PACKAGE) {
cmd += `--scope=@jpmorganchase/${process.env.PACKAGE} `;
}
execute(cmd);
}

try {
if (!process.env.PACKAGE || minimatch("perspective", process.env.PACKAGE)) {
execute("mkdir -p obj");
compileCPP();
RUNTIMES.map(compileRuntime);
}
lerna();
} catch (e) {
process.exit(1);
}