Skip to content

Commit ccb602e

Browse files
committed
Added build-litecam-jar.yml
1 parent 9923246 commit ccb602e

3 files changed

Lines changed: 249 additions & 0 deletions

File tree

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
name: Build LiteCam JAR
2+
3+
# Triggers on any push to main that touches the barcode-scanner project,
4+
# or on a manual workflow_dispatch so you can run it on-demand from GitHub.
5+
on:
6+
push:
7+
branches: [ main ]
8+
paths:
9+
- 'examples/barcode-scanner/**'
10+
- '.github/workflows/build-litecam-jar.yml'
11+
workflow_dispatch:
12+
13+
jobs:
14+
# ──────────────────────────────────────────────────────────────────
15+
# Phase 1: Build the platform-native shared library on each OS.
16+
# The three jobs run in parallel.
17+
# ──────────────────────────────────────────────────────────────────
18+
build-native:
19+
name: Build native (${{ matrix.name }})
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
# Windows – produces litecam.dll
25+
- name: windows-x86_64
26+
os: windows-latest
27+
lib_src: examples/barcode-scanner/build/Release/litecam.dll
28+
29+
# Linux – produces liblitecam.so
30+
- name: linux-x86_64
31+
os: ubuntu-latest
32+
lib_src: examples/barcode-scanner/build/liblitecam.so
33+
34+
# macOS – CMakeLists.txt sets CMAKE_OSX_ARCHITECTURES="x86_64;arm64"
35+
# so the resulting dylib is a universal binary for both Intel and Apple Silicon.
36+
- name: macos-universal
37+
os: macos-latest
38+
lib_src: examples/barcode-scanner/build/liblitecam.dylib
39+
40+
runs-on: ${{ matrix.os }}
41+
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v4
45+
46+
# Make sure JAVA_HOME is set before CMake runs so that find_package(JNI)
47+
# can locate the JNI headers needed to compile LiteCamJNI.cpp.
48+
- name: Set up Java (for JNI headers)
49+
uses: actions/setup-java@v4
50+
with:
51+
java-version: '11'
52+
distribution: 'temurin'
53+
54+
# Linux needs X11 and Video4Linux2 development headers.
55+
- name: Install Linux build dependencies
56+
if: matrix.os == 'ubuntu-latest'
57+
run: |
58+
sudo apt-get update
59+
sudo apt-get install -y \
60+
build-essential \
61+
cmake \
62+
libx11-dev \
63+
libv4l-dev
64+
65+
- name: Configure CMake
66+
working-directory: examples/barcode-scanner
67+
run: cmake -B build -DCMAKE_BUILD_TYPE=Release
68+
69+
- name: Build litecam shared library
70+
working-directory: examples/barcode-scanner
71+
run: cmake --build build --config Release --target litecam
72+
73+
- name: Upload native library artifact
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: native-${{ matrix.name }}
77+
path: ${{ matrix.lib_src }}
78+
if-no-files-found: error
79+
retention-days: 1 # Only needed within this workflow run
80+
81+
# ──────────────────────────────────────────────────────────────────
82+
# Phase 2: Collect all three native libraries, compile the Java
83+
# wrapper, and assemble the fat JAR that bundles every platform.
84+
# ──────────────────────────────────────────────────────────────────
85+
package-jar:
86+
name: Package multi-platform JAR
87+
needs: build-native
88+
runs-on: ubuntu-latest
89+
90+
steps:
91+
- name: Checkout repository
92+
uses: actions/checkout@v4
93+
94+
- name: Set up Java
95+
uses: actions/setup-java@v4
96+
with:
97+
java-version: '11'
98+
distribution: 'temurin'
99+
100+
# Download all three native artifacts into native-artifacts/<artifact-name>/
101+
- name: Download all native artifacts
102+
uses: actions/download-artifact@v4
103+
with:
104+
path: native-artifacts
105+
106+
- name: Show downloaded artifacts
107+
run: find native-artifacts -type f | sort
108+
109+
# Compile Java sources from java-src/ into java-build/
110+
- name: Compile Java sources
111+
working-directory: examples/barcode-scanner
112+
run: |
113+
rm -rf java-build
114+
mkdir -p java-build
115+
find java-src -name '*.java' | xargs javac -d java-build
116+
117+
# Arrange the native libraries into the layout that LiteCam.java
118+
# expects inside the JAR: /natives/<osToken>-<archToken>/<libname>
119+
#
120+
# LiteCam.java archToken logic:
121+
# aarch64 / arm64 → arm64
122+
# *64* → x86_64
123+
#
124+
# The macOS universal binary covers both Intel (x86_64) and Apple Silicon (arm64),
125+
# so the same file is placed into both macos-* directories.
126+
- name: Arrange native libraries in JAR staging area
127+
run: |
128+
BASE=examples/barcode-scanner/java-build/natives
129+
130+
mkdir -p "$BASE/windows-x86_64"
131+
mkdir -p "$BASE/linux-x86_64"
132+
mkdir -p "$BASE/macos-x86_64"
133+
mkdir -p "$BASE/macos-arm64"
134+
135+
cp native-artifacts/native-windows-x86_64/litecam.dll "$BASE/windows-x86_64/"
136+
cp native-artifacts/native-linux-x86_64/liblitecam.so "$BASE/linux-x86_64/"
137+
cp native-artifacts/native-macos-universal/liblitecam.dylib "$BASE/macos-x86_64/"
138+
cp native-artifacts/native-macos-universal/liblitecam.dylib "$BASE/macos-arm64/"
139+
140+
# MANIFEST.MF requires a trailing blank line per the JAR spec.
141+
- name: Create MANIFEST.MF
142+
run: |
143+
mkdir -p examples/barcode-scanner/java-build/META-INF
144+
printf 'Manifest-Version: 1.0\n' > examples/barcode-scanner/java-build/META-INF/MANIFEST.MF
145+
printf 'Main-Class: com.example.litecam.LiteCamViewer\n' >> examples/barcode-scanner/java-build/META-INF/MANIFEST.MF
146+
printf 'Implementation-Title: LiteCam Java Wrapper\n' >> examples/barcode-scanner/java-build/META-INF/MANIFEST.MF
147+
printf 'Implementation-Version: 1.0.0\n' >> examples/barcode-scanner/java-build/META-INF/MANIFEST.MF
148+
printf 'Built-By: GitHub Actions\n' >> examples/barcode-scanner/java-build/META-INF/MANIFEST.MF
149+
printf '\n' >> examples/barcode-scanner/java-build/META-INF/MANIFEST.MF
150+
151+
- name: Create litecam.jar
152+
working-directory: examples/barcode-scanner/java-build
153+
run: jar cfm ../litecam.jar META-INF/MANIFEST.MF .
154+
155+
- name: Verify JAR contents
156+
run: |
157+
echo "=== All entries in litecam.jar ==="
158+
jar -tf examples/barcode-scanner/litecam.jar
159+
echo ""
160+
echo "=== Native libraries ==="
161+
jar -tf examples/barcode-scanner/litecam.jar | grep '^natives/'
162+
163+
# Upload the JAR as a workflow artifact so it can be downloaded from the
164+
# GitHub Actions run page (Actions → the run → Artifacts section).
165+
# Retention is set to 90 days so recent builds remain downloadable.
166+
- name: Upload litecam.jar
167+
uses: actions/upload-artifact@v4
168+
with:
169+
name: litecam-jar
170+
path: examples/barcode-scanner/litecam.jar
171+
if-no-files-found: error
172+
retention-days: 90

examples/barcode-scanner/include/com_example_litecam_LiteCam.h

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)