-
Notifications
You must be signed in to change notification settings - Fork 47
195 lines (169 loc) · 5.78 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
name: CI
on:
pull_request:
push:
jobs:
test-gnu:
# dynamically linked glibc
name: Test on Ubuntu ${{ matrix.os-arch }} (${{ matrix.args }})
strategy:
matrix:
include:
- rust-target: x86_64-unknown-linux-gnu
os-target: x86_64-linux-gnu
os-arch: amd64
args: ''
- rust-target: x86_64-unknown-linux-gnu
os-target: x86_64-linux-gnu
os-arch: amd64
args: --no-default-features
install-sys-libbpf: y
- rust-target: aarch64-unknown-linux-gnu
os-target: aarch64-linux-gnu
os-arch: arm64
args: ''
- rust-target: powerpc64le-unknown-linux-gnu
os-target: powerpc64le-linux-gnu
os-arch: ppc64el
args: ''
runs-on: ubuntu-latest
env:
CARGO_BUILD_TARGET: ${{ matrix.rust-target }}
CARGO_TERM_VERBOSE: 'true'
RUSTFLAGS: -C linker=/usr/bin/${{ matrix.os-target }}-gcc
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- 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
shell: sudo sh -e {0}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install \
build-essential \
libelf-dev:${{ matrix.os-arch }} \
zlib1g-dev:${{ matrix.os-arch }}
- name: Install libbpf-dev
if: matrix.install-sys-libbpf == 'y'
run: sudo apt-get install libbpf-dev:${{ matrix.os-arch }}
- name: Install linker for ${{ matrix.os-target }}
if: matrix.os-arch != 'amd64'
run: sudo apt-get install gcc-${{ matrix.os-target }}
- name: Install Rust stable for ${{ matrix.rust-target }}
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.rust-target }}
- run: cargo build ${{ matrix.args }}
- run: cargo test ${{ matrix.args }}
if: matrix.os-arch == 'amd64'
test-musl:
# dynamically linked musl libc
name: Test on Alpine Linux x86_64 (${{ matrix.args }})
runs-on: ubuntu-latest
strategy:
matrix:
include:
- args: ''
- args: --no-default-features
install-sys-libbpf: y
env:
CARGO_TERM_VERBOSE: 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Alpine Linux with dependencies
uses: jirutka/setup-alpine@v1
with:
branch: latest-stable
packages: >
build-base
cargo
elfutils-dev
linux-headers
zlib-dev
- name: Install libbpf-dev
if: matrix.install-sys-libbpf == 'y'
run: apk add libbpf-dev
shell: alpine.sh --root {0}
- run: cargo build ${{ matrix.args }}
shell: alpine.sh {0}
- run: cargo test ${{ matrix.args }}
shell: alpine.sh {0}
test-libbpf-rs:
# check that libbpf-rs, one of the main consumers of the library, works with
# this version of libbpf-sys
name: Test libbpf-rs integration
runs-on: ubuntu-latest
env:
CARGO_TERM_VERBOSE: 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install \
build-essential \
libelf-dev \
zlib1g-dev
- name: Build libbpf-rs with libbpf-sys
run: |
cargo init --bin libbpf-rs-test-project
cd libbpf-rs-test-project
# Add the most recent *published* version of libbpf-rs (as opposed to,
# say, cloning a development snapshot, which would just introduce
# additional uncertainty into the process).
cargo add libbpf-rs
# Override libbpf-sys in use with our current one.
cat >> Cargo.toml <<EOF
[patch.crates-io]
libbpf-sys = { path = '..' }
EOF
cargo build
publish:
name: Publish to crates.io
if: github.ref == 'refs/heads/master' && github.ref_type == 'tag'
needs:
- test-gnu
- test-musl
- test-libbpf-rs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.rust-target }}
# This is needed for cargo-pkgid.
- name: Fetch dependencies and generate Cargo.lock
run: cargo fetch
- name: Resolve crate version and check git tag name
run: |
crate_version="$(cargo pkgid | cut -d '#' -f2 | grep -o '[^:]*$')"
git_tag=${GITHUB_REF#refs/tags/}
if [ "$git_tag" != "$crate_version" ]; then
printf '::error::%s\n' "Crate version ($crate_version) does not match git tag ($git_tag)"
exit 1
fi
- name: Publish to crates.io
# no-verify is to skip building; it has been already verified in the test-* jobs.
run: cargo publish --no-verify --verbose
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}