Update builder and migrate to ESM #3

Merged
Sirherobrine23 merged 7 commits from ci_zig into main 2024-02-17 16:41:50 +00:00
3 changed files with 21176 additions and 14 deletions
Showing only changes of commit 97f6a3d118 - Show all commits

View File

@@ -13,14 +13,17 @@ jobs:
strategy:
matrix:
node_version: [ 16.x, 18.x, 19.x, 20.x, 21.x ]
target_os: [ "windows", "linux", "macos" ]
target_arch: [ "x86_64", "aarch64" ]
target_os:
- "linux"
# - "windows"
# - "macos"
steps:
- uses: actions/checkout@v4
name: Checkout
- uses: goto-bus-stop/setup-zig@v2
name: "Setup zig"
- name: "Setup zig"
uses: goto-bus-stop/setup-zig@v2
- uses: actions/setup-node@v4
name: Setup Node.js
@@ -36,11 +39,6 @@ jobs:
- name: Build addon
run: npm run dev -- --target_zig=${{ matrix.target_arch }}-${{ matrix.target_os }}
env:
CC: zig cc -target ${{ matrix.target_arch }}-${{ matrix.target_os }}
CXX: "zig c++ -target ${{ matrix.target_arch }}-${{ matrix.target_os }}"
AR: "zig ar"
RANLIB: "zig ranlib"
- name: Upload prebuilds interface
uses: actions/upload-artifact@v3

View File

@@ -4,6 +4,7 @@ import { promises as fs } from "node:fs";
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";
import zig_config from "./zigTargs.json" assert { type: "json" };
const __dirname = path.dirname(fileURLToPath(import.meta.url)); // Fix ESM __dirname
const nodeGyp = path.resolve(createRequire(import.meta.url).resolve("node-gyp"), "../../bin/node-gyp.js"); // Node gyp script
@@ -83,22 +84,28 @@ async function migrateBuildAddon(platform, arch) {
if (args.at(0) === "build") {
const config = {
clean: args.includes("--clean"),
zigUse: false,
/** @type {{ os: NodeJS.Platform, arch: NodeJS.Architecture, extra_env?: Record<string, string> }[]} */
zigUse: !args.includes("--no-zig"),
autoArchs: args.includes("--auto"),
/** @type {{ os: string, arch: string, extra_env?: Record<string, string> }[]} */
targets: [ { os: process.platform, arch: process.arch } ],
};
if (args.some(s => s.startsWith("--zig_target=")||s.startsWith("--target="))) {
config.zigUse = true;
if (config.zigUse && args.some(s => s.startsWith("--zig_target="))) {
config.targets = [];
const check = /^([a-zA-Z0-9_\-]+)-([a-zA-Z0-9_]+)$/;
const ts = args.filter(s => s.startsWith("--zig_target=")||s.startsWith("--target=")).map(s => (s[3] === "z" ? s.slice(13) : s.slice(9)).trim());
const check = /^([a-z0-9_]+)-([a-z0-9_]+)(-([a-z0-9_]+))?$/;
const ts = args.filter(s => s.startsWith("--zig_target=")).map(s => s.slice(13).trim());
for (const t of ts) {
if (!(check.test(t))) {
console.error("Target (%s) is invalid!", t);
process.exit(-1);
}
let [, arch_t, os_t ] = (check.exec(t)||[]);
if (!zig_config.arch.includes(arch_t) || !zig_config.os.includes(os_t)) {
console.error("Target (%s) is invalid!", t);
if (!zig_config.arch[arch_t]) console.error("Avaible archs:", zig_config.arch.join("\n"));
if (!zig_config.os[os_t]) console.error("Avaible os:", zig_config.os.join("\n"));
process.exit(-1);
}
if (os_t === "windows") os_t = "win32";
else if (os_t === "macos") os_t = "darwin";

21157
libs/zigTargs.json Normal file

File diff suppressed because it is too large Load Diff