@@ -48,27 +48,45 @@ jobs:
4848 run : cargo fmt --all -- --check
4949
5050 build :
51- # We don't use ubuntu-latest because we care about the apt packages available.
52- runs-on : ubuntu-22.04
51+ runs-on : ${{ matrix.target.os }}
5352 strategy :
5453 fail-fast : false
5554 matrix :
5655 rust :
5756 - stable
5857 - beta
5958 - nightly
60- llvm :
61- - 20
62- - source
63- name : rustc=${{ matrix.rust }} llvm=${{ matrix.llvm }}
59+ # We don't use ubuntu-latest because we care about the apt packages available.
60+ target :
61+ - os : macos-14
62+ target : aarch64-apple-darwin
63+ build-type : native
64+ - os : macos-13
65+ target : x86_64-apple-darwin
66+ build-type : native
67+ - os : ubuntu-22.04
68+ target : aarch64-unknown-linux-musl
69+ build-type : cross
70+ - os : ubuntu-22.04
71+ target : x86_64-unknown-linux-gnu
72+ build-type : native
73+ - os : ubuntu-22.04
74+ target : x86_64-unknown-linux-musl
75+ build-type : cross
76+ name : rustc=${{ matrix.rust }} target=${{ matrix.target.target }}
6477 needs : llvm
6578
6679 env :
6780 RUST_BACKTRACE : full
81+ RUSTUP_TOOLCHAIN : ${{ matrix.rust }}
6882
6983 steps :
7084 - uses : actions/checkout@v4
7185
86+ - name : Free disk space
87+ if : runner.os == 'Linux'
88+ uses : ./.github/actions/free-disk-space
89+
7290 - name : Install Rust ${{ matrix.rust }}
7391 if : matrix.rust != 'nightly'
7492 uses : dtolnay/rust-toolchain@master
@@ -85,65 +103,60 @@ jobs:
85103 - uses : Swatinem/rust-cache@v2
86104
87105 - name : Check (default features, no system LLVM)
106+ if : matrix.target.build-type == 'native'
88107 run : cargo check
89108
90109 - name : Build (default features, no system LLVM)
110+ if : matrix.target.build-type == 'native'
91111 run : cargo build
92112
93113 - name : Install btfdump
94- if : matrix.rust == 'nightly'
114+ if : matrix.rust == 'nightly' && matrix.target.build-type == 'native'
95115 run : cargo install btfdump
96116
117+ - name : Install icedragon
118+ if : runner.os == 'Linux'
119+ run : cargo install --git https://github.com/exein-io/icedragon --branch persistent-rustup
120+
121+ - name : Install btfdump
122+ if : matrix.rust == 'nightly' && matrix.target.build-type == 'cross'
123+ run : icedragon cargo -- install btfdump
124+
97125 - name : Install prerequisites
98- if : matrix.rust == 'nightly'
126+ if : matrix.rust == 'nightly' && runner.os == 'Linux' && startsWith(matrix.target.target, 'x86_64')
99127 # ubuntu-22.04 comes with clang 13-15[0]; support for signed and 64bit
100128 # enum values was added in clang 15[1] which isn't in `$PATH`.
101129 #
102130 # gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
103131 #
132+ # libelf is a dependency of libbpf.
133+ #
104134 # [0] https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
105135 #
106136 # [1] https://github.com/llvm/llvm-project/commit/dc1c43d
107137 run : |
108138 set -euxo pipefail
109139 sudo apt update
110- sudo apt -y install gcc-multilib
140+ sudo apt -y install gcc-multilib libelf-dev
111141 echo /usr/lib/llvm-15/bin >> $GITHUB_PATH
112142
113- - name : Install LLVM
114- if : matrix.llvm != 'source'
143+ - name : Install prerequisites
144+ if : runner.os == 'macOS'
145+ # We need system-wide LLVM only for FileCheck.
115146 run : |
116147 set -euxo pipefail
117- wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
118- echo -e deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-${{ matrix.llvm }} main | sudo tee /etc/apt/sources.list.d/llvm.list
119-
120- sudo apt update
121- # TODO(vadorovsky): Remove the requirement of libpolly.
122- #
123- # Packages from apt.llvm.org are being built all at once, with one
124- # cmake build with superset of options, then different binaries and
125- # libraries are being included in different packages.
126- #
127- # That results in `llvm-config --libname --link-static` mentioning
128- # libpolly, even if it's not installed. The output of that command is
129- # being used in build.rs of llvm-sys, so building llvm-sys on such
130- # system is complaining about lack of libpolly.
131- #
132- # Hopefully that nightmare goes away once we switch to binstalls and
133- # ditch the system LLVM option.
134- sudo apt -y install llvm-${{ matrix.llvm }}-dev libpolly-${{ matrix.llvm }}-dev
135- echo /usr/lib/llvm-${{ matrix.llvm }}/bin >> $GITHUB_PATH
148+ brew install llvm
149+ echo $(brew --prefix)/opt/llvm/bin >> $GITHUB_PATH
136150
137151 - name : Restore LLVM
138- if : matrix.llvm == 'source'
139152 uses : actions/cache/restore@v4
140153 with :
141154 path : llvm-install
142- key : ${{ needs.llvm.outputs. cache-key }}
155+ key : ${{ needs.llvm.outputs[format(' cache-key-{0}', matrix.target.target)] }}
143156 fail-on-cache-miss : true
144157
145158 - name : Add LLVM to PATH && LD_LIBRARY_PATH
146- if : matrix.llvm == 'source '
159+ if : matrix.target.build-type == 'native '
147160 run : |
148161 set -euxo pipefail
149162 echo "${{ github.workspace }}/llvm-install/bin" >> $GITHUB_PATH
@@ -160,17 +173,63 @@ jobs:
160173 cargo clean -p llvm-sys --release
161174
162175 - uses : taiki-e/install-action@cargo-hack
176+ if : matrix.target.build-type == 'native'
177+
178+ # Run cargo commands with `cargo hack` for native targets.
179+ # Run cargo commands with `icedragon cargo` for cross targets. Running
180+ # `cargo hack` wouldn't work, because cross builds need a custom LLVM
181+ # build and can't use the rustc proxy, therefore `--feature-powerset`
182+ # won't work.
163183
164184 - name : Check
185+ if : matrix.target.build-type == 'native'
165186 run : cargo hack check --feature-powerset
166187
188+ - name : Check
189+ if : matrix.target.build-type == 'cross'
190+ env :
191+ BPF_LINKER_LLVM_PREFIX : " /llvm-install"
192+ run : |
193+ icedragon cargo \
194+ --target ${{ matrix.target.target }} \
195+ --volume "${{ github.workspace }}/llvm-install:/llvm-install" \
196+ -- \
197+ check \
198+ --no-default-features --features llvm-sys/no-llvm-linking
199+
167200 - name : Build
201+ if : matrix.target.build-type == 'native'
168202 run : cargo hack build --feature-powerset
169203
204+ - name : Build
205+ if : matrix.target.build-type == 'cross'
206+ env :
207+ BPF_LINKER_LLVM_PREFIX : " /llvm-install"
208+ run : |
209+ icedragon cargo \
210+ --target ${{ matrix.target.target }} \
211+ --volume "${{ github.workspace }}/llvm-install:/llvm-install" \
212+ -- \
213+ build \
214+ --no-default-features --features llvm-sys/no-llvm-linking
215+
170216 - name : Test
171- if : matrix.rust == 'nightly'
217+ if : matrix.rust == 'nightly' && matrix.target.build-type == 'native'
172218 run : cargo hack test --feature-powerset
173219
220+ - name : Test
221+ # We can run tests only for the x86_64-unknown-linux-musl cross target.
222+ if : matrix.rust == 'nightly' && matrix.target.build-type == 'cross' && startsWith(matrix.target.target, 'x86_64')
223+ env :
224+ BPF_LINKER_LLVM_PREFIX : " /llvm-install"
225+ run : |
226+ icedragon cargo \
227+ --target ${{ matrix.target.target }} \
228+ --volume "${{ github.workspace }}/llvm-install:/llvm-install" \
229+ -- \
230+ test \
231+ --no-default-features --features llvm-sys/no-llvm-linking
232+
174233 - uses : actions/checkout@v4
175234 if : matrix.rust == 'nightly'
176235 with :
@@ -179,10 +238,24 @@ jobs:
179238 submodules : recursive
180239
181240 - name : Install
182- if : matrix.rust == 'nightly'
183- run : cargo install --path . --no-default-features
241+ if : matrix.rust == 'nightly' && runner.os == 'Linux' && matrix.target.build-type == 'native' && startsWith(matrix.target.target, 'x86_64')
242+ run : |
243+ cargo install --path .
244+
245+ - name : Install
246+ if : matrix.rust == 'nightly' && runner.os == 'Linux' && matrix.target.build-type == 'cross' && startsWith(matrix.target.target, 'x86_64')
247+ env :
248+ BPF_LINKER_LLVM_PREFIX : " /llvm-install"
249+ run : |
250+ icedragon cargo \
251+ --target ${{ matrix.target.target }} \
252+ --volume "${{ github.workspace }}/llvm-install:/llvm-install" \
253+ --volume ~/.cargo:/install \
254+ -- \
255+ install --path . --root /install \
256+ --no-default-features --features llvm-sys/no-llvm-linking
184257
185258 - name : Run aya integration tests
186- if : matrix.rust == 'nightly'
259+ if : matrix.rust == 'nightly' && runner.os == 'Linux' && startsWith(matrix.target.target, 'x86_64')
187260 working-directory : aya
188261 run : cargo xtask integration-test local
0 commit comments