@@ -48,19 +48,32 @@ 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 :
6982    steps :
7083      - uses : actions/checkout@v4 
7184
85+       - name : Free disk space 
86+         if : runner.os == 'Linux' 
87+         uses : ./.github/actions/free-disk-space 
88+ 
7289      - name : Install Rust ${{ matrix.rust }} 
7390        if : matrix.rust != 'nightly' 
7491        uses : dtolnay/rust-toolchain@master 
@@ -85,65 +102,60 @@ jobs:
85102      - uses : Swatinem/rust-cache@v2 
86103
87104      - name : Check (default features, no system LLVM) 
105+         if : matrix.target.build-type == 'native' 
88106        run : cargo check 
89107
90108      - name : Build (default features, no system LLVM) 
109+         if : matrix.target.build-type == 'native' 
91110        run : cargo build 
92111
93112      - name : Install btfdump 
94-         if : matrix.rust == 'nightly' 
113+         if : matrix.rust == 'nightly' && matrix.target.build-type == 'native'  
95114        run : cargo install btfdump 
96115
116+       - name : Install icedragon 
117+         if : runner.os == 'Linux' 
118+         run : cargo install --git https://github.com/exein-io/icedragon --branch persistent-rustup 
119+ 
120+       - name : Install btfdump 
121+         if : matrix.rust == 'nightly' && matrix.target.build-type == 'cross' 
122+         run : icedragon cargo -- install btfdump 
123+ 
97124      - name : Install prerequisites 
98-         if : matrix.rust == 'nightly' 
125+         if : matrix.rust == 'nightly' && runner.os == 'Linux' && startsWith(matrix.target.target, 'x86_64')  
99126        #  ubuntu-22.04 comes with clang 13-15[0]; support for signed and 64bit
100127        #  enum values was added in clang 15[1] which isn't in `$PATH`.
101128        # 
102129        #  gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
103130        # 
131+         #  libelf is a dependency of libbpf.
132+         # 
104133        #  [0] https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
105134        # 
106135        #  [1] https://github.com/llvm/llvm-project/commit/dc1c43d
107136        run : | 
108137          set -euxo pipefail 
109138          sudo apt update 
110-           sudo apt -y install gcc-multilib 
139+           sudo apt -y install gcc-multilib libelf-dev  
111140          echo /usr/lib/llvm-15/bin >> $GITHUB_PATH 
112141
113- name : Install LLVM 
114-         if : matrix.llvm != 'source' 
142+ name : Install prerequisites 
143+         if : runner.os == 'macOS' 
144+         #  We need system-wide LLVM only for FileCheck.
115145        run : | 
116146          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 
147+           brew install llvm 
148+           echo $(brew --prefix)/opt/llvm/bin >> $GITHUB_PATH 
136149
137150name : Restore LLVM 
138-         if : matrix.llvm == 'source' 
139151        uses : actions/cache/restore@v4 
140152        with :
141153          path : llvm-install 
142-           key : ${{ needs.llvm.outputs. cache-key }} 
154+           key : ${{ needs.llvm.outputs[format(' cache-key-{0}', matrix.target.target)]  }} 
143155          fail-on-cache-miss : true 
144156
145157      - name : Add LLVM to PATH && LD_LIBRARY_PATH 
146-         if : matrix.llvm  == 'source ' 
158+         if : matrix.target.build-type  == 'native ' 
147159        run : | 
148160          set -euxo pipefail 
149161          echo "${{ github.workspace }}/llvm-install/bin" >> $GITHUB_PATH 
@@ -160,17 +172,63 @@ jobs:
160172          cargo clean -p llvm-sys --release 
161173
162174uses : taiki-e/install-action@cargo-hack 
175+         if : matrix.target.build-type == 'native' 
176+ 
177+       #  Run cargo commands with `cargo hack` for native targets.
178+       #  Run cargo commands with `icedragon cargo` for cross targets. Running
179+       #  `cargo hack` wouldn't work, because cross builds need a custom LLVM
180+       #  build and can't use the rustc proxy, therefore `--feature-powerset`
181+       #  won't work.
163182
164183      - name : Check 
184+         if : matrix.target.build-type == 'native' 
165185        run : cargo hack check --feature-powerset 
166186
187+       - name : Check 
188+         if : matrix.target.build-type == 'cross' 
189+         env :
190+           BPF_LINKER_LLVM_PREFIX : " /llvm-install" 
191+         run : | 
192+           icedragon cargo \ 
193+             --target ${{ matrix.target.target }} \ 
194+             --volume "${{ github.workspace }}/llvm-install:/llvm-install" \ 
195+             -- \ 
196+             check \ 
197+             --no-default-features --features llvm-sys/no-llvm-linking 
198+ 
167199name : Build 
200+         if : matrix.target.build-type == 'native' 
168201        run : cargo hack build --feature-powerset 
169202
203+       - name : Build 
204+         if : matrix.target.build-type == 'cross' 
205+         env :
206+           BPF_LINKER_LLVM_PREFIX : " /llvm-install" 
207+         run : | 
208+           icedragon cargo \ 
209+             --target ${{ matrix.target.target }} \ 
210+             --volume "${{ github.workspace }}/llvm-install:/llvm-install" \ 
211+             -- \ 
212+             build \ 
213+             --no-default-features --features llvm-sys/no-llvm-linking 
214+ 
170215name : Test 
171-         if : matrix.rust == 'nightly' 
216+         if : matrix.rust == 'nightly' && matrix.target.build-type == 'native'  
172217        run : cargo hack test --feature-powerset 
173218
219+       - name : Test 
220+         #  We can run tests only for the x86_64-unknown-linux-musl cross target.
221+         if : matrix.rust == 'nightly' && matrix.target.build-type == 'cross' && startsWith(matrix.target.target, 'x86_64') 
222+         env :
223+           BPF_LINKER_LLVM_PREFIX : " /llvm-install" 
224+         run : | 
225+           icedragon cargo \ 
226+             --target ${{ matrix.target.target }} \ 
227+             --volume "${{ github.workspace }}/llvm-install:/llvm-install" \ 
228+             -- \ 
229+             test \ 
230+             --no-default-features --features llvm-sys/no-llvm-linking 
231+ 
174232uses : actions/checkout@v4 
175233        if : matrix.rust == 'nightly' 
176234        with :
@@ -179,10 +237,28 @@ jobs:
179237          submodules : recursive 
180238
181239      - name : Install 
182-         if : matrix.rust == 'nightly' 
183-         run : cargo install --path . --no-default-features 
240+         if : matrix.rust == 'nightly' && runner.os == 'Linux' && matrix.target.build-type == 'native' && startsWith(matrix.target.target, 'x86_64') 
241+         run : | 
242+           cargo install 
243+ 
244+ name : Install 
245+         if : matrix.rust == 'nightly' && runner.os == 'Linux' && matrix.target.build-type == 'cross' && startsWith(matrix.target.target, 'x86_64') 
246+         env :
247+           BPF_LINKER_LLVM_PREFIX : " /llvm-install" 
248+         run : | 
249+           icedragon cargo \ 
250+             --target ${{ matrix.target.target }} \ 
251+             --volume "${{ github.workspace }}/llvm-install:/llvm-install" \ 
252+             --volume ~/cargo:/install \ 
253+             -- \ 
254+             install --path . --root /install \ 
255+             --no-default-features --features llvm-sys/no-llvm-linking 
184256
185257name : Run aya integration tests 
186-         if : matrix.rust == 'nightly' 
258+         if : matrix.rust == 'nightly' && runner.os == 'Linux' && startsWith(matrix.target.target, 'x86_64')  
187259        working-directory : aya 
188260        run : cargo xtask integration-test local 
261+ 
262+       - name : Setup tmate session 
263+         if : ${{ failure() }} 
264+         uses : mxschmitt/action-tmate@v3 
0 commit comments