Skip to content

A fast, helpful, and open-source document parser

feat: support older glibc on releases

Logan Markewichc02d6f74f6aa
diff --git a/.github/workflows/release-crates.yml b/.github/workflows/release-crates.yml
index 00f32b5..2e42439 100644
--- a/.github/workflows/release-crates.yml
+++ b/.github/workflows/release-crates.yml
@@ -81,10 +81,12 @@ jobs:
os: ubuntu-22.04
artifact: lit-linux-x64
pdfium-dylib: libpdfium.so
+ use-glibc-container: true
- target: aarch64-unknown-linux-gnu
os: ubuntu-22.04-arm
artifact: lit-linux-arm64
pdfium-dylib: libpdfium.so
+ use-glibc-container: true
- target: aarch64-apple-darwin
os: macos-latest
artifact: lit-darwin-arm64
@@ -112,7 +114,7 @@ jobs:
targets: ${{ matrix.target }}
- name: Install system dependencies (Linux)
- if: runner.os == 'Linux'
+ if: runner.os == 'Linux' && !matrix.use-glibc-container
run: |
sudo apt-get update
sudo apt-get install -y libtesseract-dev libleptonica-dev
@@ -138,8 +140,22 @@ jobs:
key: ${{ runner.os }}-${{ matrix.target }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
- name: Build
+ if: ${{ !matrix.use-glibc-container }}
run: cargo build --release --target ${{ matrix.target }} -p liteparse
+ - name: Build (glibc container)
+ if: ${{ matrix.use-glibc-container }}
+ run: |
+ chmod +x scripts/build-glibc-cli.sh
+ docker run --rm \
+ -v "$GITHUB_WORKSPACE":/work \
+ -v "$HOME/.cargo/registry":/root/.cargo/registry \
+ -v "$HOME/.cargo/git":/root/.cargo/git \
+ -v "$HOME/.cache/pdfium-rs":/root/.cache/pdfium-rs \
+ -w /work \
+ node:20-bullseye \
+ /work/scripts/build-glibc-cli.sh ${{ matrix.target }}
+
- name: Stage binary and pdfium (Unix)
if: runner.os != 'Windows'
shell: bash
diff --git a/.github/workflows/release-node.yml b/.github/workflows/release-node.yml
index 76c6d8e..2933bbe 100644
--- a/.github/workflows/release-node.yml
+++ b/.github/workflows/release-node.yml
@@ -57,11 +57,15 @@ jobs:
target: x86_64-unknown-linux-gnu
node-arch: linux-x64-gnu
pdfium-dylib: libpdfium.so
+ # Build in an old-glibc container (see build-glibc-node.sh) so the
+ # binary loads on glibc <= 2.34 hosts like AWS Lambda / AL2023.
+ use-glibc-container: true
- os: ubuntu-22.04-arm
target: aarch64-unknown-linux-gnu
node-arch: linux-arm64-gnu
pdfium-dylib: libpdfium.so
+ use-glibc-container: true
- os: ubuntu-22.04
target: x86_64-unknown-linux-musl
@@ -94,7 +98,7 @@ jobs:
targets: ${{ matrix.target }}
- name: Install system dependencies (Linux glibc)
- if: runner.os == 'Linux' && !matrix.use-container
+ if: runner.os == 'Linux' && !matrix.use-container && !matrix.use-glibc-container
run: |
sudo apt-get update
sudo apt-get install -y libtesseract-dev libleptonica-dev
@@ -120,11 +124,24 @@ jobs:
run: npm install --ignore-scripts
- name: Build native module
- if: ${{ !matrix.use-container }}
+ if: ${{ !matrix.use-container && !matrix.use-glibc-container }}
working-directory: packages/node
shell: bash
run: npx napi build --cargo-cwd ../../crates/liteparse-napi --platform --release --js false --dts native.d.ts --target ${{ matrix.target }} .
+ - name: Build native module (glibc container)
+ if: ${{ matrix.use-glibc-container }}
+ run: |
+ chmod +x scripts/build-glibc-node.sh
+ docker run --rm \
+ -v "$GITHUB_WORKSPACE":/work \
+ -v "$HOME/.cargo/registry":/root/.cargo/registry \
+ -v "$HOME/.cargo/git":/root/.cargo/git \
+ -v "$HOME/.cache/pdfium-rs":/root/.cache/pdfium-rs \
+ -w /work/packages/node \
+ node:20-bullseye \
+ /work/scripts/build-glibc-node.sh ${{ matrix.target }}
+
- name: Build native module (musl container)
if: ${{ matrix.use-container }}
run: |
@@ -237,10 +254,11 @@ jobs:
- target: x86_64-unknown-linux-gnu
os: ubuntu-22.04
artifact: lit-linux-x64
+ use-glibc-container: true
- target: aarch64-unknown-linux-gnu
- os: ubuntu-22.04
+ os: ubuntu-22.04-arm
artifact: lit-linux-arm64
- use-cross: true
+ use-glibc-container: true
- target: aarch64-apple-darwin
os: macos-latest
artifact: lit-darwin-arm64
@@ -257,18 +275,11 @@ jobs:
targets: ${{ matrix.target }}
- name: Install system dependencies (Linux native)
- if: runner.os == 'Linux' && !matrix.use-cross
+ if: runner.os == 'Linux' && !matrix.use-glibc-container
run: |
sudo apt-get update
sudo apt-get install -y libtesseract-dev libleptonica-dev
- - name: Install cross-compilation tools (Linux ARM64)
- if: matrix.use-cross
- run: |
- sudo apt-get update
- sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
-
- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
run: brew install tesseract leptonica
@@ -284,12 +295,21 @@ jobs:
key: ${{ matrix.os }}-${{ matrix.target }}-cargo-cli-${{ hashFiles('**/Cargo.lock') }}
- name: Build
+ if: ${{ !matrix.use-glibc-container }}
+ run: cargo build --release --target ${{ matrix.target }} -p liteparse
+
+ - name: Build (glibc container)
+ if: ${{ matrix.use-glibc-container }}
run: |
- if [ "${{ matrix.use-cross }}" = "true" ]; then
- cargo build --release --target ${{ matrix.target }} --no-default-features -p liteparse
- else
- cargo build --release --target ${{ matrix.target }} -p liteparse
- fi
+ chmod +x scripts/build-glibc-cli.sh
+ docker run --rm \
+ -v "$GITHUB_WORKSPACE":/work \
+ -v "$HOME/.cargo/registry":/root/.cargo/registry \
+ -v "$HOME/.cargo/git":/root/.cargo/git \
+ -v "$HOME/.cache/pdfium-rs":/root/.cache/pdfium-rs \
+ -w /work \
+ node:20-bullseye \
+ /work/scripts/build-glibc-cli.sh ${{ matrix.target }}
- name: Package binary
run: |
diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml
index 663b37d..431bc8d 100644
--- a/.github/workflows/release-python.yml
+++ b/.github/workflows/release-python.yml
@@ -277,9 +277,11 @@ jobs:
- target: x86_64-unknown-linux-gnu
os: ubuntu-22.04
artifact: lit-linux-x64
+ use-glibc-container: true
- target: aarch64-unknown-linux-gnu
os: ubuntu-22.04-arm
artifact: lit-linux-arm64
+ use-glibc-container: true
- target: aarch64-apple-darwin
os: macos-latest
artifact: lit-darwin-arm64
@@ -296,7 +298,7 @@ jobs:
targets: ${{ matrix.target }}
- name: Install system dependencies (Linux)
- if: runner.os == 'Linux'
+ if: runner.os == 'Linux' && !matrix.use-glibc-container
run: |
sudo apt-get update
sudo apt-get install -y libtesseract-dev libleptonica-dev
@@ -316,8 +318,22 @@ jobs:
key: ${{ runner.os }}-${{ matrix.target }}-cargo-cli-${{ hashFiles('**/Cargo.lock') }}
- name: Build
+ if: ${{ !matrix.use-glibc-container }}
run: cargo build --release --target ${{ matrix.target }} -p liteparse
+ - name: Build (glibc container)
+ if: ${{ matrix.use-glibc-container }}
+ run: |
+ chmod +x scripts/build-glibc-cli.sh
+ docker run --rm \
+ -v "$GITHUB_WORKSPACE":/work \
+ -v "$HOME/.cargo/registry":/root/.cargo/registry \
+ -v "$HOME/.cargo/git":/root/.cargo/git \
+ -v "$HOME/.cache/pdfium-rs":/root/.cache/pdfium-rs \
+ -w /work \
+ node:20-bullseye \
+ /work/scripts/build-glibc-cli.sh ${{ matrix.target }}
+
- name: Package binary
run: |
mkdir -p dist
diff --git a/scripts/build-glibc-cli.sh b/scripts/build-glibc-cli.sh
new file mode 100755
index 0000000..39c45af
--- /dev/null
+++ b/scripts/build-glibc-cli.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+set -eux
+
+# Build the `lit` CLI inside an OLD-glibc Debian container so the resulting
+# binary loads on hosts with an older glibc than the CI runner.
+#
+# The GitHub `ubuntu-22.04` runners ship glibc 2.35, which bakes a `GLIBC_2.35`
+# symbol requirement into the binary and breaks it on AWS Lambda / Amazon Linux
+# 2023 (glibc 2.34) and other older hosts. Debian bullseye ships glibc 2.31 —
+# below the 2.34 Lambda floor — and glibc is backward-compatible, so a
+# 2.31-baseline binary still runs on newer hosts. This only WIDENS
+# compatibility; it is not a breaking change.
+#
+# Mirrors scripts/build-glibc-node.sh but produces the standalone CLI via
+# `cargo build` instead of the napi module. tesseract-rs (build-tesseract)
+# compiles Tesseract + Leptonica from source; on linux-gnu it uses
+# g++/libstdc++, so no clang/libc++ bundling is required.
+
+TARGET="${1:?usage: build-glibc-cli.sh <rust-target>}"
+
+export DEBIAN_FRONTEND=noninteractive
+apt-get update
+apt-get install -y --no-install-recommends \
+ build-essential cmake git curl pkg-config ca-certificates \
+ libtesseract-dev libleptonica-dev \
+ libpng-dev libjpeg-dev libtiff-dev zlib1g-dev
+
+curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs \
+ | sh -s -- -y --default-toolchain 1.95.0 -t "$TARGET"
+. "$HOME/.cargo/env"
+
+cargo build --release --target "$TARGET" -p liteparse
+
+BIN="target/$TARGET/release/lit"
+echo "Built CLI: $BIN"
+ls -la "$BIN"
+echo "glibc symbol versions required by $BIN:"
+objdump -T "$BIN" 2>/dev/null \
+ | grep -oE 'GLIBC_[0-9]+\.[0-9]+' | sort -u -V || true
diff --git a/scripts/build-glibc-node.sh b/scripts/build-glibc-node.sh
new file mode 100755
index 0000000..540d1f7
--- /dev/null
+++ b/scripts/build-glibc-node.sh
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+set -eux
+
+# Build the linux-gnu napi binding inside an OLD-glibc Debian container so the
+# resulting .node loads on hosts with an older glibc than the CI runner.
+#
+# The GitHub `ubuntu-22.04` runner ships glibc 2.35, which bakes a
+# `GLIBC_2.35` symbol requirement into the binary. That binary then fails to
+# dlopen on AWS Lambda / Amazon Linux 2023 (glibc 2.34) and other older hosts.
+# Debian bullseye ships glibc 2.31 — comfortably below the 2.34 Lambda floor —
+# and glibc is backward-compatible, so a 2.31-baseline binary still runs on the
+# newer runners/hosts. This only WIDENS compatibility; it is not a breaking
+# change for existing users.
+#
+# tesseract-rs (build-tesseract) compiles Tesseract + Leptonica from source via
+# cmake. On linux-gnu it selects g++/libstdc++ (see the crate's build.rs), so —
+# unlike the musl path — we do NOT need clang/libc++ and do not have to bundle a
+# C++ runtime next to the .node.
+
+TARGET="${1:?usage: build-glibc-node.sh <rust-target>}"
+
+export DEBIAN_FRONTEND=noninteractive
+apt-get update
+# build-essential/cmake/pkg-config: toolchain to compile Tesseract + Leptonica.
+# lib*-dev: image-format deps Leptonica links against (same set apt pulls in for
+# libleptonica-dev on the ubuntu runner today).
+apt-get install -y --no-install-recommends \
+ build-essential cmake git curl pkg-config ca-certificates \
+ libtesseract-dev libleptonica-dev \
+ libpng-dev libjpeg-dev libtiff-dev zlib1g-dev
+
+# Pin the same toolchain the non-container matrix builds use ([email protected]).
+curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs \
+ | sh -s -- -y --default-toolchain 1.95.0 -t "$TARGET"
+. "$HOME/.cargo/env"
+
+# node/npm/npx come from the node:20-bullseye base image; @napi-rs/cli is already
+# present in the host-installed node_modules (mounted via the workspace).
+npx napi build --cargo-cwd ../../crates/liteparse-napi --platform --release \
+ --js false --dts native.d.ts --target "$TARGET" .
+
+NODE_FILE=$(ls liteparse.*.node | head -n1)
+echo "Built native module: $NODE_FILE"
+ls -la ./*.node
+# Fail loudly if the build somehow still references a too-new glibc, so a broken
+# baseline can't silently ship again.
+echo "glibc symbol versions required by $NODE_FILE:"
+objdump -T "$NODE_FILE" 2>/dev/null \
+ | grep -oE 'GLIBC_[0-9]+\.[0-9]+' | sort -u -V || true