ci.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. name: aya-ci
  2. on:
  3. push:
  4. branches:
  5. - main
  6. pull_request:
  7. branches:
  8. - main
  9. schedule:
  10. - cron: 00 4 * * *
  11. env:
  12. CARGO_TERM_COLOR: always
  13. LLVM_VERSION: 18
  14. jobs:
  15. lint:
  16. runs-on: ubuntu-22.04
  17. steps:
  18. - uses: actions/checkout@v4
  19. - uses: dtolnay/rust-toolchain@master
  20. with:
  21. toolchain: nightly
  22. components: rustfmt, clippy, miri, rust-src
  23. - uses: Swatinem/rust-cache@v2
  24. - uses: taiki-e/install-action@v2
  25. with:
  26. tool: cargo-hack,taplo-cli
  27. - name: Check C formatting
  28. run: git ls-files -- '*.c' '*.h' | xargs clang-format --dry-run --Werror
  29. - name: Check Markdown
  30. uses: DavidAnson/markdownlint-cli2-action@v16
  31. - name: Check TOML formatting
  32. run: taplo fmt --check
  33. - name: Check formatting
  34. run: cargo fmt --all -- --check
  35. - name: Run clippy
  36. run: cargo hack clippy --all-targets --feature-powerset --workspace -- --deny warnings
  37. - name: Check public API
  38. run: cargo xtask public-api
  39. - name: Run miri
  40. run: |
  41. set -euxo pipefail
  42. cargo hack miri test --all-targets --feature-powerset \
  43. --exclude aya-ebpf \
  44. --exclude aya-ebpf-bindings \
  45. --exclude aya-log-ebpf \
  46. --exclude integration-ebpf \
  47. --exclude integration-test \
  48. --workspace
  49. build-test-aya:
  50. strategy:
  51. fail-fast: false
  52. matrix:
  53. arch:
  54. - x86_64-unknown-linux-gnu
  55. - aarch64-unknown-linux-gnu
  56. - armv7-unknown-linux-gnueabi
  57. - riscv64gc-unknown-linux-gnu
  58. - powerpc64le-unknown-linux-gnu
  59. - s390x-unknown-linux-gnu
  60. runs-on: ubuntu-22.04
  61. steps:
  62. - uses: actions/checkout@v4
  63. - uses: dtolnay/rust-toolchain@master
  64. with:
  65. toolchain: stable
  66. targets: ${{ matrix.arch }}
  67. - uses: Swatinem/rust-cache@v2
  68. - uses: taiki-e/install-action@cargo-hack
  69. - uses: taiki-e/setup-cross-toolchain-action@v1
  70. with:
  71. target: ${{ matrix.arch }}
  72. - name: Build
  73. run: |
  74. set -euxo pipefail
  75. cargo hack build --all-targets --feature-powerset \
  76. --exclude aya-ebpf \
  77. --exclude aya-ebpf-bindings \
  78. --exclude aya-log-ebpf \
  79. --exclude integration-ebpf \
  80. --workspace
  81. - name: Test
  82. env:
  83. RUST_BACKTRACE: full
  84. run: |
  85. set -euxo pipefail
  86. cargo hack test --all-targets --feature-powerset \
  87. --exclude aya-ebpf \
  88. --exclude aya-ebpf-bindings \
  89. --exclude aya-log-ebpf \
  90. --exclude integration-ebpf \
  91. --exclude integration-test \
  92. --workspace
  93. - name: Doctests
  94. env:
  95. RUST_BACKTRACE: full
  96. run: |
  97. set -euxo pipefail
  98. cargo hack test --doc --feature-powerset \
  99. --exclude aya-ebpf \
  100. --exclude aya-ebpf-bindings \
  101. --exclude aya-log-ebpf \
  102. --exclude init \
  103. --exclude integration-ebpf \
  104. --exclude integration-test \
  105. --workspace
  106. build-test-aya-ebpf:
  107. strategy:
  108. fail-fast: false
  109. matrix:
  110. arch:
  111. - x86_64
  112. - aarch64
  113. - arm
  114. - riscv64
  115. - powerpc64
  116. - s390x
  117. target:
  118. - bpfel-unknown-none
  119. - bpfeb-unknown-none
  120. runs-on: ubuntu-22.04
  121. steps:
  122. - uses: actions/checkout@v4
  123. - uses: dtolnay/rust-toolchain@master
  124. with:
  125. toolchain: nightly
  126. components: rust-src
  127. - uses: Swatinem/rust-cache@v2
  128. - name: bpf-linker
  129. run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git
  130. - uses: taiki-e/install-action@cargo-hack
  131. - name: Build
  132. env:
  133. CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.arch }}
  134. run: |
  135. set -euxo pipefail
  136. cargo hack build --package aya-ebpf --package aya-log-ebpf \
  137. --feature-powerset \
  138. --target ${{ matrix.target }} \
  139. -Z build-std=core
  140. - name: Test
  141. env:
  142. CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.arch }}
  143. RUST_BACKTRACE: full
  144. run: |
  145. set -euxo pipefail
  146. cargo hack test --doc \
  147. --package aya-ebpf \
  148. --package aya-log-ebpf \
  149. --feature-powerset
  150. run-integration-test:
  151. strategy:
  152. fail-fast: false
  153. matrix:
  154. runner:
  155. # macos-14 is arm64 per
  156. # https://github.com/actions/runner-images#available-images which
  157. # doesn't support nested virtualization per
  158. # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#limitations-for-arm64-macos-runners
  159. - macos-13
  160. - ubuntu-22.04
  161. runs-on: ${{ matrix.runner }}
  162. steps:
  163. - uses: actions/checkout@v4
  164. with:
  165. submodules: recursive
  166. - name: Install prerequisites
  167. if: runner.os == 'Linux'
  168. # ubuntu-22.04 comes with clang 14[0] which doesn't include support for signed and 64bit
  169. # enum values which was added in clang 15[1].
  170. #
  171. # gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
  172. #
  173. # llvm provides llvm-objcopy which is used to build the BTF relocation tests.
  174. #
  175. # [0] https://github.com/actions/runner-images/blob/ubuntu22/20230724.1/images/linux/Ubuntu2204-Readme.md
  176. #
  177. # [1] https://github.com/llvm/llvm-project/commit/dc1c43d
  178. run: |
  179. set -euxo pipefail
  180. wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
  181. echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-${{ env.LLVM_VERSION }} main | sudo tee /etc/apt/sources.list.d/llvm.list
  182. sudo apt update
  183. sudo apt -y install clang-${{ env.LLVM_VERSION }} gcc-multilib llvm-${{ env.LLVM_VERSION }} locate qemu-system-{arm,x86}
  184. echo /usr/lib/llvm-${{ env.LLVM_VERSION }}/bin >> $GITHUB_PATH
  185. - name: bpf-linker
  186. if: runner.os == 'Linux'
  187. run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git
  188. - name: Install prerequisites
  189. if: runner.os == 'macOS'
  190. # The xargs shipped on macOS always exits 0 with -P0, so we need GNU findutils.
  191. #
  192. # The tar shipped on macOS doesn't support --wildcards, so we need GNU tar.
  193. #
  194. # The clang shipped on macOS doesn't support BPF, so we need LLVM from brew.
  195. #
  196. # We also need LLVM for bpf-linker, see comment below.
  197. run: |
  198. set -euxo pipefail
  199. brew update
  200. # https://github.com/actions/setup-python/issues/577
  201. find /usr/local/bin -type l -exec sh -c 'readlink -f "$1" \
  202. | grep -q ^/Library/Frameworks/Python.framework/Versions/' _ {} \; -exec rm -v {} \;
  203. HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 \
  204. brew install dpkg findutils gnu-tar llvm pkg-config qemu
  205. echo $(brew --prefix)/opt/findutils/libexec/gnubin >> $GITHUB_PATH
  206. echo $(brew --prefix)/opt/gnu-tar/libexec/gnubin >> $GITHUB_PATH
  207. echo $(brew --prefix)/opt/llvm/bin >> $GITHUB_PATH
  208. - uses: dtolnay/rust-toolchain@master
  209. with:
  210. toolchain: nightly
  211. components: rust-src
  212. targets: aarch64-unknown-linux-musl,x86_64-unknown-linux-musl
  213. - uses: Swatinem/rust-cache@v2
  214. - name: bpf-linker
  215. if: runner.os == 'macOS'
  216. # NB: rustc doesn't ship libLLVM.so on macOS, so disable proxying (default feature). We also
  217. # --force so that bpf-linker gets always relinked against the latest LLVM installed by brew.
  218. run: cargo install --force bpf-linker --git https://github.com/aya-rs/bpf-linker.git --no-default-features
  219. - name: Download debian kernels
  220. if: runner.arch == 'ARM64'
  221. run: |
  222. set -euxo pipefail
  223. mkdir -p test/.tmp/debian-kernels/arm64
  224. # NB: a 4.19 kernel image for arm64 was not available.
  225. # TODO: enable tests on kernels before 6.0.
  226. # linux-image-5.10.0-23-cloud-arm64-unsigned_5.10.179-3_arm64.deb \
  227. printf '%s\0' \
  228. linux-image-6.1.0-16-cloud-arm64-unsigned_6.1.67-1_arm64.deb \
  229. linux-image-6.10.4-cloud-arm64-unsigned_6.10.4-1_arm64.deb \
  230. | xargs -0 -t -P0 -I {} wget -nd -nv -P test/.tmp/debian-kernels/arm64 ftp://ftp.us.debian.org/debian/pool/main/l/linux/{}
  231. - name: Download debian kernels
  232. if: runner.arch == 'X64'
  233. run: |
  234. set -euxo pipefail
  235. mkdir -p test/.tmp/debian-kernels/amd64
  236. # TODO: enable tests on kernels before 6.0.
  237. # linux-image-4.19.0-21-cloud-amd64-unsigned_4.19.249-2_amd64.deb \
  238. # linux-image-5.10.0-23-cloud-amd64-unsigned_5.10.179-3_amd64.deb \
  239. printf '%s\0' \
  240. linux-image-6.1.0-16-cloud-amd64-unsigned_6.1.67-1_amd64.deb \
  241. linux-image-6.10.4-cloud-amd64-unsigned_6.10.4-1_amd64.deb \
  242. | xargs -0 -t -P0 -I {} wget -nd -nv -P test/.tmp/debian-kernels/amd64 ftp://ftp.us.debian.org/debian/pool/main/l/linux/{}
  243. - name: Extract debian kernels
  244. run: |
  245. set -euxo pipefail
  246. find test/.tmp -name '*.deb' -print0 | xargs -t -0 -I {} \
  247. sh -c "dpkg --fsys-tarfile {} | tar -C test/.tmp --wildcards --extract '*vmlinuz*' --file -"
  248. - name: Run local integration tests
  249. if: runner.os == 'Linux'
  250. run: cargo xtask integration-test local
  251. - name: Run virtualized integration tests
  252. run: find test/.tmp -name 'vmlinuz-*' | xargs -t cargo xtask integration-test vm
  253. # Provides a single status check for the entire build workflow.
  254. # This is used for merge automation, like Mergify, since GH actions
  255. # has no concept of "when all status checks pass".
  256. # https://docs.mergify.com/conditions/#validating-all-status-checks
  257. build-workflow-complete:
  258. needs:
  259. - lint
  260. - build-test-aya
  261. - build-test-aya-ebpf
  262. - run-integration-test
  263. runs-on: ubuntu-latest
  264. steps:
  265. - name: Build Complete
  266. run: echo "Build Complete"