ci.yml 9.8 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. jobs:
  14. lint:
  15. runs-on: ubuntu-latest
  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@v17
  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-latest
  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-latest
  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. include:
  154. - target: x86_64-apple-darwin
  155. # macos-14 is arm64[0] which doesn't support nested
  156. # virtualization[1].
  157. #
  158. # [0] https://github.com/actions/runner-images#available-images
  159. #
  160. # [1] https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#limitations-for-arm64-macos-runners
  161. os: macos-13
  162. - target: x86_64-unknown-linux-gnu
  163. # We don't use ubuntu-latest because we care about the apt packages available.
  164. os: ubuntu-22.04
  165. runs-on: ${{ matrix.os }}
  166. steps:
  167. - uses: actions/checkout@v4
  168. with:
  169. submodules: recursive
  170. - name: Install prerequisites
  171. if: runner.os == 'Linux'
  172. # ubuntu-22.04 comes with clang 13-15[0]; support for signed and 64bit
  173. # enum values was added in clang 15[1] which isn't in `$PATH`.
  174. #
  175. # gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
  176. #
  177. # [0] https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
  178. #
  179. # [1] https://github.com/llvm/llvm-project/commit/dc1c43d
  180. run: |
  181. set -euxo pipefail
  182. sudo apt update
  183. sudo apt -y install gcc-multilib lynx qemu-system-{arm,x86}
  184. echo /usr/lib/llvm-15/bin >> $GITHUB_PATH
  185. - name: Install prerequisites
  186. if: runner.os == 'macOS'
  187. # The xargs shipped on macOS always exits 0 with -P0, so we need GNU findutils.
  188. #
  189. # The tar shipped on macOS doesn't support --wildcards, so we need GNU tar.
  190. #
  191. # The clang shipped on macOS doesn't support BPF, so we need LLVM from brew.
  192. run: |
  193. set -euxo pipefail
  194. brew update
  195. # https://github.com/actions/setup-python/issues/577
  196. find /usr/local/bin -type l -exec sh -c 'readlink -f "$1" \
  197. | grep -q ^/Library/Frameworks/Python.framework/Versions/' _ {} \; -exec rm -v {} \;
  198. brew install --formula dpkg gnu-tar llvm lynx pkg-config qemu
  199. echo $(brew --prefix)/opt/gnu-tar/libexec/gnubin >> $GITHUB_PATH
  200. echo $(brew --prefix)/opt/llvm/bin >> $GITHUB_PATH
  201. - uses: dtolnay/rust-toolchain@master
  202. with:
  203. toolchain: nightly
  204. components: rust-src
  205. targets: aarch64-unknown-linux-musl,x86_64-unknown-linux-musl
  206. - uses: Swatinem/rust-cache@v2
  207. - name: Install libLLVM
  208. # Download libLLVM from Rust CI to ensure that the libLLVM version
  209. # matches exactly with the version used by the current Rust nightly. A
  210. # mismatch between libLLVM (used by bpf-linker) and Rust's LLVM version
  211. # can lead to linking issues.
  212. run: |
  213. set -euxo pipefail
  214. # Get the partial SHA from Rust nightly.
  215. rustc_sha=$(rustc +nightly --version | grep -oE '[a-f0-9]{7,40}')
  216. # Get the full SHA from GitHub.
  217. rustc_sha=$(curl -sfSL https://api.github.com/repos/rust-lang/rust/commits/$rustc_sha \
  218. --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
  219. --header 'content-type: application/json' \
  220. | jq -r '.sha')
  221. mkdir -p /tmp/rustc-llvm
  222. curl -sfSL https://ci-artifacts.rust-lang.org/rustc-builds/$rustc_sha/rust-dev-nightly-${{ matrix.target }}.tar.xz | \
  223. tar -xJ --strip-components 2 -C /tmp/rustc-llvm
  224. echo /tmp/rustc-llvm/bin >> $GITHUB_PATH
  225. - name: bpf-linker
  226. # NB: rustc doesn't ship libLLVM.so on macOS, so disable proxying (default feature). We also
  227. # --force so that bpf-linker gets always relinked against the latest LLVM downloaded above.
  228. #
  229. # Do this on all system (not just macOS) to avoid relying on rustc-provided libLLVM.so.
  230. run: cargo install --force bpf-linker --git https://github.com/aya-rs/bpf-linker.git --no-default-features
  231. - name: Download debian kernels
  232. if: runner.arch == 'ARM64'
  233. # TODO: enable tests on kernels before 6.0.
  234. run: .github/scripts/download_kernel_images.sh test/.tmp/debian-kernels/arm64 arm64 6.1 6.10
  235. - name: Download debian kernels
  236. if: runner.arch == 'X64'
  237. # TODO: enable tests on kernels before 6.0.
  238. run: .github/scripts/download_kernel_images.sh test/.tmp/debian-kernels/amd64 amd64 6.1 6.10
  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"