Skip to content

Commit 05723db

Browse files
committed
Add new pacakge pdf-runtime
1 parent 3f061ba commit 05723db

66 files changed

Lines changed: 2651 additions & 43 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Build PDF Runtime
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
paths:
7+
- 'packages/pdf-runtime/**'
8+
- '.github/workflows/build-pdf-runtime.yml'
9+
push:
10+
branches:
11+
- main
12+
- next
13+
paths:
14+
- 'packages/pdf-runtime/**'
15+
- '.github/workflows/build-pdf-runtime.yml'
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
linux:
22+
name: Linux x64 + musl + WASM
23+
runs-on: ubuntu-24.04
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
target: [linux-x64, linuxmusl-x64, wasm32]
28+
steps:
29+
- uses: actions/checkout@v6
30+
- uses: pnpm/action-setup@v4
31+
with:
32+
version: 10.4.0
33+
- uses: actions/setup-node@v6
34+
with:
35+
node-version: 22
36+
cache: pnpm
37+
- if: ${{ !contains(matrix.target, 'linuxmusl') }}
38+
run: pnpm install --frozen-lockfile
39+
- if: ${{ !contains(matrix.target, 'linuxmusl') }}
40+
name: Install build tools
41+
run: sudo apt-get update && sudo apt-get install -y cmake clang
42+
- if: ${{ !contains(matrix.target, 'linuxmusl') }}
43+
name: Build target
44+
run: pnpm --filter @embedpdf/pdf-runtime build:target -- ${{ matrix.target }}
45+
- if: ${{ contains(matrix.target, 'linuxmusl') }}
46+
name: Build musl target in Alpine
47+
run: |
48+
docker run --rm \
49+
-v "$GITHUB_WORKSPACE:/workspace" \
50+
-w /workspace \
51+
node:22-alpine \
52+
sh -lc "apk add --no-cache bash cmake clang g++ make python3 curl tar git && corepack enable && pnpm install --frozen-lockfile && pnpm --filter @embedpdf/pdf-runtime build:target -- ${{ matrix.target }}"
53+
- uses: actions/upload-artifact@v6
54+
with:
55+
name: pdf-runtime-${{ matrix.target }}
56+
path: packages/pdf-runtime/npm/${{ matrix.target }}/
57+
58+
linux-arm:
59+
name: Linux arm64 + musl
60+
runs-on: ubuntu-24.04-arm
61+
strategy:
62+
fail-fast: false
63+
matrix:
64+
target: [linux-arm64, linuxmusl-arm64]
65+
steps:
66+
- uses: actions/checkout@v6
67+
- uses: pnpm/action-setup@v4
68+
with:
69+
version: 10.4.0
70+
- uses: actions/setup-node@v6
71+
with:
72+
node-version: 22
73+
cache: pnpm
74+
- if: ${{ !contains(matrix.target, 'linuxmusl') }}
75+
run: pnpm install --frozen-lockfile
76+
- if: ${{ !contains(matrix.target, 'linuxmusl') }}
77+
name: Install build tools
78+
run: sudo apt-get update && sudo apt-get install -y cmake clang
79+
- if: ${{ !contains(matrix.target, 'linuxmusl') }}
80+
name: Build target
81+
run: pnpm --filter @embedpdf/pdf-runtime build:target -- ${{ matrix.target }}
82+
- if: ${{ contains(matrix.target, 'linuxmusl') }}
83+
name: Build musl target in Alpine
84+
run: |
85+
docker run --rm \
86+
-v "$GITHUB_WORKSPACE:/workspace" \
87+
-w /workspace \
88+
node:22-alpine \
89+
sh -lc "apk add --no-cache bash cmake clang g++ make python3 curl tar git && corepack enable && pnpm install --frozen-lockfile && pnpm --filter @embedpdf/pdf-runtime build:target -- ${{ matrix.target }}"
90+
- uses: actions/upload-artifact@v6
91+
with:
92+
name: pdf-runtime-${{ matrix.target }}
93+
path: packages/pdf-runtime/npm/${{ matrix.target }}/
94+
95+
mac:
96+
name: macOS
97+
runs-on: macos-14
98+
strategy:
99+
fail-fast: false
100+
matrix:
101+
target: [darwin-arm64, darwin-x64]
102+
steps:
103+
- uses: actions/checkout@v6
104+
- uses: pnpm/action-setup@v4
105+
with:
106+
version: 10.4.0
107+
- uses: actions/setup-node@v6
108+
with:
109+
node-version: 22
110+
cache: pnpm
111+
- run: pnpm install --frozen-lockfile
112+
- name: Build target
113+
run: pnpm --filter @embedpdf/pdf-runtime build:target -- ${{ matrix.target }}
114+
- uses: actions/upload-artifact@v6
115+
with:
116+
name: pdf-runtime-${{ matrix.target }}
117+
path: packages/pdf-runtime/npm/${{ matrix.target }}/
118+
119+
win:
120+
name: Windows
121+
runs-on: windows-2022
122+
strategy:
123+
fail-fast: false
124+
matrix:
125+
target: [win32-x64, win32-arm64]
126+
steps:
127+
- uses: actions/checkout@v6
128+
- uses: pnpm/action-setup@v4
129+
with:
130+
version: 10.4.0
131+
- uses: actions/setup-node@v6
132+
with:
133+
node-version: 22
134+
cache: pnpm
135+
- run: pnpm install --frozen-lockfile
136+
- name: Build target
137+
shell: bash
138+
run: pnpm --filter @embedpdf/pdf-runtime build:target -- ${{ matrix.target }}
139+
- uses: actions/upload-artifact@v6
140+
with:
141+
name: pdf-runtime-${{ matrix.target }}
142+
path: packages/pdf-runtime/npm/${{ matrix.target }}/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ config/tsup.frameworks.config.bundled*
1515
publish-summary.json
1616
**/.svelte-kit
1717
**/*/*.tgz
18+
temp/

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
path = packages/pdfium/pdfium-src
33
url = https://github.com/embedpdf/pdfium.git
44
branch = embedpdf/main
5+
[submodule "packages/pdf-runtime/runtime-src"]
6+
path = packages/pdf-runtime/runtime-src
7+
url = https://github.com/embedpdf/pdfium.git
8+
branch = embedpdf/main

packages/pdf-runtime/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pdf-runtime-build.local.json
2+
3+
build/build/
4+
build/cache/
5+
build/generated/
6+
build/libpdfium/
7+
build/local-artifacts/
8+
build/local-staging/
9+
.cache/
10+
11+
npm/*/pdf-runtime.node
12+
npm/wasm32/pdfium.js
13+
npm/wasm32/pdfium.cjs
14+
npm/wasm32/pdfium.wasm

