ci.yml 10 KB

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