forked from scream3r/java-simple-serial-connector
-
Notifications
You must be signed in to change notification settings - Fork 54
198 lines (173 loc) · 7.37 KB
/
cross-compile.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Cross-compile native libraries
on: workflow_dispatch
env:
MAVEN_OPTS: -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
GITHUB_BOT_NAME: github-actions
GITHUB_BOT_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
jobs:
create-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: echo "precompiled_branch=$(git branch --show-current)-precompiled-natives" >> $GITHUB_ENV
- name: Create branch for precompiled natives
run: git checkout -b ${{ env.precompiled_branch }}
- name: Sync SerialNativeInterface version with the project pom version
run: |
FILE=src/main/java/jssc/SerialNativeInterface.java
RELEASE_VERSION=$(mvn validate help:evaluate -Dexpression=release.version -q -DforceStdout)
sed -i "s/private static final String libVersion =.*/private static final String libVersion = \"${RELEASE_VERSION}\";/" ${FILE}
if [ $(git ls-files --modified) ]; then
git config --global user.email "${GITHUB_BOT_EMAIL}"
git config --global user.name "${GITHUB_BOT_NAME}"
git commit ${FILE} --message "Update version in source files before building native libraries"
fi
- run: echo "rev=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- run: git push --force origin HEAD
outputs:
precompiled_branch: ${{ env.precompiled_branch }}
base_rev: ${{ env.rev }}
linux-windows:
runs-on: ubuntu-latest
needs: create-branch
strategy:
matrix:
include:
- target: linux_32
os_target_name: linux
os_target_arch: x86_32
os_target_bitness: 32
image: docker.io/dockcross/linux-x86
- target: linux_64
os_target_name: linux
os_target_arch: x86_64
os_target_bitness: 64
image: docker.io/dockcross/linux-x64
- target: linux_arm
os_target_name: linux
os_target_arch: arm_32
os_target_bitness: 32
image: docker.io/dockcross/linux-armv6-lts
- target: linux_arm64
os_target_name: linux
os_target_arch: aarch_64
os_target_bitness: 64
image: docker.io/dockcross/linux-arm64-lts
- target: linux_riscv32
os_target_name: linux
os_target_arch: riscv32
os_target_bitness: 32
image: docker.io/dockcross/linux-riscv32
- target: linux_riscv64
os_target_name: linux
os_target_arch: riscv64
os_target_bitness: 64
image: docker.io/dockcross/linux-riscv64
- target: linux_ppc
os_target_name: linux
os_target_arch: ppc_64
os_target_bitness: 64
image: docker.io/dockcross/linux-ppc64le
- target: windows_32
os_target_name: windows
os_target_arch: x86_32
os_target_bitness: 32
image: docker.io/dockcross/windows-static-x86
- target: windows_64
os_target_name: windows
os_target_arch: x86_64
os_target_bitness: 64
image: docker.io/dockcross/windows-static-x64
- target: windows_arm64
os_target_name: windows
os_target_arch: aarch_64
os_target_bitness: 64
image: docker.io/dockcross/windows-arm64
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Pull docker images
run: docker pull ${{ matrix.image }}
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- name: Build for ${{ matrix.target }} in ${{ matrix.image }}
run: |
docker run --rm --workdir=/work \
--volume $PWD:/work \
--volume $HOME/.m2:/root/.m2 \
--env MAVEN_OPTS=${MAVEN_OPTS} \
${{ matrix.image }} \
bash -c \
'apt-get update && apt-get install --yes maven openjdk-11-jdk-headless && \
mvn -B clean install -P dockcross,update-resources-precompiled \
-Dos.target.name=${{ matrix.os_target_name }} \
-Dos.target.arch=${{ matrix.os_target_arch }} \
-Dos.target.bitness=${{ matrix.os_target_bitness }} \
'
- name: Push recompiled binaries
run: |
git config --global user.email "${GITHUB_BOT_EMAIL}"
git config --global user.name "${GITHUB_BOT_NAME}"
git fetch && git checkout -t origin/${{ needs.create-branch.outputs.precompiled_branch }}
git add src/main/resources-precompiled/**
git commit --allow-empty -m "Precompiled natives (@${{ needs.create-branch.outputs.base_rev }}) for ${{ matrix.target }}"
while git pull --rebase && ! git push; do sleep 5; done
macos:
runs-on: macos-11
needs: create-branch
strategy:
matrix:
include:
- target: osx_64
profile: 'x86_64'
macos-deployment-target: 10.8
sdk-version: MacOSX10.9.sdk
- target: osx_arm64
profile: 'aarch64'
macos-deployment-target: 11.0
sdk-version: MacOSX11.0.sdk
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- name: Get oldest supported SDK
if: ${{ matrix.sdk-version == 'MacOSX10.9.sdk' }}
run: |
wget -qO- https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX10.9.sdk.tar.xz \
| tar -xjv -C $XCODE_12_DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs
- name: Set SDK version
run: |
export MACOSX_DEPLOYMENT_TARGET=${{ matrix.macos-deployment-target }}
export SDKROOT=$XCODE_12_DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/${{ matrix.sdk-version }}
export CMAKE_OSX_SYSROOT=$SDKROOT
- name: Build with Maven
run: mvn -B clean install -P ${{ matrix.profile }},update-resources-precompiled
- name: Push recompiled binaries
run: |
git config --global user.email "${GITHUB_BOT_EMAIL}"
git config --global user.name "${GITHUB_BOT_NAME}"
git fetch && git checkout -t origin/${{ needs.create-branch.outputs.precompiled_branch }}
git add src/main/resources-precompiled/**
git commit --allow-empty -m "Precompiled natives (@${{ needs.create-branch.outputs.base_rev }}) for ${{ matrix.target }}"
while git pull --rebase && ! git push; do sleep 5; done
single-commit:
runs-on: ubuntu-latest
needs: [create-branch, linux-windows, macos]
steps:
- uses: actions/checkout@v3
- name: Squash into one commit
run: |
git config --global user.email "${GITHUB_BOT_EMAIL}"
git config --global user.name "${GITHUB_BOT_NAME}"
git fetch && git checkout -t origin/${{ needs.create-branch.outputs.precompiled_branch }}
git reset --soft ${{ needs.create-branch.outputs.base_rev }}
git add src/main/resources-precompiled/**
git commit -m "Precompiled natives @${{ needs.create-branch.outputs.base_rev }}"
git push -f