-
-
Notifications
You must be signed in to change notification settings - Fork 0
346 lines (297 loc) · 10.6 KB
/
ci.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
name: CI
on:
- push
- pull_request
env:
ALPINE_BRANCH: v3.16
CRATE_NAME: connman-resolvconf
BIN_NAME: connman-resolvconfd
jobs:
check:
name: Run linters
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust stable
uses: actions-rs/toolchain@v1
with:
override: true
profile: minimal
toolchain: stable
components: rustfmt, clippy
- name: Install libdbus-1-dev
run: sudo apt-get install libdbus-1-dev
- name: Run clippy linter
run: cargo clippy
- name: Run rustfmt check (ignore any errors)
run: cargo fmt -- --check || true
- name: Resolve crate version and check git tag name
if: startsWith(github.ref, 'refs/tags/v')
run: |
crate_version="$(cargo pkgid | cut -d '#' -f2 | grep -o '[^:]*$')"
git_tag=${GITHUB_REF#refs/tags/}
if [ "$git_tag" != "v$crate_version" ]; then
printf '::error::%s\n' "Crate version ($crate_version) does not match git tag ($git_tag)"
exit 1
fi
build-multi-glibc:
name: Build for ${{ matrix.rust-target }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- rust-target: x86_64-unknown-linux-gnu
os-target: x86_64-linux-gnu
os-arch: amd64
- rust-target: aarch64-unknown-linux-gnu
os-target: aarch64-linux-gnu
os-arch: arm64
- rust-target: armv7-unknown-linux-gnueabihf
os-target: arm-linux-gnueabihf
os-arch: armhf
- rust-target: powerpc64le-unknown-linux-gnu
os-target: powerpc64le-linux-gnu
os-arch: ppc64el
env:
TARGET_DIR: target/${{ matrix.rust-target }}/release
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust stable for ${{ matrix.rust-target }}
uses: actions-rs/toolchain@v1
with:
override: true
profile: minimal
target: ${{ matrix.rust-target }}
toolchain: stable
- name: Add apt sources for ${{ matrix.os-arch }}
if: matrix.os-arch != 'amd64'
run: |
dpkg --add-architecture ${{ matrix.os-arch }}
release=$(. /etc/os-release && echo "$UBUNTU_CODENAME")
sed -i 's/^deb /deb [arch=amd64] /' /etc/apt/sources.list
printf 'deb [arch=${{ matrix.os-arch }}] http://ports.ubuntu.com/ %s main restricted\n' \
$release $release-updates $release-security \
>> /etc/apt/sources.list
apt-get update
shell: sudo sh -e {0}
- name: Install linker for ${{ matrix.os-target }}
if: matrix.os-arch != 'amd64'
run: sudo apt-get install gcc-${{ matrix.os-target }}
- name: Install libdbus-1-dev
run: sudo apt-get install libdbus-1-dev:${{ matrix.os-arch }}
- name: Build binary
env:
CARGO_BUILD_TARGET: ${{ matrix.rust-target }}
CARGO_PROFILE_RELEASE_STRIP: symbols
PKG_CONFIG_SYSROOT_DIR: /usr/lib/${{ matrix.os-target }}
PKG_CONFIG_LIBDIR: /usr/lib/${{ matrix.os-target }}/pkgconfig
RUSTFLAGS: -C linker=/usr/bin/${{ matrix.os-target }}-gcc
run: cargo build --release --locked
- name: Inspect binary
run: |
ls -l $BIN_NAME
file $BIN_NAME
readelf -hd $BIN_NAME
working-directory: ${{ env.TARGET_DIR }}
- if: matrix.os-arch == 'amd64'
run: ./${{ env.BIN_NAME }} --version
working-directory: ${{ env.TARGET_DIR }}
- name: Upload binary to artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.rust-target }}
path: ${{ env.TARGET_DIR }}/${{ env.BIN_NAME }}
if-no-files-found: error
build-x86_64-musl:
name: Build for ${{ matrix.rust-target }} (statically linked)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- rust-target: x86_64-unknown-linux-musl
env:
TARGET_DIR: target/release
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Alpine Linux with dependencies
uses: jirutka/setup-alpine@v1
with:
branch: ${{ env.ALPINE_BRANCH }}
packages: >
build-base
rustup
dbus-dev
dbus-static
# We cannot build with Alpine's rust due to https://gitlab.alpinelinux.org/alpine/aports/-/issues/12941.
- name: Install Rust stable toolchain via rustup
run: rustup-init --target ${{ matrix.rust-target }} --default-toolchain stable --profile minimal -y
shell: alpine.sh {0}
- name: Build binary
env:
CARGO_PROFILE_RELEASE_STRIP: symbols
PKG_CONFIG_ALL_STATIC: '1'
SYSROOT: /dummy # workaround for https://github.com/rust-lang/pkg-config-rs/issues/102
run: cargo build --release --locked
shell: alpine.sh {0}
- name: Inspect binary
run: |
ls -l $BIN_NAME
file $BIN_NAME
readelf -hd $BIN_NAME
working-directory: ${{ env.TARGET_DIR }}
shell: alpine.sh {0}
- run: ./${{ env.BIN_NAME }} --version
working-directory: ${{ env.TARGET_DIR }}
shell: alpine.sh {0}
- name: Upload binary to artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.rust-target }}
path: ${{ env.TARGET_DIR }}/${{ env.BIN_NAME }}
if-no-files-found: error
build-x86_64-alpine-musl:
name: Build x86_64-alpine-linux-musl (dynamically linked)
runs-on: ubuntu-latest
env:
TARGET_DIR: target/release
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Alpine Linux
uses: jirutka/setup-alpine@v1
with:
packages: build-base cargo dbus-dev
- name: Build binary
run: |
cargo build --release --locked
strip $TARGET_DIR/$BIN_NAME
shell: alpine.sh {0}
- name: Inspect binary
run: |
ls -l $BIN_NAME
file $BIN_NAME
readelf -hd $BIN_NAME
working-directory: ${{ env.TARGET_DIR }}
shell: alpine.sh {0}
- run: ./${{ env.BIN_NAME }} --version
working-directory: ${{ env.TARGET_DIR }}
shell: alpine.sh {0}
build-cross-musl:
name: Build for ${{ matrix.rust-target }} (statically linked)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- rust-target: aarch64-unknown-linux-musl
os-arch: aarch64
# FIXME: undefined symbol __fstat_time64, __clock_gettime64 etc.
#- rust-target: armv7-unknown-linux-musleabihf
# os-arch: armv7
env:
TARGET_DIR: target/${{ matrix.rust-target }}/release
CROSS_SYSROOT: /mnt/alpine-${{ matrix.os-arch }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Alpine Linux for ${{ matrix.os-arch }} (target arch)
id: alpine-target
uses: jirutka/setup-alpine@v1
with:
shell-name: alpine-target.sh
arch: ${{ matrix.os-arch }}
branch: ${{ env.ALPINE_BRANCH }}
packages: >
dbus-dev
dbus-static
- name: Install Alpine Linux for x86_64 (build arch)
uses: jirutka/setup-alpine@v1
with:
shell-name: alpine.sh
arch: x86_64
branch: ${{ env.ALPINE_BRANCH }}
packages: >
build-base
pkgconf
lld
rustup
volumes: ${{ steps.alpine-target.outputs.root-path }}:${{ env.CROSS_SYSROOT }}
- name: Install Rust stable toolchain via rustup
run: rustup-init --target ${{ matrix.rust-target }} --default-toolchain stable --profile minimal -y
shell: alpine.sh {0}
- name: Build binary
env:
CARGO_BUILD_TARGET: ${{ matrix.rust-target }}
CARGO_PROFILE_RELEASE_STRIP: symbols
PKG_CONFIG_ALL_STATIC: '1'
PKG_CONFIG_LIBDIR: ${{ env.CROSS_SYSROOT }}/usr/lib/pkgconfig
RUSTFLAGS: -C linker=/usr/bin/ld.lld
SYSROOT: /dummy # workaround for https://github.com/rust-lang/pkg-config-rs/issues/102
run: |
# Workaround for https://github.com/rust-lang/pkg-config-rs/issues/102.
echo -e '#!/bin/sh\nPKG_CONFIG_SYSROOT_DIR=${{ env.CROSS_SYSROOT }} exec pkgconf "$@"' \
| install -m755 /dev/stdin pkg-config
export PKG_CONFIG="$(pwd)/pkg-config"
cargo build --release --locked --verbose
shell: alpine.sh {0}
- name: Inspect binary
run: |
ls -l $BIN_NAME
file $BIN_NAME
readelf -hd $BIN_NAME
working-directory: ${{ env.TARGET_DIR }}
shell: alpine.sh {0}
- name: connman-resolvconfd --version
run: ./$BIN_NAME --version
working-directory: ${{ env.TARGET_DIR }}
shell: alpine-target.sh {0}
- name: Upload binary to artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.rust-target }}
path: ${{ env.TARGET_DIR }}/${{ env.BIN_NAME }}
if-no-files-found: error
publish:
name: Publish binaries to Releases
if: ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name != 'pull_request' }}
needs:
- build-multi-glibc
- build-x86_64-musl
- build-cross-musl
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download binaries from artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Create tarballs
run: |
version=${GITHUB_REF#refs/tags/v}
cd artifacts
for target in *; do
tarname=${CRATE_NAME}-${version}-${target/-unknown/}
tarname=${tarname%-musl}
install -D -m755 $target/$BIN_NAME -t "$tarname"/
install -m644 ../LICENSE -t "$tarname"/
tar -czf "$tarname.tar.gz" "$tarname"
ls -la "$tarname.tar.gz"
done
- name: Generate checksums.txt
run: shasum -a 256 *.tar.gz | tee checksums.txt
working-directory: artifacts
- name: Upload binaries to Releases
uses: softprops/action-gh-release@v1
with:
files: |
artifacts/*.tar.gz
artifacts/checksums.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}