Skip to content

A fast, helpful, and open-source document parser

chore: try making node ci green

Clelia (Astra) Bertelli349a4a0390ec
diff --git a/.github/workflows/ci-node.yml b/.github/workflows/ci-node.yml
index e6e0926..387349d 100644
--- a/.github/workflows/ci-node.yml
+++ b/.github/workflows/ci-node.yml
@@ -2,7 +2,7 @@ name: CI - Node Bindings
on:
push:
- branches: [main]
+ branches: [main, logan/musl-builds] # temporary, will remove once this is merged
paths:
- "crates/**"
- "packages/node/**"
@@ -105,9 +105,19 @@ jobs:
-w /work/packages/node \
node:20-alpine \
sh -c '
- apk add --no-cache build-base cmake git curl pkgconf tesseract-ocr-dev leptonica-dev perl openssl-dev
+ set -eux
+ # Static libs needed because musl rust defaults to -static-pie / crt-static
+ # for build scripts. openssl-libs-static/zlib-static satisfy tesseract-rs build-deps.
+ apk add --no-cache \
+ build-base cmake git curl pkgconf perl \
+ tesseract-ocr-dev leptonica-dev \
+ openssl-dev openssl-libs-static zlib-static
curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable -t x86_64-unknown-linux-musl
- source /root/.cargo/env
+ . /root/.cargo/env
+ # napi produces a cdylib (.node) which MUST be dynamically linked against libc,
+ # so disable crt-static for the final link. Build scripts still link static
+ # against openssl/zlib via the static libs above.
+ export RUSTFLAGS="-C target-feature=-crt-static"
npx napi build --cargo-cwd ../../crates/liteparse-napi --platform --release --js false --dts native.d.ts --target x86_64-unknown-linux-musl .
'
diff --git a/.github/workflows/release-node.yml b/.github/workflows/release-node.yml
index 11eba2c..e64a8f9 100644
--- a/.github/workflows/release-node.yml
+++ b/.github/workflows/release-node.yml
@@ -126,9 +126,19 @@ jobs:
-w /work/packages/node \
node:20-alpine \
sh -c '
- apk add --no-cache build-base cmake git curl pkgconf tesseract-ocr-dev leptonica-dev perl openssl-dev
+ set -eux
+ # Static libs needed because musl rust defaults to -static-pie / crt-static
+ # for build scripts. openssl-libs-static/zlib-static satisfy tesseract-rs build-deps.
+ apk add --no-cache \
+ build-base cmake git curl pkgconf perl \
+ tesseract-ocr-dev leptonica-dev \
+ openssl-dev openssl-libs-static zlib-static
curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable -t x86_64-unknown-linux-musl
- source /root/.cargo/env
+ . /root/.cargo/env
+ # napi produces a cdylib (.node) which MUST be dynamically linked against libc,
+ # so disable crt-static for the final link. Build scripts still link static
+ # against openssl/zlib via the static libs above.
+ export RUSTFLAGS="-C target-feature=-crt-static"
npx napi build --cargo-cwd ../../crates/liteparse-napi --platform --release --js false --dts native.d.ts --target x86_64-unknown-linux-musl .
'
diff --git a/musl_build_cargozig.md b/musl_build_cargozig.md
new file mode 100644
index 0000000..0c573c9
--- /dev/null
+++ b/musl_build_cargozig.md
@@ -0,0 +1,62 @@
+## Maturin
+
+Maturin has **first-class support** for `cargo-zigbuild` via the `--zig` flag:
+
+```bash
+maturin build --release --target x86_64-unknown-linux-musl --zig
+maturin build --release --target aarch64-unknown-linux-musl --zig
+```
+
+That's it. Maturin detects `cargo-zigbuild` is installed and routes through it automatically when `--zig` is passed. You just need:
+
+```bash
+pip install maturin
+cargo install cargo-zigbuild
+# and the targets:
+rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl
+```
+
+In a CI matrix (GitHub Actions example):
+```yaml
+- name: Build musl wheels
+ run: |
+ maturin build --release --target ${{ matrix.target }} --zig
+ strategy:
+ matrix:
+ target: [x86_64-unknown-linux-musl, aarch64-unknown-linux-musl]
+```
+
+## napi-rs
+
+Actually, the **real pattern** for napi is to override the cargo command via the `CARGO` env var or use napi's `--cargo-cwd` + a wrapper script. The cleanest approach in practice:
+
+```bash
+# Tell napi-rs to use cargo-zigbuild instead of cargo
+CARGO=cargo-zigbuild npx @napi-rs/cli build \
+ --platform \
+ --release \
+ --target x86_64-unknown-linux-musl
+```
+
+`napi-rs` internally shells out to whatever `$CARGO` points to, and `cargo-zigbuild` accepts the same interface as `cargo build`, so this works cleanly.
+
+## The even cleaner napi path: use their Docker images
+
+The `@napi-rs/cli` team maintains cross-compilation Docker images that have Zig + musl toolchains pre-configured:
+
+```bash
+docker run --rm -v $(pwd):/build \
+ ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine \
+ sh -c "cd /build && npx @napi-rs/cli build --release --target x86_64-unknown-linux-musl"
+```
+
+Their [CI template](https://github.com/napi-rs/package-template) scaffolds all of this out of the box if you use `napi new`.
+
+## Summary
+
+| Tool | musl + Zig support |
+|---|---|
+| maturin | Native `--zig` flag, trivial |
+| napi-rs | `CARGO=cargo-zigbuild` env var, or use their Docker images |
+
+For maturin, `--zig` is the blessed path. For napi-rs, the `CARGO` env var override or their Docker-based CI template is the practical answer.