ci.yml 10 KB

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