Skip to content

Commit 268fd51

Browse files
committed
Add make target to enable all patches, and corresponding CI workflow
1 parent 2f5b0ba commit 268fd51

4 files changed

Lines changed: 185 additions & 9 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Patched JNI CI
2+
3+
# This workflow attempts to build and test the wolfSSL JNI library with all
4+
# available wolfSSL PR patches applied, eg WOLFSSL_PR*_PATCH_APPLIED defines.
5+
# It currently only supports a single PR patch at a time, using the highest PR
6+
# number found in the defines.
7+
8+
on:
9+
push:
10+
branches: [ 'master', 'main', 'release/**' ]
11+
pull_request:
12+
branches: [ 'master' ]
13+
14+
jobs:
15+
resolve_wolfssl_ref:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
should_run: ${{ steps.resolve.outputs.should_run }}
19+
wolfssl_repo: ${{ steps.resolve.outputs.wolfssl_repo }}
20+
wolfssl_ref: ${{ steps.resolve.outputs.wolfssl_ref }}
21+
pr_number: ${{ steps.resolve.outputs.pr_number }}
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Resolve wolfSSL ref from patch defines
26+
id: resolve
27+
run: |
28+
set -euo pipefail
29+
30+
# Find WOLFSSL_PR*_PATCH_APPLIED defines in wolfssl source.
31+
defines="$(./scripts/find-wolfssl-pr-patch-defines.sh)"
32+
if [ -z "$defines" ]; then
33+
echo "::warning::No WOLFSSL_PR*_PATCH_APPLIED defines found; skipping patched CI."
34+
echo "should_run=false" >> "$GITHUB_OUTPUT"
35+
exit 0
36+
fi
37+
echo "Found patch defines:"
38+
printf "%s\n" "$defines"
39+
40+
# Find the highest PR number from the defines.
41+
pr_number="$(printf "%s\n" "$defines" | sed -E 's/^WOLFSSL_PR([0-9]+)_PATCH_APPLIED$/\1/' | sort -n | tail -1)"
42+
if [ -z "$pr_number" ]; then
43+
echo "::warning::Failed to derive PR number from patch defines; skipping patched CI."
44+
echo "should_run=false" >> "$GITHUB_OUTPUT"
45+
exit 0
46+
fi
47+
echo "Highest PR number from defines: $pr_number"
48+
49+
# Check PR status via GitHub API.
50+
pr_json="$(curl -fsSL "https://api.github.com/repos/wolfSSL/wolfssl/pulls/$pr_number" || true)"
51+
if [ -z "$pr_json" ]; then
52+
echo "::warning::Unable to fetch PR #$pr_number from GitHub API; skipping patched CI."
53+
echo "should_run=false" >> "$GITHUB_OUTPUT"
54+
exit 0
55+
fi
56+
echo "Fetched PR #$pr_number info from GitHub API."
57+
58+
state="$(printf "%s" "$pr_json" | jq -r '.state // empty')"
59+
merged_at="$(printf "%s" "$pr_json" | jq -r '.merged_at // empty')"
60+
head_repo="$(printf "%s" "$pr_json" | jq -r '.head.repo.full_name // empty')"
61+
head_ref="$(printf "%s" "$pr_json" | jq -r '.head.ref // empty')"
62+
63+
if [ -n "$merged_at" ]; then
64+
echo "PR #$pr_number is merged; using wolfSSL master branch."
65+
echo "should_run=true" >> "$GITHUB_OUTPUT"
66+
echo "wolfssl_repo=wolfSSL/wolfssl" >> "$GITHUB_OUTPUT"
67+
echo "wolfssl_ref=master" >> "$GITHUB_OUTPUT"
68+
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
69+
exit 0
70+
fi
71+
72+
if [ "$state" = "open" ] && [ -n "$head_repo" ] && [ -n "$head_ref" ]; then
73+
echo "should_run=true" >> "$GITHUB_OUTPUT"
74+
echo "wolfssl_repo=$head_repo" >> "$GITHUB_OUTPUT"
75+
echo "wolfssl_ref=$head_ref" >> "$GITHUB_OUTPUT"
76+
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
77+
echo "PR #$pr_number is open; using branch $head_ref from repo $head_repo."
78+
exit 0
79+
fi
80+
81+
echo "::warning::PR #$pr_number is not merged or has no accessible branch; skipping patched CI."
82+
echo "should_run=false" >> "$GITHUB_OUTPUT"
83+
84+
patched_jni_build:
85+
needs: resolve_wolfssl_ref
86+
if: needs.resolve_wolfssl_ref.outputs.should_run == 'true'
87+
runs-on: ubuntu-latest
88+
steps:
89+
- uses: actions/checkout@v4
90+
91+
- name: Cache JUnit dependencies
92+
uses: actions/cache@v4
93+
id: cache-junit
94+
with:
95+
path: junit
96+
key: junit-jars-v1
97+
98+
- name: Download junit-4.13.2.jar
99+
if: steps.cache-junit.outputs.cache-hit != 'true'
100+
run: curl -fsSL -o "$GITHUB_WORKSPACE/junit/junit-4.13.2.jar" https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar
101+
- name: Download hamcrest-all-1.3.jar
102+
if: steps.cache-junit.outputs.cache-hit != 'true'
103+
run: curl -fsSL -o "$GITHUB_WORKSPACE/junit/hamcrest-all-1.3.jar" https://repo1.maven.org/maven2/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3.jar
104+
105+
- name: Build native wolfSSL
106+
uses: wolfSSL/actions-build-autotools-project@v1
107+
with:
108+
repository: ${{ needs.resolve_wolfssl_ref.outputs.wolfssl_repo }}
109+
ref: ${{ needs.resolve_wolfssl_ref.outputs.wolfssl_ref }}
110+
path: wolfssl
111+
configure: --enable-jni
112+
check: false
113+
install: true
114+
115+
- name: Setup java
116+
uses: actions/setup-java@v4
117+
with:
118+
distribution: zulu
119+
java-version: '21'
120+
121+
- name: Set JUNIT_HOME
122+
run: |
123+
echo "JUNIT_HOME=$GITHUB_WORKSPACE/junit" >> "$GITHUB_ENV"
124+
125+
- name: Set LD_LIBRARY_PATH
126+
run: |
127+
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib" >> "$GITHUB_ENV"
128+
129+
- name: Build and test JNI library with all patches
130+
run: make all-patched PREFIX=$GITHUB_WORKSPACE/build-dir
131+
132+
- name: Show logs on failure
133+
if: failure() || cancelled()
134+
run: |
135+
cat build/reports/*.txt

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ build:
2424
./java.sh $(INSTALL_DIR)
2525
ant
2626

27+
# Enable all WOLFSSL_PR*_PATCH_APPLIED defines when building JNI.
28+
# Requires latest/recent wolfssl source with patches applied. This is not
29+
# detected automatically.
30+
all-patched:
31+
@defines="$$(./scripts/find-wolfssl-pr-patch-defines.sh)"; \
32+
if [ -z "$$defines" ]; then \
33+
echo "warning: no WOLFSSL_PR*_PATCH_APPLIED defines found; skipping all-patched"; \
34+
exit 0; \
35+
fi; \
36+
cflags=""; \
37+
for define in $$defines; do \
38+
cflags="$$cflags -D$$define"; \
39+
done; \
40+
CFLAGS="$$cflags" ./java.sh $(INSTALL_DIR); \
41+
ant
42+
2743
install:
2844
$(INSTALL) -d $(INSTALL_DIR)/$(LIBDIR)
2945
$(INSTALL) lib/libwolfssljni.so $(INSTALL_DIR)/$(LIBDIR)
@@ -52,3 +68,6 @@ rpm: dist
5268
rpmbuild -ba --clean rpm/spec
5369
@cp ~/rpmbuild/RPMS/*/$(NAME)-$(VERSION)*.rpm .
5470
@cp ~/rpmbuild/SRPMS/$(NAME)-$(VERSION)*.rpm .
71+
72+
clean:
73+
ant clean cleanjni

