ci.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. name: aya-ci
  2. on:
  3. push:
  4. pull_request:
  5. schedule:
  6. - cron: 00 4 * * *
  7. env:
  8. CARGO_TERM_COLOR: always
  9. jobs:
  10. lint:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - uses: actions/checkout@v5
  14. - uses: dtolnay/rust-toolchain@nightly
  15. with:
  16. components: clippy,miri,rustfmt,rust-src
  17. # Installed *after* nightly so it is the default.
  18. - uses: dtolnay/rust-toolchain@stable
  19. - uses: Swatinem/rust-cache@v2
  20. - uses: taiki-e/install-action@v2
  21. with:
  22. tool: cargo-hack,taplo-cli
  23. - run: git ls-files -- '*.c' '*.h' | xargs clang-format --dry-run --Werror
  24. - uses: DavidAnson/markdownlint-cli2-action@v20
  25. - run: taplo fmt --check
  26. - run: cargo +nightly fmt --all -- --check
  27. - run: ./clippy.sh
  28. # On the `aya-rs/aya` repository, regenerate the public API on a schedule.
  29. #
  30. # On all other events and repositories assert the public API is up to date.
  31. - run: cargo xtask public-api
  32. if: ${{ !(github.event_name == 'schedule' && github.repository == 'aya-rs/aya') }}
  33. - run: cargo xtask public-api --bless
  34. if: ${{ (github.event_name == 'schedule' && github.repository == 'aya-rs/aya') }}
  35. - uses: peter-evans/create-pull-request@v7
  36. if: ${{ (github.event_name == 'schedule' && github.repository == 'aya-rs/aya') }}
  37. with:
  38. # GitHub actions aren't allowed to trigger other actions to prevent
  39. # abuse; the canonical workaround is to use a sufficiently authorized
  40. # token.
  41. #
  42. # See https://github.com/peter-evans/create-pull-request/issues/48.
  43. token: ${{ secrets.CRABBY_GITHUB_TOKEN }}
  44. branch: create-pull-request/public-api
  45. commit-message: 'public-api: regenerate'
  46. title: 'public-api: regenerate'
  47. body: |
  48. **Automated changes**
  49. - name: Run miri
  50. run: |
  51. set -euxo pipefail
  52. cargo +nightly hack miri test --all-targets --feature-powerset \
  53. --exclude aya-ebpf \
  54. --exclude aya-ebpf-bindings \
  55. --exclude aya-log-ebpf \
  56. --exclude integration-ebpf \
  57. --exclude integration-test \
  58. --workspace
  59. build-test-aya:
  60. strategy:
  61. fail-fast: false
  62. matrix:
  63. arch:
  64. - aarch64-unknown-linux-gnu
  65. - armv7-unknown-linux-gnueabi
  66. - loongarch64-unknown-linux-gnu
  67. - powerpc64le-unknown-linux-gnu
  68. - riscv64gc-unknown-linux-gnu
  69. - s390x-unknown-linux-gnu
  70. - x86_64-unknown-linux-gnu
  71. runs-on: ubuntu-latest
  72. steps:
  73. - uses: actions/checkout@v5
  74. - uses: dtolnay/rust-toolchain@stable
  75. with:
  76. targets: ${{ matrix.arch }}
  77. - uses: Swatinem/rust-cache@v2
  78. - uses: taiki-e/install-action@cargo-hack
  79. # This is magic, it sets `$CARGO_BUILD_TARGET`.
  80. - uses: taiki-e/setup-cross-toolchain-action@v1
  81. with:
  82. target: ${{ matrix.arch }}
  83. - name: Build
  84. run: |
  85. set -euxo pipefail
  86. cargo hack build --all-targets --feature-powerset \
  87. --exclude aya-ebpf \
  88. --exclude aya-ebpf-bindings \
  89. --exclude aya-log-ebpf \
  90. --exclude integration-ebpf \
  91. --exclude xtask \
  92. --workspace
  93. - name: Test
  94. env:
  95. RUST_BACKTRACE: full
  96. run: |
  97. set -euxo pipefail
  98. cargo hack test --all-targets --feature-powerset \
  99. --exclude aya-ebpf \
  100. --exclude aya-ebpf-bindings \
  101. --exclude aya-log-ebpf \
  102. --exclude integration-ebpf \
  103. --exclude integration-test \
  104. --exclude xtask \
  105. --workspace
  106. - name: Doctests
  107. env:
  108. RUST_BACKTRACE: full
  109. run: |
  110. set -euxo pipefail
  111. cargo hack test --doc --feature-powerset \
  112. --exclude aya-ebpf \
  113. --exclude aya-ebpf-bindings \
  114. --exclude aya-log-ebpf \
  115. --exclude init \
  116. --exclude integration-ebpf \
  117. --exclude integration-test \
  118. --exclude xtask \
  119. --workspace
  120. build-test-aya-ebpf:
  121. runs-on: ubuntu-latest
  122. steps:
  123. - uses: actions/checkout@v5
  124. - uses: dtolnay/rust-toolchain@nightly
  125. with:
  126. components: rust-src
  127. # Installed *after* nightly so it is the default.
  128. - uses: dtolnay/rust-toolchain@stable
  129. - uses: Swatinem/rust-cache@v2
  130. - run: cargo install --git https://github.com/aya-rs/bpf-linker.git bpf-linker --features llvm-21
  131. - uses: taiki-e/install-action@cargo-hack
  132. - name: Build & test for all BPF architectures
  133. env:
  134. RUST_BACKTRACE: full
  135. run: |
  136. set -euo pipefail
  137. failures=()
  138. # NB: this hand-rolled shell script is used instead of a matrix
  139. # because the time spent doing useful work per target is about equal
  140. # to the overhead of setting up the job - so this saves a bunch of
  141. # machine time.
  142. for arch in aarch64 arm loongarch64 mips powerpc64 riscv64 s390x x86_64; do
  143. for target in bpfeb-unknown-none bpfel-unknown-none; do
  144. echo "::group::Build and test for $arch / $target"
  145. if ! (
  146. RUSTFLAGS="--cfg bpf_target_arch=\"$arch\"" cargo +nightly hack build \
  147. --target "$target" \
  148. -Z build-std=core \
  149. --package aya-ebpf \
  150. --package aya-log-ebpf \
  151. --feature-powerset
  152. cargo hack test \
  153. --doc \
  154. --package aya-ebpf \
  155. --package aya-log-ebpf \
  156. --feature-powerset
  157. ); then
  158. echo "FAILED: $arch / $target"
  159. failures+=("$arch/$target")
  160. fi
  161. echo "::endgroup::"
  162. done
  163. done
  164. if ((${#failures[@]})); then
  165. echo "::error::Some builds/tests failed:"
  166. printf ' %s\n' "${failures[@]}"
  167. exit 1
  168. fi
  169. run-integration-test:
  170. strategy:
  171. fail-fast: false
  172. matrix:
  173. include:
  174. - target: x86_64-apple-darwin
  175. # macos-15 is arm64[0] which doesn't support nested
  176. # virtualization[1].
  177. #
  178. # [0] https://github.com/actions/runner-images#available-images
  179. #
  180. # [1] https://docs.github.com/en/actions/reference/runners/github-hosted-runners#limitations-for-arm64-macos-runners
  181. os: macos-15-intel
  182. # We don't use ubuntu-latest because we care about the apt packages available.
  183. - target: x86_64-unknown-linux-gnu
  184. os: ubuntu-24.04
  185. - target: aarch64-unknown-linux-gnu
  186. os: ubuntu-24.04-arm
  187. runs-on: ${{ matrix.os }}
  188. steps:
  189. - uses: actions/checkout@v5
  190. with:
  191. submodules: recursive
  192. - name: Install prerequisites
  193. if: runner.os == 'Linux'
  194. run: |
  195. set -euxo pipefail
  196. sudo apt update
  197. sudo apt -y install \
  198. liblzma-dev \
  199. lynx \
  200. musl-tools \
  201. qemu-system-{arm,x86}
  202. - name: Install prerequisites
  203. if: runner.os == 'macOS'
  204. # The curl shipped on macOS doesn't contain
  205. # https://github.com/curl/curl/commit/85efbb92b8e6679705e122cee45ce76c56414a3e which is
  206. # needed for proper handling of `--etag-{compare,save}`.
  207. #
  208. # The tar shipped on macOS doesn't support --wildcards, so we need GNU tar.
  209. #
  210. # The clang shipped on macOS doesn't support BPF, so we need LLVM from brew.
  211. #
  212. # We need a musl C toolchain to compile our `test-distro` since some of
  213. # our dependencies have build scripts that compile C code (i.e xz2).
  214. # This is provided by `brew install filosottile/musl-cross/musl-cross`.
  215. run: |
  216. set -euxo pipefail
  217. # Dependencies are tracked in `Brewfile`.
  218. brew bundle
  219. echo $(brew --prefix curl)/bin >> $GITHUB_PATH
  220. echo $(brew --prefix llvm)/bin >> $GITHUB_PATH
  221. # https://github.com/actions/setup-python/issues/577
  222. find /usr/local/bin -type l -exec sh -c 'readlink -f "$1" \
  223. | grep -q ^/Library/Frameworks/Python.framework/Versions/' _ {} \; -exec rm -v {} \;
  224. - uses: dtolnay/rust-toolchain@nightly
  225. with:
  226. components: rust-src
  227. # Installed *after* nightly so it is the default.
  228. - uses: dtolnay/rust-toolchain@stable
  229. with:
  230. targets: aarch64-unknown-linux-musl,x86_64-unknown-linux-musl
  231. - uses: Swatinem/rust-cache@v2
  232. - name: Install libLLVM
  233. # Download libLLVM from Rust CI to ensure that the libLLVM version
  234. # matches exactly with the version used by the current Rust nightly. A
  235. # mismatch between libLLVM (used by bpf-linker) and Rust's LLVM version
  236. # can lead to linking issues.
  237. run: |
  238. set -euxo pipefail
  239. # Get the partial SHA from Rust nightly.
  240. rustc_sha=$(rustc +nightly --version | grep -oE '[a-f0-9]{7,40}')
  241. # Get the full SHA from GitHub.
  242. rustc_sha=$(curl -sfSL https://api.github.com/repos/rust-lang/rust/commits/$rustc_sha \
  243. --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
  244. --header 'content-type: application/json' \
  245. | jq -r '.sha')
  246. mkdir -p /tmp/rustc-llvm
  247. curl -sfSL https://ci-artifacts.rust-lang.org/rustc-builds/$rustc_sha/rust-dev-nightly-${{ matrix.target }}.tar.xz | \
  248. tar -xJ --strip-components 2 -C /tmp/rustc-llvm
  249. echo /tmp/rustc-llvm/bin >> $GITHUB_PATH
  250. # NB: rustc doesn't ship libLLVM.so on macOS, so disable proxying (default feature). We also
  251. # --force so that bpf-linker gets always relinked against the latest LLVM downloaded above.
  252. #
  253. # Do this on all system (not just macOS) to avoid relying on rustc-provided libLLVM.so.
  254. - run: cargo install --git https://github.com/aya-rs/bpf-linker.git bpf-linker --no-default-features --features llvm-21 --force
  255. - uses: actions/cache@v4
  256. with:
  257. path: test/.tmp
  258. key: ${{ runner.arch }}-${{ runner.os }}-test-cache
  259. - name: Download debian kernels
  260. if: runner.arch == 'ARM64'
  261. run: .github/scripts/download_kernel_images.sh test/.tmp/debian-kernels/arm64 arm64 5.10 6.1 6.12
  262. - name: Download debian kernels
  263. if: runner.arch == 'X64'
  264. run: .github/scripts/download_kernel_images.sh test/.tmp/debian-kernels/amd64 amd64 5.10 6.1 6.12
  265. - name: Cleanup stale kernels and modules
  266. run: |
  267. set -euxo pipefail
  268. rm -rf test/.tmp/boot test/.tmp/lib
  269. - name: Run local integration tests
  270. if: runner.os == 'Linux'
  271. run: cargo xtask integration-test local
  272. - name: Run virtualized integration tests
  273. if: runner.os == 'Linux'
  274. run: |
  275. set -euxo pipefail
  276. # https://github.blog/changelog/2023-02-23-hardware-accelerated-android-virtualization-on-actions-windows-and-linux-larger-hosted-runners/
  277. echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
  278. sudo udevadm control --reload-rules
  279. sudo udevadm trigger --name-match=kvm || true # kvm is not available on arm64.
  280. find test/.tmp -name '*.deb' -print0 | sort -Vz | xargs -t -0 \
  281. cargo xtask integration-test vm --cache-dir test/.tmp \
  282. --github-api-token ${{ secrets.GITHUB_TOKEN }}
  283. - name: Run virtualized integration tests
  284. if: runner.os == 'macOS'
  285. env:
  286. # This sets the linker to the one installed by FiloSottile/musl-cross.
  287. CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: x86_64-linux-musl-gcc
  288. run: |
  289. set -euxo pipefail
  290. find test/.tmp -name '*.deb' -print0 | sort -Vz | xargs -t -0 \
  291. cargo xtask integration-test vm --cache-dir test/.tmp \
  292. --github-api-token ${{ secrets.GITHUB_TOKEN }}
  293. # Provides a single status check for the entire build workflow.
  294. # This is used for merge automation, like Mergify, since GH actions
  295. # has no concept of "when all status checks pass".
  296. # https://docs.mergify.com/conditions/#validating-all-status-checks
  297. build-workflow-complete:
  298. needs:
  299. - lint
  300. - build-test-aya
  301. - build-test-aya-ebpf
  302. - run-integration-test
  303. runs-on: ubuntu-latest
  304. steps:
  305. - run: echo 'Build Complete'