-
Notifications
You must be signed in to change notification settings - Fork 143
169 lines (148 loc) · 5.13 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Build
on:
- push
- pull_request
jobs:
natives-linux-windows:
name: Linux (x86/ARM/PPC) and Windows native library compilation
runs-on: ubuntu-latest
container:
image: ubuntu:18.04
env:
GCC: gcc-8
defaults:
run:
working-directory: src/main/c
steps:
- name: Checkout the target branch
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
# Don't need the dependency cache here (or in any of the other native
# library compilation steps), because we're not invoking the Java
# compiler in this step. We only need the JDK for its headers.
- name: Install build prerequisites
run: |
apt-get update
apt-get --assume-yes install make $GCC
make crosstools
- name: Build the Linux and Windows native libraries
run: |
make clean-linux clean-windows
make linux windows
# The names of the artifacts containing native libraries correspond
# exactly to the directories inside `src/main/c/resources/native`. That
# way, the Java build job can pull down all artifacts and unpack them
# into that directory to overwrite the versions in-repo. This is sadly
# necessary because the actions/download-artifact@v3 action flattens
# paths inside artifacts. If it retained full relative paths, we could
# put Linux and Windows natives inside the same artifact, and we could be
# flexible with the artifact names. But it doesn't, so we can't, and we
# can't.
- name: Upload Linux native libraries
uses: actions/upload-artifact@v3
with:
name: linux
path: src/main/c/resources/native/linux
- name: Upload Windows native libraries
uses: actions/upload-artifact@v3
with:
name: windows
path: src/main/c/resources/native/windows
natives-macos:
name: macOS native library compilation
runs-on: macos-latest
defaults:
run:
working-directory: src/main/c
steps:
- name: Checkout the target branch
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
- name: Build the macOS native libraries
run: |
make clean-osx
make osx
- name: Upload macOS native libraries
uses: actions/upload-artifact@v3
with:
name: osx
path: src/main/c/resources/native/osx/libNRJavaSerial.jnilib
natives-freebsd:
name: FreeBSD native library compilation
runs-on: ubuntu-latest
container:
image: empterdose/freebsd-cross-build:11.4
defaults:
run:
working-directory: src/main/c
steps:
- name: Checkout the target branch
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
- name: Fake the FreeBSD Java headers
# This feels extremely dirty, but the only native header we care about
# is `jni_md.h`, and it is exactly identical between Linux and FreeBSD
# (at least in OpenJDK 8).
run: |
ln -s $JAVA_HOME/include/linux $JAVA_HOME/include/freebsd
- name: Build the FreeBSD native libraries
run: |
make clean-freebsd
settarget i386-freebsd11 make freebsd32
settarget x86_64-freebsd11 make freebsd64
settarget arm64-freebsd11 make freebsdarm64v8
- name: Upload FreeBSD native libraries
uses: actions/upload-artifact@v3
with:
name: freebsd
path: src/main/c/resources/native/freebsd
java:
name: Java compilation
runs-on: ubuntu-latest
needs:
- natives-linux-windows
- natives-macos
- natives-freebsd
steps:
# We use Spotless in “ratchet mode” to incrementally enforce code
# formatting throughout the project. In order to ensure feature branches
# don't regress formatting when compared with the master branch, we need
# to have a local copy of the master branch for comparison.
- name: Checkout the master branch
uses: actions/checkout@v3
with:
ref: master
- name: Checkout the target branch
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
cache: gradle
- name: Download native libraries
uses: actions/download-artifact@v3
with:
path: src/main/c/resources/native
- name: Build the Java library
run: ./gradlew build
- name: Determine commit hash for artifact filename
id: vars
run: echo "short-rev=$(git rev-parse --short HEAD)" >>$GITHUB_OUTPUT
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: nrjavaserial-${{steps.vars.outputs.short-rev}}
path: build/libs/*.jar