java.sh

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,34 @@
2929
#
3030
# java.sh /usr/local wolfssljsse
3131

32+
# Fail on any errors
33+
set -euo pipefail
34+
3235
OS=`uname`
3336
ARCH=`uname -m`
3437

35-
if [ -z "$1" ]; then
38+
if [ -z "${1-}" ]; then
3639
# default install location is /usr/local
3740
WOLFSSL_INSTALL_DIR="/usr/local"
3841
else
3942
# use custom wolfSSL install location
4043
# should match directory set at wolfSSL ./configure --prefix=<DIR>
41-
WOLFSSL_INSTALL_DIR=$1
44+
WOLFSSL_INSTALL_DIR="$1"
4245
fi
4346

44-
if [ -z "$2" ]; then
47+
if [ -z "${2-}" ]; then
4548
# default wolfSSL library name is libwolfssl
4649
WOLFSSL_LIBNAME="wolfssl"
4750
else
4851
# use custom wolfSSL library name
4952
# should match wolfsslSUFFIX as set using ./configure --with-libsuffix
50-
WOLFSSL_LIBNAME=$2
53+
WOLFSSL_LIBNAME="$2"
5154
fi
5255

5356
echo "Compiling Native JNI library:"
5457
echo " WOLFSSL_INSTALL_DIR = $WOLFSSL_INSTALL_DIR"
5558

