Use a task runner for more granularity/parallelism

This commit is contained in:
Nick Gerleman
2022-12-24 05:57:36 -08:00
parent fb68379dee
commit d8296b9190
6 changed files with 855 additions and 35 deletions

View File

@@ -29,7 +29,7 @@ module.exports = {
}, },
overrides: [ overrides: [
{ {
files: ["jest.*", "tests/**"], files: ["jest.*", "just.config.js", "tests/**"],
env: { env: {
node: true, node: true,
}, },
@@ -38,6 +38,7 @@ module.exports = {
getMeasureCounterMax: "writable", getMeasureCounterMax: "writable",
getMeasureCounterMin: "writable", getMeasureCounterMin: "writable",
Yoga: "writable", Yoga: "writable",
YGBENCHMARK: "writable",
}, },
}, },
], ],

View File

@@ -18,3 +18,7 @@ module.exports = async () => {
global.Yoga = await require("./dist/entrypoint/asmjs-async").loadYoga(); global.Yoga = await require("./dist/entrypoint/asmjs-async").loadYoga();
} }
}; };
Object.defineProperty(global, "YGBENCHMARK", {
get: () => global.test,
});

114
javascript/just.config.js Normal file
View File

@@ -0,0 +1,114 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
const {
copyTask,
jestTask,
parallel,
series,
spawn,
task,
} = require("just-scripts");
const glob = require("glob");
const which = require("which");
const cmake = which.sync("cmake");
const encmake = which.sync("emcmake");
const ninja = which.sync("ninja", { nothrow: true });
const node = which.sync("node");
const npx = which.sync("npx");
task(
"copy-dts",
copyTask({
paths: ["./src_js/**/*.d.ts"],
dest: "./dist",
})
);
task("babel", () =>
spawn(npx, ["babel", "src_js", "--source-maps", "--out-dir", "dist"])
);
task("cmake-generate", () =>
spawn(encmake, [
"cmake",
"-S",
".",
"-B",
"build",
...(ninja ? ["-G", "Ninja"] : []),
])
);
task("prepare", parallel("copy-dts", "babel", "cmake-generate"));
function cmakeBuildTask(targets) {
return () =>
spawn(
cmake,
["--build", "build", ...(targets ? ["--target", ...targets] : [])],
{ stdio: "inherit" }
);
}
task("cmake-build:all", cmakeBuildTask());
task("cmake-build:async", cmakeBuildTask(["asmjs-async", "wasm-async"]));
task("cmake-build:sync", cmakeBuildTask(["asmjs-sync", "wasm-sync"]));
task("cmake-build:asmjs-async", cmakeBuildTask(["asmjs-async"]));
task("cmake-build:asmjs-sync", cmakeBuildTask(["asmjs-sync"]));
task("cmake-build:wasm-async", cmakeBuildTask(["wasm-async"]));
task("cmake-build:wasm-sync", cmakeBuildTask(["wasm-sync"]));
task("jest:asmjs-async", jestTask({ env: { WASM: false, SYNC: false } }));
task("jest:asmjs-sync", jestTask({ env: { WASM: false, SYNC: true } }));
task("jest:wasm-async", jestTask({ env: { WASM: true, SYNC: false } }));
task("jest:wasm-sync", jestTask({ env: { WASM: true, SYNC: true } }));
task(
"test:asmjs-async",
series("prepare", "cmake-build:asmjs-async", "jest:asmjs-async")
);
task(
"test:asmjs-sync",
series("prepare", "cmake-build:asmjs-sync", "jest:asmjs-sync")
);
task(
"test:wasm-async",
series("prepare", "cmake-build:wasm-async", "jest:wasm-async")
);
task(
"test:wasm-sync",
series("prepare", "cmake-build:wasm-sync", "jest:wasm-sync")
);
task("run-bench", () =>
spawn(
node,
["./tests/run-bench.js", ...glob.sync("./tests/Benchmarks/**/*.js")],
{ stdio: "inherit" }
)
);
task("build", series("prepare", "cmake-build:all"));
task(
"test",
series(
"prepare",
series(
series("cmake-build:asmjs-async", "jest:asmjs-async"),
series("cmake-build:asmjs-sync", "jest:asmjs-sync"),
series("cmake-build:wasm-async", "jest:wasm-async"),
series("cmake-build:wasm-sync", "jest:wasm-sync")
)
)
);
task("benchmark", series("prepare", "cmake-build:sync", "run-bench"));

View File

@@ -26,19 +26,15 @@
"src_js/**" "src_js/**"
], ],
"scripts": { "scripts": {
"benchmark": "yarn build && node tests/run-bench $(find tests/benchmarks -name '*.js')", "benchmark": "just benchmark",
"build": "yarn build:js && yarn build:native", "build": "just build",
"build:configure": "which ninja && emcmake cmake -S . -B build -G Ninja || emcmake cmake -S . -B build",
"build:copy-dts": "cd src_js && find . -name '*.d.ts' | cpio -pdm ../dist",
"build:js": "babel src_js --source-maps --out-dir dist && yarn build:copy-dts",
"build:native": "yarn build:configure && cmake --build build",
"lint": "eslint .", "lint": "eslint .",
"lint:fix": "yarn lint --fix", "lint:fix": "yarn lint --fix",
"test": "yarn test:asmjs-async && yarn test:asmjs-sync && yarn test:wasm-async && yarn test:wasm-sync", "test": "just test",
"test:asmjs-async": "yarn build --target asmjs-async && WASM=0 SYNC=0 jest", "test:asmjs-async": "just test:asmjs-async",
"test:asmjs-sync": "yarn build --target asmjs-sync && WASM=0 SYNC=1 jest", "test:asmjs-sync": "just test:asmjs-sync",
"test:wasm-async": "yarn build --target wasm-async && WASM=1 SYNC=0 jest", "test:wasm-async": "just test:wasm-async",
"test:wasm-sync": "yarn build --target wasm-sync && WASM=1 SYNC=1 jest" "test:wasm-sync": "just test:wasm-sync"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.20.7", "@babel/cli": "^7.20.7",
@@ -49,7 +45,10 @@
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^27.1.7", "eslint-plugin-jest": "^27.1.7",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
"glob": "^8.0.3",
"jest": "^29.3.1", "jest": "^29.3.1",
"prettier": "^2.4.1" "just-scripts": "^2.1.0",
"prettier": "^2.4.1",
"which": "^3.0.0"
} }
} }

View File

@@ -6,7 +6,6 @@
*/ */
const ITERATIONS = 2000; const ITERATIONS = 2000;
const YGBENCHMARK = global.YGBENCHMARK ?? global.test;
YGBENCHMARK("Stack with flex", () => { YGBENCHMARK("Stack with flex", () => {
const root = Yoga.Node.create(); const root = Yoga.Node.create();

File diff suppressed because it is too large Load Diff