diff --git a/.github/workflows/linux-daily-check.yml b/.github/workflows/linux-daily-check.yml index 610b789..bf98806 100644 --- a/.github/workflows/linux-daily-check.yml +++ b/.github/workflows/linux-daily-check.yml @@ -12,15 +12,27 @@ jobs: strategy: matrix: arch: [amd64, arm64] + include: + - arch: arm64 + is_arm: true steps: + # - if: ${{ matrix.is_arm }} + # uses: pguyot/arm-runner-action@v2 + # with: + # base_image: raspios_lite_arm64:latest + - name: Update system - run: sudo apt-get update && sudo apt-get --yes upgrade + run: sudo apt-get update - name: Install Nodejs 21 repo run: sudo apt-get install --yes ca-certificates curl gnupg && curl -sL https://deb.nodesource.com/setup_21.x | sudo bash - && sudo apt-get update - name: Install building tools - run: sudo apt-get install --yes git python3 python3-pip gcc g++ make ninja-build nodejs sudo + run: sudo apt-get install --yes git python3 python3-pip gcc g++ make build-essential binutils libz-dev linux-libc-dev nodejs sudo + + - if: ${{ matrix.is_arm }} + name: Install cross platform building tools + run: sudo apt-get install --yes crossbuild-essential-arm64 linux-libc-dev-arm64-cross binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - name: Clone the repo run: git clone https://github.com/devraymondsh/libnode-distributable @@ -30,8 +42,6 @@ jobs: - name: Run the script env: - CC: "sccache gcc" - CXX: "sccache g++" ARCH: ${{ matrix.arch }} SCCACHE_GHA_ENABLED: "true" run: cd libnode-distributable && node index.js diff --git a/.github/workflows/macos-daily-check.yml b/.github/workflows/macos-daily-check.yml index 4519324..2b40b09 100644 --- a/.github/workflows/macos-daily-check.yml +++ b/.github/workflows/macos-daily-check.yml @@ -8,11 +8,19 @@ on: jobs: update: name: Macos daily check - runs-on: macos-latest strategy: matrix: arch: [amd64, arm64] + include: + - arch: arm64 + os: macos-14 + is_arm: true + - arch: amd64 + os: macos-13 + runs-on: ${{ matrix.os }} steps: + - run: sysctl -a | grep machdep.cpu + - name: Install building tools run: brew install node python ninja nasm git @@ -24,8 +32,6 @@ jobs: - name: Run the script env: - CC: "sccache cc" - CXX: "sccache c++" ARCH: ${{ matrix.arch }} SCCACHE_GHA_ENABLED: "true" run: cd libnode-distributable && node index.js diff --git a/index.js b/index.js index 858192f..8be84b1 100644 --- a/index.js +++ b/index.js @@ -6,9 +6,11 @@ import { spawn } from "node:child_process"; let CC = process.env.CC; let CXX = process.env.CXX; let ARCH = process.env.ARCH; +let CROSS_COMPILE = process.env.CROSS_COMPILE; if (!CC) CC = "gcc"; if (!CXX) CXX = "g++"; if (!ARCH) ARCH = "amd64"; +if (!CROSS_COMPILE) CROSS_COMPILE = false; const coreCount = cpus().length; const threadCount = coreCount * 2; @@ -55,11 +57,16 @@ const isANewerVersion = (oldVer, newVer) => { return false; }; -const spawnAsync = (program, args, cwd) => +const spawnAsync = (program, args, cwd, env) => new Promise((resolve, reject) => { - console.log([program, ...args].join(" ")); + console.log("ENV: ", process.env); + console.log("Running:", [program, ...args].join(" ")); - const child = spawn(program, args, cwd ? { cwd } : {}); + const child = spawn( + program, + args, + cwd ? { cwd, env: { ...process.env, ...env } } : {} + ); child.stdout.on("data", (chunk) => console.log(chunk.toString())); child.stderr.on("data", (chunk) => console.error(chunk.toString())); @@ -85,17 +92,62 @@ if (!syncFs.existsSync("node")) { `v${latestNodeVersion}`, "--depth=1", ], - undefined + undefined, + {} ); } +let extraArgs = []; if (process.platform == "win32") { - await spawnAsync("vcbuild.bat", [arch, "dll"], "node"); + await spawnAsync("vcbuild.bat", [arch, "dll"], "node", {}); } else { + let env; + if (process.platform === "linux") { + if (arch === "arm64") { + process.env.CC_host = "sccache gcc"; + process.env.CXX_host = "sccache g++"; + process.env.CC = "sccache aarch64-linux-gnu-gcc"; + process.env.CXX = "sccache aarch64-linux-gnu-g++"; + + env = { + CC_host: "sccache gcc", + CXX_host: "sccache g++", + CC: "sccache aarch64-linux-gnu-gcc", + CXX: "sccache aarch64-linux-gnu-g++", + }; + } else { + process.env.CC = "sccache gcc"; + process.env.CXX = "sccache g++"; + + env = { + CC: "sccache gcc", + CXX: "sccache g++", + }; + } + } else { + process.env.CC = "sccache cc"; + process.env.CXX = "sccache c++"; + + env = { + CC: "sccache cc", + CXX: "sccache c++", + }; + } + + if (arch === "arm64") { + if (os === "linux") extraArgs.push("--cross-compiling"); + + extraArgs.push("--with-arm-float-abi"); + extraArgs.push("hard"); + extraArgs.push("--with-arm-fpu"); + extraArgs.push("neon"); + } + await spawnAsync( "./configure", - ["--ninja", "--shared", "--dest-cpu", arch, "--dest-os", os], - "node" + ["--shared", "--dest-cpu", arch, "--dest-os", os, ...extraArgs], + "node", + env ); - await spawnAsync("make", [`-j${threadCount}`], "node"); + await spawnAsync("make", [`-j${threadCount}`], "node", env); }