ci.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. - powerpc64le-unknown-linux-gnu
  67. - riscv64gc-unknown-linux-gnu
  68. - s390x-unknown-linux-gnu
  69. - x86_64-unknown-linux-gnu
  70. runs-on: ubuntu-latest
  71. steps:
  72. - uses: actions/checkout@v5
  73. - uses: dtolnay/rust-toolchain@stable
  74. with:
  75. targets: ${{ matrix.arch }}
  76. - uses: Swatinem/rust-cache@v2
  77. - uses: taiki-e/install-action@cargo-hack
  78. # This is magic, it sets `$CARGO_BUILD_TARGET`.
  79. - uses: taiki-e/setup-cross-toolchain-action@v1
  80. with:
  81. target: ${{ matrix.arch }}
  82. - name: Build
  83. run: |
  84. set -euxo pipefail
  85. cargo hack build --all-targets --feature-powerset \
  86. --exclude aya-ebpf \
  87. --exclude aya-ebpf-bindings \
  88. --exclude aya-log-ebpf \
  89. --exclude integration-ebpf \
  90. --exclude xtask \
  91. --workspace
  92. - name: Test
  93. env:
  94. RUST_BACKTRACE: full
  95. run: |
  96. set -euxo pipefail
  97. cargo hack test --all-targets --feature-powerset \
  98. --exclude aya-ebpf \
  99. --exclude aya-ebpf-bindings \
  100. --exclude aya-log-ebpf \
  101. --exclude integration-ebpf \
  102. --exclude integration-test \
  103. --exclude xtask \
  104. --workspace
  105. - name: Doctests
  106. env:
  107. RUST_BACKTRACE: full
  108. run: |
  109. set -euxo pipefail
  110. cargo hack test --doc --feature-powerset \
  111. --exclude aya-ebpf \
  112. --exclude aya-ebpf-bindings \
  113. --exclude aya-log-ebpf \
  114. --exclude init \
  115. --exclude integration-ebpf \
  116. --exclude integration-test \
  117. --exclude xtask \
  118. --workspace
  119. build-test-aya-ebpf:
  120. strategy:
  121. fail-fast: false
  122. matrix:
  123. bpf_target_arch:
  124. - aarch64
  125. - arm
  126. - mips
  127. - powerpc64
  128. - riscv64
  129. - s390x
  130. - x86_64
  131. target:
  132. - bpfel-unknown-none
  133. - bpfeb-unknown-none
  134. runs-on: ubuntu-latest
  135. steps:
  136. - uses: actions/checkout@v5
  137. - uses: dtolnay/rust-toolchain@nightly
  138. with:
  139. components: rust-src
  140. # Installed *after* nightly so it is the default.
  141. - uses: dtolnay/rust-toolchain@stable
  142. - uses: Swatinem/rust-cache@v2
  143. - run: cargo install --git https://github.com/aya-rs/bpf-linker.git bpf-linker --features llvm-21
  144. - uses: taiki-e/install-action@cargo-hack
  145. - name: Build
  146. env:
  147. CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
  148. run: |
  149. set -euxo pipefail
  150. cargo +nightly hack build \
  151. --target ${{ matrix.target }} \
  152. -Z build-std=core \
  153. --package aya-ebpf \
  154. --package aya-log-ebpf \
  155. --feature-powerset
  156. - name: Test
  157. env:
  158. CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
  159. RUST_BACKTRACE: full
  160. run: |
  161. set -euxo pipefail
  162. cargo hack test \
  163. --doc \
  164. --package aya-ebpf \
  165. --package aya-log-ebpf \
  166. --feature-powerset
  167. run-integration-test:
  168. strategy:
  169. fail-fast: false
  170. matrix:
  171. include:
  172. - target: x86_64-apple-darwin
  173. # macos-15 is arm64[0] which doesn't support nested
  174. # virtualization[1].
  175. #
  176. # [0] https://github.com/actions/runner-images#available-images
  177. #
  178. # [1] https://docs.github.com/en/actions/reference/runners/github-hosted-runners#limitations-for-arm64-macos-runners
  179. os: macos-15-intel
  180. # We don't use ubuntu-latest because we care about the apt packages available.
  181. - target: x86_64-unknown-linux-gnu
  182. os: ubuntu-24.04
  183. - target: aarch64-unknown-linux-gnu
  184. os: ubuntu-24.04-arm
  185. runs-on: ${{ matrix.os }}
  186. steps:
  187. - uses: actions/checkout@v5
  188. with:
  189. submodules: recursive
  190. - name: Install prerequisites
  191. if: runner.os == 'Linux'
  192. run: |
  193. set -euxo pipefail
  194. sudo apt update
  195. sudo apt -y install \
  196. liblzma-dev \
  197. lynx \
  198. musl-tools \
  199. qemu-system-{arm,x86}
  200. - name: Install prerequisites
  201. if: runner.os == 'macOS'
  202. # The curl shipped on macOS doesn't contain
  203. # https://github.com/curl/curl/commit/85efbb92b8e6679705e122cee45ce76c56414a3e which is
  204. # needed for proper handling of `--etag-{compare,save}`.
  205. #
  206. # The tar shipped on macOS doesn't support --wildcards, so we need GNU tar.
  207. #
  208. # The clang shipped on macOS doesn't support BPF, so we need LLVM from brew.
  209. #
  210. # We need a musl C toolchain to compile our `test-distro` since some of
  211. # our dependencies have build scripts that compile C code (i.e xz2).
  212. # This is provided by `brew install filosottile/musl-cross/musl-cross`.
  213. run: |
  214. set -euxo pipefail
  215. # Dependencies are tracked in `Brewfile`.
  216. brew bundle
  217. echo $(brew --prefix curl)/bin >> $GITHUB_PATH
  218. echo $(brew --prefix gnu-tar)/libexec/gnubin >> $GITHUB_PATH
  219. echo $(brew --prefix llvm)/bin >> $GITHUB_PATH
  220. # https://github.com/actions/setup-python/issues/577
  221. find /usr/local/bin -type l -exec sh -c 'readlink -f "$1" \
  222. | grep -q ^/Library/Frameworks/Python.framework/Versions/' _ {} \; -exec rm -v {} \;
  223. - uses: dtolnay/rust-toolchain@nightly
  224. with:
  225. components: rust-src
  226. # Installed *after* nightly so it is the default.
  227. - uses: dtolnay/rust-toolchain@stable
  228. with:
  229. targets: aarch64-unknown-linux-musl,x86_64-unknown-linux-musl
  230. - uses: Swatinem/rust-cache@v2
  231. - name: Install libLLVM
  232. # Download libLLVM from Rust CI to ensure that the libLLVM version
  233. # matches exactly with the version used by the current Rust nightly. A
  234. # mismatch between libLLVM (used by bpf-linker) and Rust's LLVM version
  235. # can lead to linking issues.
  236. run: |
  237. set -euxo pipefail
  238. # Get the partial SHA from Rust nightly.
  239. rustc_sha=$(rustc +nightly --version | grep -oE '[a-f0-9]{7,40}')
  240. # Get the full SHA from GitHub.
  241. rustc_sha=$(curl -sfSL https://api.github.com/repos/rust-lang/rust/commits/$rustc_sha \
  242. --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
  243. --header 'content-type: application/json' \
  244. | jq -r '.sha')
  245. mkdir -p /tmp/rustc-llvm
  246. curl -sfSL https://ci-artifacts.rust-lang.org/rustc-builds/$rustc_sha/rust-dev-nightly-${{ matrix.target }}.tar.xz | \
  247. tar -xJ --strip-components 2 -C /tmp/rustc-llvm
  248. echo /tmp/rustc-llvm/bin >> $GITHUB_PATH
  249. # NB: rustc doesn't ship libLLVM.so on macOS, so disable proxying (default feature). We also
  250. # --force so that bpf-linker gets always relinked against the latest LLVM downloaded above.
  251. #
  252. # Do this on all system (not just macOS) to avoid relying on rustc-provided libLLVM.so.
  253. - run: cargo install --git https://github.com/aya-rs/bpf-linker.git bpf-linker --no-default-features --features llvm-21 --force
  254. - uses: actions/cache@v4
  255. with:
  256. path: test/.tmp
  257. key: ${{ runner.arch }}-${{ runner.os }}-test-cache
  258. - name: Download debian kernels
  259. if: runner.arch == 'ARM64'
  260. # TODO: enable tests on kernels before 6.0.
  261. run: .github/scripts/download_kernel_images.sh test/.tmp/debian-kernels/arm64 arm64 6.1 6.12
  262. - name: Download debian kernels
  263. if: runner.arch == 'X64'
  264. # TODO: enable tests on kernels before 6.0.
  265. run: .github/scripts/download_kernel_images.sh test/.tmp/debian-kernels/amd64 amd64 6.1 6.12
  266. - name: Cleanup stale kernels and modules
  267. run: |
  268. set -euxo pipefail
  269. rm -rf test/.tmp/boot test/.tmp/lib
  270. - name: Extract debian kernels
  271. run: |
  272. set -euxo pipefail
  273. # The wildcard '**/boot/*' extracts kernel images and config.
  274. # The wildcard '**/modules/*' extracts kernel modules.
  275. # Modules are required since not all parts of the kernel we want to
  276. # test are built-in.
  277. find test/.tmp -name '*.deb' -print0 | xargs -t -0 -I {} \
  278. sh -c "dpkg --fsys-tarfile {} | tar -C test/.tmp \
  279. --wildcards --extract '**/boot/*' '**/modules/*' --file -"
  280. - name: Run local integration tests
  281. if: runner.os == 'Linux'
  282. run: cargo xtask integration-test local
  283. - name: Run virtualized integration tests
  284. if: runner.os == 'Linux'
  285. run: |
  286. set -euxo pipefail
  287. # https://github.blog/changelog/2023-02-23-hardware-accelerated-android-virtualization-on-actions-windows-and-linux-larger-hosted-runners/
  288. echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
  289. sudo udevadm control --reload-rules
  290. sudo udevadm trigger --name-match=kvm || true # kvm is not available on arm64.
  291. .github/scripts/find_kernels.py | xargs -t -0 \
  292. cargo xtask integration-test vm --cache-dir test/.tmp \
  293. --github-api-token ${{ secrets.GITHUB_TOKEN }} \
  294. - name: Run virtualized integration tests
  295. if: runner.os == 'macOS'
  296. env:
  297. # This sets the linker to the one installed by FiloSottile/musl-cross.
  298. CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: x86_64-linux-musl-gcc
  299. run: |
  300. set -euxo pipefail
  301. .github/scripts/find_kernels.py | xargs -t -0 \
  302. cargo xtask integration-test vm --cache-dir test/.tmp \
  303. --github-api-token ${{ secrets.GITHUB_TOKEN }} \
  304. # Provides a single status check for the entire build workflow.
  305. # This is used for merge automation, like Mergify, since GH actions
  306. # has no concept of "when all status checks pass".
  307. # https://docs.mergify.com/conditions/#validating-all-status-checks
  308. build-workflow-complete:
  309. needs:
  310. - lint
  311. - build-test-aya
  312. - build-test-aya-ebpf
  313. - run-integration-test
  314. runs-on: ubuntu-latest
  315. steps:
  316. - run: echo 'Build Complete'