Skip to content

Commit 8526410

Browse files
author
Dave Kozma
authored
Add precompiled binary support for Linux, macOS, and Windows (#51)
* Add build workflow * Install pnpm with corepack * Install deps * Specify linker and cross compiler env vars * Update c2pa to 0.27.1 * Build for mac * Add windows build for x86_64 * Upload artifact * Update Neon dependency
1 parent 2cf6a56 commit 8526410

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+858
-325
lines changed

.changeset/warm-phones-kick.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"c2pa-node": patch
3+
---
4+
5+
- Add precompiled binary support for Linux, macOS, and Windows
6+
- Update c2pa-rs to 0.27.1

.github/workflows/build-test.yml

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build-test
1+
name: Build and test
22

33
on:
44
push:
@@ -12,17 +12,18 @@ jobs:
1212
name: Build and test
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v3
16-
- name: Use Node.js
17-
uses: actions/setup-node@v3
18-
with:
19-
node-version: "16.x"
15+
- uses: actions/checkout@v4
16+
17+
- name: Install pnpm
18+
run: |
19+
corepack enable
20+
corepack prepare pnpm@latest --activate
2021
21-
- uses: pnpm/action-setup@v2
22-
name: Install pnpm
23-
id: pnpm-install
22+
- name: Install Node.js
23+
uses: actions/setup-node@v4
2424
with:
25-
version: 8
25+
node-version: 18
26+
cache: pnpm
2627

2728
- run: pnpm install
2829
- run: pnpm run build
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Build release binaries
2+
3+
on:
4+
push:
5+
branches:
6+
- build-binaries
7+
release:
8+
types: ['created']
9+
10+
jobs:
11+
build-binaries:
12+
name: Build binaries for ${{matrix.target}}
13+
runs-on: ${{matrix.runner}}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- target: aarch64-unknown-linux-gnu
19+
runner: ubuntu-latest
20+
- target: x86_64-unknown-linux-gnu
21+
runner: ubuntu-latest
22+
- target: aarch64-apple-darwin
23+
runner: macos-14
24+
- target: x86_64-apple-darwin
25+
runner: macos-13
26+
- target: x86_64-pc-windows-msvc
27+
runner: windows-latest
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Install system deps (aarch64-unknown-linux-gnu)
34+
if: ${{matrix.target == 'aarch64-unknown-linux-gnu'}}
35+
run: |
36+
sudo apt-get update
37+
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross
38+
39+
- name: Install Rust toolchain
40+
uses: dtolnay/rust-toolchain@stable
41+
with:
42+
components: llvm-tools-preview
43+
target: ${{matrix.target}}
44+
45+
- name: Install pnpm
46+
run: |
47+
corepack enable
48+
corepack prepare pnpm@latest --activate
49+
50+
- name: Install Node.js
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version: 18
54+
cache: pnpm
55+
56+
- name: Cache Rust dependencies
57+
uses: Swatinem/rust-cache@v2
58+
with:
59+
shared-key: ${{matrix.target}}
60+
61+
- name: Install Node.js dependencies
62+
env:
63+
SKIP_RUST_BUILD: 1
64+
run: pnpm install
65+
66+
- name: Build library for aarch64-unknown-linux-gnu
67+
if: ${{matrix.target == 'aarch64-unknown-linux-gnu'}}
68+
env:
69+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
70+
CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
71+
CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++
72+
run: |
73+
mkdir -p generated/${{matrix.target}}
74+
pnpm run build:rust --target=${{matrix.target}}
75+
76+
- name: Build library
77+
id: build-library
78+
if: ${{!contains(fromJSON('["aarch64-unknown-linux-gnu"]'), matrix.target)}}
79+
run: |
80+
mkdir -p generated/${{matrix.target}}
81+
pnpm run build:rust --target=${{matrix.target}}
82+
83+
- name: Package artifact
84+
id: package-artifact
85+
# This needs to be set so that this works on a Windows runner
86+
shell: bash
87+
env:
88+
ARCHIVE_FILENAME: c2pa-node_${{matrix.target}}-${{ github.event.release.tag_name || 'dev' }}.zip
89+
run: |
90+
cd generated
91+
7z a -tzip "${{ env.ARCHIVE_FILENAME }}" c2pa.node
92+
echo "archive=${{ env.ARCHIVE_FILENAME }}" >> "$GITHUB_OUTPUT"
93+
94+
- name: Upload artifact (development only)
95+
id: upload-artifact
96+
uses: actions/upload-artifact@v4
97+
if: ${{ github.event.release.upload_url == '' }}
98+
with:
99+
name: ${{ steps.package-artifact.outputs.archive }}
100+
path: generated/${{ steps.package-artifact.outputs.archive }}
101+
retention-days: 3
102+
103+
- name: Upload release asset
104+
id: upload-release-asset
105+
uses: actions/upload-release-asset@v1
106+
if: ${{ github.event.release.upload_url != '' }}
107+
env:
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
with:
110+
upload_url: ${{ github.event.release.upload_url }}
111+
asset_path: generated/${{ steps.package-artifact.outputs.archive }}
112+
asset_name: ${{ steps.package-artifact.outputs.archive }}
113+
asset_content_type: application/zip

.github/workflows/release.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ jobs:
1515
- name: Checkout Repo
1616
uses: actions/checkout@v3
1717

18-
- name: Setup Node.js 16.x
19-
uses: actions/setup-node@v3
20-
with:
21-
node-version: 16.x
18+
- name: Install pnpm
19+
run: |
20+
corepack enable
21+
corepack prepare pnpm@latest --activate
2222
23-
- uses: pnpm/action-setup@v2
24-
name: Install pnpm
25-
id: pnpm-install
23+
- name: Install Node.js
24+
uses: actions/setup-node@v4
2625
with:
27-
version: 8
26+
node-version: 18
27+
cache: pnpm
2828

2929
- name: Install Dependencies
3030
run: pnpm install

0 commit comments

Comments
 (0)