packages/pdf-runtime/Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# syntax=docker/dockerfile-upstream:master-labs
2+
FROM emscripten/emsdk:3.1.70 AS base
3+
4+
ARG DEBIAN_FRONTEND=noninteractive
5+
6+
ENV PATH="/emsdk/upstream/bin:${PATH}"
7+
8+
RUN apt-get update && \
9+
apt-get install -y --no-install-recommends \
10+
autoconf \
11+
automake \
12+
build-essential \
13+
curl \
14+
git \
15+
libtool \
16+
lsb-release \
17+
pkg-config \
18+
python3 \
19+
rsync \
20+
subversion \
21+
tini \
22+
yasm && \
23+
apt-get clean && rm -rf /var/lib/apt/lists/*
24+
25+
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
26+
apt-get install -y --no-install-recommends nodejs && \
27+
apt-get clean && rm -rf /var/lib/apt/lists/*
28+
29+
RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git \
30+
-b main /opt/depot-tools
31+
32+
ENV PATH="${PATH}:/opt/depot-tools"
33+
34+
RUN curl -sSf https://sh.rustup.rs | bash -s -- -y && \
35+
. "$HOME/.cargo/env" && \
36+
cargo install --locked watchexec-cli && \
37+
strip "$HOME/.cargo/bin/watchexec" && \
38+
rm -rf "$HOME/.cargo/registry" "$HOME/.cargo/git"
39+
40+
ENV PATH="$HOME/.cargo/bin:${PATH}"
41+
42+
WORKDIR /workspace
43+
44+
ENTRYPOINT ["/usr/bin/tini", "--"]

packages/pdf-runtime/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# @embedpdf/pdf-runtime
2+
3+
Low-level PDF execution runtime for EmbedPDF.
4+
5+
This package is powered by EmbedPDF's fork of PDFium and provides a single runtime abstraction over WebAssembly and native Node.js builds. Most users should continue to use `@embedpdf/engines`; this package is the implementation layer used by future engine releases.
6+
7+
## Packages
8+
9+
- `@embedpdf/pdf-runtime` - pure JavaScript loader and shared types.
10+
- `@embedpdf/pdf-runtime-wasm32` - WebAssembly runtime.
11+
- `@embedpdf/pdf-runtime-<platform>` - native Node.js runtime packages.
12+
13+
The main package resolves the best runtime for the current environment and falls back to WebAssembly when a native runtime is unavailable.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(pdf_runtime_node)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
if(NOT DEFINED PDFIUM_LIB_DIR)
8+
message(FATAL_ERROR "PDFIUM_LIB_DIR is required")
9+
endif()
10+
11+
if(NOT DEFINED PDFIUM_INCLUDE_DIR)
12+
message(FATAL_ERROR "PDFIUM_INCLUDE_DIR is required")
13+
endif()
14+
15+
set(GENERATED_DIR "${CMAKE_CURRENT_LIST_DIR}/generated")
16+
17+
add_library(${PROJECT_NAME} SHARED
18+
"${GENERATED_DIR}/binding.generated.cc"
19+
)
20+
21+
target_include_directories(${PROJECT_NAME} PRIVATE
22+
${CMAKE_JS_INC}
23+
"${PDFIUM_INCLUDE_DIR}"
24+
)
25+
26+
if(WIN32)
27+
set(PDFIUM_LIB "${PDFIUM_LIB_DIR}/pdfium.lib")
28+
else()
29+
set(PDFIUM_LIB "${PDFIUM_LIB_DIR}/libpdfium.a")
30+
endif()
31+
32+
target_link_libraries(${PROJECT_NAME} PRIVATE
33+
${CMAKE_JS_LIB}
34+
"${PDFIUM_LIB}"
35+
)
36+
37+
if(APPLE)
38+
target_link_libraries(${PROJECT_NAME} PRIVATE
39+
"-framework AppKit"
40+
"-framework CoreFoundation"
41+
"-framework CoreGraphics"
42+
"-framework Foundation"
43+
)
44+
elseif(WIN32)
45+
target_link_libraries(${PROJECT_NAME} PRIVATE
46+
advapi32
47+
gdi32
48+
user32
49+
usp10
50+
)
51+
else()
52+
target_link_libraries(${PROJECT_NAME} PRIVATE
53+
pthread
54+
dl
55+
m
56+
)
57+
endif()
58+
59+
set_target_properties(${PROJECT_NAME} PROPERTIES
60+
PREFIX ""
61+
SUFFIX ".node"
62+
OUTPUT_NAME "pdf-runtime"
63+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
TARGET="${PDF_RUNTIME_TARGET:-wasm32}"
6+
LIB_DIR="$ROOT/build/libpdfium/$TARGET"
7+
OUT_DIR="$ROOT/npm/wasm32"
8+
GEN_DIR="$ROOT/build/generated"
9+
10+
mkdir -p "$OUT_DIR"
11+
12+
em++ "$LIB_DIR/lib/libpdfium.a" \
13+
-sEXPORT_ES6=1 \
14+
-sENVIRONMENT=node,worker,web,shell \
15+
-sMODULARIZE=1 \
16+
-sWASM=1 \
17+
-sALLOW_MEMORY_GROWTH=1 \
18+
-sALLOW_TABLE_GROWTH=1 \
19+
-sEXPORT_NAME=createPdfRuntimeWasm \
20+
-sASSERTIONS=1 \
21+
-sEXPORTED_RUNTIME_METHODS="$(cat "$GEN_DIR/exported-runtime-methods.txt")" \
22+
-sEXPORTED_FUNCTIONS="$(cat "$GEN_DIR/exported-functions.txt")" \
23+
-I"$LIB_DIR/include" \
24+
-std=c++17 \
25+
-Wall \
26+
--no-entry \
27+
-o "$OUT_DIR/pdfium.js"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
TARGET="${PDF_RUNTIME_TARGET:-wasm32}"
6+
LIB_DIR="$ROOT/build/libpdfium/$TARGET"
7+
OUT_DIR="$ROOT/npm/wasm32"
8+
GEN_DIR="$ROOT/build/generated"
9+
10+
mkdir -p "$OUT_DIR"
11+
12+
em++ "$LIB_DIR/lib/libpdfium.a" \
13+
-sENVIRONMENT=node,worker,web,shell \
14+
-sMODULARIZE=1 \
15+
-sWASM=1 \
16+
-sALLOW_MEMORY_GROWTH=1 \
17+
-sALLOW_TABLE_GROWTH=1 \
18+
-sEXPORT_NAME=createPdfRuntimeWasm \
19+
-sASSERTIONS=1 \
20+
-sEXPORTED_RUNTIME_METHODS="$(cat "$GEN_DIR/exported-runtime-methods.txt")" \
21+
-sEXPORTED_FUNCTIONS="$(cat "$GEN_DIR/exported-functions.txt")" \
22+
-I"$LIB_DIR/include" \
23+
-std=c++17 \
24+
-Wall \
25+
--no-entry \
26+
-o "$OUT_DIR/pdfium.cjs"

0 commit comments

Comments
 (0)