ci.yml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. jobs:
  14. lint:
  15. runs-on: ubuntu-22.04
  16. steps:
  17. - uses: actions/checkout@v4
  18. - uses: dtolnay/rust-toolchain@master
  19. with:
  20. toolchain: nightly
  21. components: rustfmt, clippy, miri, rust-src
  22. - uses: Swatinem/rust-cache@v2
  23. - uses: taiki-e/install-action@v2
  24. with:
  25. tool: cargo-hack,taplo-cli
  26. - name: Check C formatting
  27. run: git ls-files -- '*.c' '*.h' | xargs clang-format --dry-run --Werror
  28. - name: Check Markdown
  29. uses: DavidAnson/markdownlint-cli2-action@v16
  30. - name: Check TOML formatting
  31. run: taplo fmt --check
  32. - name: Check formatting
  33. run: cargo fmt --all -- --check
  34. - name: Run clippy
  35. run: cargo hack clippy --all-targets --feature-powerset --workspace -- --deny warnings
  36. - name: Check public API
  37. run: cargo xtask public-api
  38. - name: Run miri
  39. run: |
  40. set -euxo pipefail
  41. cargo hack miri test --all-targets --feature-powerset \
  42. --exclude aya-ebpf \
  43. --exclude aya-ebpf-bindings \
  44. --exclude aya-log-ebpf \
  45. --exclude integration-ebpf \
  46. --exclude integration-test \
  47. --workspace
  48. build-test-aya:
  49. strategy:
  50. fail-fast: false
  51. matrix:
  52. arch:
  53. - x86_64-unknown-linux-gnu
  54. - aarch64-unknown-linux-gnu
  55. - armv7-unknown-linux-gnueabi
  56. - riscv64gc-unknown-linux-gnu
  57. - powerpc64le-unknown-linux-gnu
  58. - s390x-unknown-linux-gnu
  59. runs-on: ubuntu-22.04
  60. steps:
  61. - uses: actions/checkout@v4
  62. - uses: dtolnay/rust-toolchain@master
  63. with:
  64. toolchain: stable
  65. targets: ${{ matrix.arch }}
  66. - uses: Swatinem/rust-cache@v2
  67. - uses: taiki-e/install-action@cargo-hack
  68. - uses: taiki-e/setup-cross-toolchain-action@v1
  69. with:
  70. target: ${{ matrix.arch }}
  71. - name: Build
  72. run: |
  73. set -euxo pipefail
  74. cargo hack build --all-targets --feature-powerset \
  75. --exclude aya-ebpf \
  76. --exclude aya-ebpf-bindings \
  77. --exclude aya-log-ebpf \
  78. --exclude integration-ebpf \
  79. --workspace
  80. - name: Test
  81. env:
  82. RUST_BACKTRACE: full
  83. run: |
  84. set -euxo pipefail
  85. cargo hack test --all-targets --feature-powerset \
  86. --exclude aya-ebpf \
  87. --exclude aya-ebpf-bindings \
  88. --exclude aya-log-ebpf \
  89. --exclude integration-ebpf \
  90. --exclude integration-test \
  91. --workspace
  92. - name: Doctests
  93. env:
  94. RUST_BACKTRACE: full
  95. run: |
  96. set -euxo pipefail
  97. cargo hack test --doc --feature-powerset \
  98. --exclude aya-ebpf \
  99. --exclude aya-ebpf-bindings \
  100. --exclude aya-log-ebpf \
  101. --exclude init \
  102. --exclude integration-ebpf \
  103. --exclude integration-test \
  104. --workspace
  105. build-test-aya-ebpf:
  106. strategy:
  107. fail-fast: false
  108. matrix:
  109. arch:
  110. - x86_64
  111. - aarch64
  112. - arm
  113. - riscv64
  114. - powerpc64
  115. - s390x
  116. target:
  117. - bpfel-unknown-none
  118. - bpfeb-unknown-none
  119. runs-on: ubuntu-22.04
  120. steps:
  121. - uses: actions/checkout@v4
  122. - uses: dtolnay/rust-toolchain@master
  123. with:
  124. toolchain: nightly
  125. components: rust-src
  126. - uses: Swatinem/rust-cache@v2
  127. - name: bpf-linker
  128. run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git
  129. - uses: taiki-e/install-action@cargo-hack
  130. - name: Build
  131. env:
  132. CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.arch }}
  133. run: |
  134. set -euxo pipefail
  135. cargo hack build --package aya-ebpf --package aya-log-ebpf \
  136. --feature-powerset \
  137. --target ${{ matrix.target }} \
  138. -Z build-std=core
  139. - name: Test
  140. env:
  141. CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.arch }}
  142. RUST_BACKTRACE: full
  143. run: |
  144. set -euxo pipefail
  145. cargo hack test --doc \
  146. --package aya-ebpf \
  147. --package aya-log-ebpf \
  148. --feature-powerset
  149. run-integration-test:
  150. strategy:
  151. fail-fast: false
  152. matrix:
  153. runner:
  154. - macos-12
  155. - ubuntu-22.04
  156. runs-on: ${{ matrix.runner }}
  157. steps:
  158. - uses: actions/checkout@v4
  159. with:
  160. submodules: recursive
  161. - uses: dtolnay/rust-toolchain@master
  162. with:
  163. toolchain: nightly
  164. components: rust-src
  165. targets: aarch64-unknown-linux-musl,x86_64-unknown-linux-musl
  166. - uses: Swatinem/rust-cache@v2
  167. - name: Install prerequisites
  168. if: runner.os == 'Linux'
  169. # ubuntu-22.04 comes with clang 14[0] which doesn't include support for signed and 64bit
  170. # enum values which was added in clang 15[1].
  171. #
  172. # gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
  173. #
  174. # llvm provides llvm-objcopy which is used to build the BTF relocation tests.
  175. #
  176. # [0] https://github.com/actions/runner-images/blob/ubuntu22/20230724.1/images/linux/Ubuntu2204-Readme.md
  177. #
  178. # [1] https://github.com/llvm/llvm-project/commit/dc1c43d
  179. run: |
  180. set -euxo pipefail
  181. wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
  182. echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main | sudo tee /etc/apt/sources.list.d/llvm.list
  183. sudo apt update
  184. sudo apt -y install clang gcc-multilib llvm locate qemu-system-{arm,x86}
  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 /usr/local/opt/findutils/libexec/gnubin >> $GITHUB_PATH
  206. echo /usr/local/opt/gnu-tar/libexec/gnubin >> $GITHUB_PATH
  207. echo /usr/local/opt/llvm/bin >> $GITHUB_PATH
  208. # https://github.com/Homebrew/homebrew-core/issues/140244
  209. codesign --verify $(which qemu-system-x86_64) || brew reinstall qemu --build-from-source
  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-15-cloud-arm64-unsigned_6.1.66-1_arm64.deb \
  225. | xargs -0 -t -P0 -I {} wget -nd -nv -P test/.tmp/debian-kernels/arm64 ftp://ftp.us.debian.org/debian/pool/main/l/linux/{}
  226. - name: Download debian kernels
  227. if: runner.arch == 'X64'
  228. run: |
  229. set -euxo pipefail
  230. mkdir -p test/.tmp/debian-kernels/amd64
  231. # TODO: enable tests on kernels before 6.0.
  232. # linux-image-4.19.0-21-cloud-amd64-unsigned_4.19.249-2_amd64.deb \
  233. # linux-image-5.10.0-23-cloud-amd64-unsigned_5.10.179-3_amd64.deb \
  234. printf '%s\0' \
  235. linux-image-6.1.0-15-cloud-amd64-unsigned_6.1.66-1_amd64.deb \
  236. | xargs -0 -t -P0 -I {} wget -nd -nv -P test/.tmp/debian-kernels/amd64 ftp://ftp.us.debian.org/debian/pool/main/l/linux/{}
  237. - name: Extract debian kernels
  238. run: |
  239. set -euxo pipefail
  240. find test/.tmp -name '*.deb' -print0 | xargs -t -0 -I {} \
  241. sh -c "dpkg --fsys-tarfile {} | tar -C test/.tmp --wildcards --extract '*vmlinuz*' --file -"
  242. - name: Run local integration tests
  243. if: runner.os == 'Linux'
  244. run: cargo xtask integration-test local
  245. - name: Run virtualized integration tests
  246. run: find test/.tmp -name 'vmlinuz-*' | xargs -t cargo xtask integration-test vm
  247. # Provides a single status check for the entire build workflow.
  248. # This is used for merge automation, like Mergify, since GH actions
  249. # has no concept of "when all status checks pass".
  250. # https://docs.mergify.com/conditions/#validating-all-status-checks
  251. build-workflow-complete:
  252. needs:
  253. - lint
  254. - build-test-aya
  255. - build-test-aya-ebpf
  256. - run-integration-test
  257. runs-on: ubuntu-latest
  258. steps:
  259. - name: Build Complete
  260. run: echo "Build Complete"