56-
if [ -z "$JAVA_HOME" ]; then
59+
if [ -z "${JAVA_HOME:-}" ]; then
5760
# if JAVA_HOME not set, detect based on platform/OS
5861
echo " JAVA_HOME empty, trying to detect"
5962
else
@@ -62,11 +65,14 @@ else
6265
javaHome="$JAVA_HOME"
6366
fi
6467

68+
fpic=""
69+
CFLAGS="${CFLAGS:-}"
70+
6571
# set up Java include and library paths for OS X and Linux
6672
# NOTE: you may need to modify these if your platform uses different locations
6773
if [ "$OS" == "Darwin" ] ; then
6874
echo " Detected Darwin/OSX host OS"
69-
if [ -z $javaHome ]; then
75+
if [ -z "${javaHome:-}" ]; then
7076
# this is broken since Big Sur, set JAVA_HOME environment var instead
7177
# OSX JAVA_HOME is typically similar to:
7278
# /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
@@ -77,7 +83,7 @@ if [ "$OS" == "Darwin" ] ; then
7783
jniLibName="libwolfssljni.dylib"
7884
elif [ "$OS" == "Linux" ] ; then
7985
echo " Detected Linux host OS"
80-
if [ -z $javaHome ]; then
86+
if [ -z "${javaHome:-}" ]; then
8187
javaHome=`echo $(dirname $(dirname $(readlink -f $(which java))))`
8288
fi
8389
if [ ! -d "$javaHome/include" ]
@@ -89,8 +95,6 @@ elif [ "$OS" == "Linux" ] ; then
8995
jniLibName="libwolfssljni.so"
9096
if [ "$ARCH" == "x86_64" ] || [ "$ARCH" == "aarch64" ]; then
9197
fpic="-fPIC"
92-
else
93-
fpic=""
9498
fi
9599
else
96100
echo 'Unknown host OS!'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# This script searches the wolfssl repository for any defined
4+
# WOLFSSL_PR*_PATCH_APPLIED macros and lists them in sorted order.
5+
6+
set -euo pipefail
7+
8+
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
9+
10+
matches="$(grep -R -h -o -E 'WOLFSSL_PR[0-9]+_PATCH_APPLIED' \
11+
--exclude-dir=.git \
12+
--exclude-dir=build \
13+
"$repo_root" || true)"
14+
if [ -z "$matches" ]; then
15+
exit 0
16+
fi
17+
18+
printf "%s\n" "$matches" | sort -u

0 commit comments

Comments
 (0)