diff --git a/.circleci/config.yml b/.circleci/config.yml index 03fd51b..7a7fddf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -208,15 +208,18 @@ jobs: - checkout - npm_install: os: << parameters.os >> + - when: + condition: + equal: [ "alpine", << parameters.os >> ] + steps: + - prepare: + os: << parameters.os >> + - run: + command: npm run build:test - test ## WORKFLOWS ## -matrix: &matrix - matrix: - parameters: - os: [ debian, linux, macos, "win/default" ] - workflows: postject: jobs: @@ -225,8 +228,16 @@ workflows: parameters: os: [ linux, macos, "win/default" ] - build: - <<: *matrix + matrix: + parameters: + os: [ linux, macos, "win/default" ] - test: - <<: *matrix + matrix: + parameters: + os: [ macos, "win/default" ] requires: [ build-<< matrix.os >> ] - + - test: + matrix: + parameters: + os: [ alpine, debian ] + requires: [ build-linux ] diff --git a/package.json b/package.json index 741a602..af55cf2 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "main": "dist/api.js", "scripts": { "build": "zx ./scripts/build.mjs", + "build:test": "zx ./scripts/build.mjs --target=test", "clean": "rimraf ./build", "format": "npm run format:cpp && npm run format:js", "format:cpp": "clang-format -style=chromium -i postject-api.h src/**.cpp test/**.c test/**.cpp", diff --git a/scripts/build.mjs b/scripts/build.mjs index 3adbf99..e88b7ee 100755 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -1,5 +1,6 @@ #!/usr/bin/env zx +let target = argv.target; let jobs = argv.jobs; if (!jobs) { @@ -15,34 +16,56 @@ if (!jobs) { } } -try { - await which("emcmake"); -} catch { - console.log("ERROR: Couldn't find `emcmake`, is emsdk installed?"); - process.exit(1); -} +async function build() { + try { + await which("emcmake"); + } catch { + console.log("ERROR: Couldn't find `emcmake`, is emsdk installed?"); + process.exit(1); + } + + // Create build folder if needed + if (!(await fs.exists("./build"))) { + await $`mkdir -p build`; + } + + cd("build"); -// Create build folder if needed -if (!(await fs.exists("./build"))) { - await $`mkdir build`; + // Build with emsdk + await $`emcmake cmake -G Ninja ..`; + await $`cmake --build . -j ${jobs}`; + + // Bundle api.js and copy artifacts to dist + await fs.copy("../src/api.js", "api.js"); + await $`esbuild api.js --bundle --platform=node --outfile=../dist/api.js`; + await fs.copy("../src/cli.js", "../dist/cli.js"); + await fs.copy("../postject-api.h", "../dist/postject-api.h"); + + cd(".."); } -cd("build"); -// Build with emsdk -await $`emcmake cmake -G Ninja ..`; -await $`cmake --build . -j ${jobs}`; +async function test() { + // Create build folder if needed + if (!(await fs.exists("./build/test"))) { + await $`mkdir -p build/test`; + } -// Bundle api.js and copy artifacts to dist -await fs.copy("../src/api.js", "api.js"); -await $`esbuild api.js --bundle --platform=node --outfile=../dist/api.js`; -await fs.copy("../src/cli.js", "../dist/cli.js"); -await fs.copy("../postject-api.h", "../dist/postject-api.h"); + cd("build/test"); -// Build tests -if (!(await fs.exists("./test"))) { - await $`mkdir test`; + await $`cmake ../../test`; + await $`cmake --build .`; + + cd("../.."); } -cd("test"); -await $`cmake ../../test`; -await $`cmake --build .`; +switch (target) { + case "build": + await build(); + break; + case "test": + await test(); + break; + default: + await build(); + await test(); +}