Skip to content

Commit

Permalink
Add Macos support
Browse files Browse the repository at this point in the history
  • Loading branch information
devraymondsh committed Apr 7, 2024
1 parent f2d1671 commit a165961
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/linux-daily-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ jobs:
matrix:
arch: [amd64, arm64]
steps:
- if: matrix.arch == 'arm64'
uses: pguyot/arm-runner-action@v2

- name: Update system
run: sudo apt-get update && sudo apt-get --yes upgrade

Expand All @@ -35,6 +32,7 @@ jobs:
env:
CC: "sccache gcc"
CXX: "sccache g++"
ARCH: ${{ matrix.arch }}
SCCACHE_GHA_ENABLED: "true"
run: cd libnode-distributable && node index.js

Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/macos-daily-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Macos daily check

on:
schedule:
- cron: "0 8 * * *"
workflow_dispatch:

jobs:
update:
name: Macos daily check
runs-on: macos-latest
strategy:
matrix:
arch: [amd64, arm64]
steps:
- name: Install building tools
run: brew install node python ninja nasm git

- name: Clone the repo
run: git clone https://github.com/devraymondsh/libnode-distributable

- name: Run sccache-cache
uses: mozilla-actions/[email protected]

- 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

- name: Find the shared library
run: find libnode-distributable/node -name libnode.so\* -not -name '*.TOC' -not -name '*.toc' -exec ls {} \;
2 changes: 1 addition & 1 deletion .github/workflows/windows-daily-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
run: cd libnode-distributable ; node index.js

- name: Find the shared library
run: dir /s libnode-distributable\node\out\Release\libnode.dll
run: dir libnode-distributable\node\out\Release\libnode.dll
20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import syncFs from "node:fs";
import fs from "node:fs/promises";
import { spawn } from "node:child_process";

const coreCount = os.cpus().length;
const threadCount = coreCount * 2;

let CC = process.env.CC;
let CXX = process.env.CXX;
let ARCH = process.env.ARCH;
if (!CC) CC = "gcc";
if (!CXX) CXX = "g++";
if (!ARCH) ARCH = "amd64";

const coreCount = os.cpus().length;
const threadCount = coreCount * 2;
const arch = ARCH == "amd64" ? "x64" : "arm64";

const nodejsGithubRepo = "https://github.com/nodejs/node";
const removeTheVCharacter = (str) => str.replace("v", "");

Expand Down Expand Up @@ -76,10 +77,13 @@ if (!syncFs.existsSync("node")) {
);
}

if (process.platform == "linux") {
await spawnAsync("./configure", ["--ninja", "--shared"], "node");
await spawnAsync("make", [`-j${threadCount}`], "node");
} else if (process.platform == "win32") {
const arch = ARCH == "amd64" ? "x64" : "arm64";
if (process.platform == "win32") {
await spawnAsync("vcbuild.bat", [arch, "dll"], "node");
} else {
await spawnAsync(
"./configure",
["--ninja", "--shared", "--dest-cpu", arch],
"node"
);
await spawnAsync("make", [`-j${threadCount}`], "node");
}

0 comments on commit a165961

Please sign in to comment.