ci.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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@v18
  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. - run: cargo xtask public-api
  37. if: github.event_name == 'pull_request'
  38. - run: cargo xtask public-api --bless
  39. if: github.event_name != 'pull_request' && github.repository_owner == 'aya-rs'
  40. - uses: peter-evans/create-pull-request@v7
  41. if: github.event_name != 'pull_request' && github.repository_owner == 'aya-rs'
  42. with:
  43. commit-message: "public-api: regenerate"
  44. - name: Run miri
  45. run: |
  46. set -euxo pipefail
  47. cargo hack miri test --all-targets --feature-powerset \
  48. --exclude aya-ebpf \
  49. --exclude aya-ebpf-bindings \
  50. --exclude aya-log-ebpf \
  51. --exclude integration-ebpf \
  52. --exclude integration-test \
  53. --workspace
  54. build-test-aya:
  55. strategy:
  56. fail-fast: false
  57. matrix:
  58. bpf_target_arch:
  59. - x86_64-unknown-linux-gnu
  60. - aarch64-unknown-linux-gnu
  61. - armv7-unknown-linux-gnueabi
  62. - riscv64gc-unknown-linux-gnu
  63. - powerpc64le-unknown-linux-gnu
  64. - s390x-unknown-linux-gnu
  65. runs-on: ubuntu-latest
  66. steps:
  67. - uses: actions/checkout@v4
  68. - uses: dtolnay/rust-toolchain@master
  69. with:
  70. toolchain: stable
  71. - uses: Swatinem/rust-cache@v2
  72. - uses: taiki-e/install-action@cargo-hack
  73. - name: Build
  74. run: |
  75. set -euxo pipefail
  76. cargo hack build --all-targets --feature-powerset \
  77. --exclude aya-ebpf \
  78. --exclude aya-ebpf-bindings \
  79. --exclude aya-log-ebpf \
  80. --exclude integration-ebpf \
  81. --workspace
  82. - name: Test
  83. env:
  84. RUST_BACKTRACE: full
  85. run: |
  86. set -euxo pipefail
  87. cargo hack test --all-targets --feature-powerset \
  88. --exclude aya-ebpf \
  89. --exclude aya-ebpf-bindings \
  90. --exclude aya-log-ebpf \
  91. --exclude integration-ebpf \
  92. --exclude integration-test \
  93. --workspace
  94. - name: Doctests
  95. env:
  96. RUST_BACKTRACE: full
  97. run: |
  98. set -euxo pipefail
  99. cargo hack test --doc --feature-powerset \
  100. --exclude aya-ebpf \
  101. --exclude aya-ebpf-bindings \
  102. --exclude aya-log-ebpf \
  103. --exclude init \
  104. --exclude integration-ebpf \
  105. --exclude integration-test \
  106. --workspace
  107. build-test-aya-ebpf:
  108. strategy:
  109. fail-fast: false
  110. matrix:
  111. bpf_target_arch:
  112. - x86_64
  113. - aarch64
  114. - arm
  115. - riscv64
  116. - powerpc64
  117. - s390x
  118. target:
  119. - bpfel-unknown-none
  120. - bpfeb-unknown-none
  121. runs-on: ubuntu-latest
  122. steps:
  123. - uses: actions/checkout@v4
  124. - uses: dtolnay/rust-toolchain@master
  125. with:
  126. toolchain: nightly
  127. components: rust-src
  128. - uses: Swatinem/rust-cache@v2
  129. - name: bpf-linker
  130. run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git
  131. - uses: taiki-e/install-action@cargo-hack
  132. - name: Build
  133. env:
  134. CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
  135. run: |
  136. set -euxo pipefail
  137. cargo hack build --package aya-ebpf --package aya-log-ebpf \
  138. --feature-powerset \
  139. --target ${{ matrix.target }} \
  140. -Z build-std=core
  141. - name: Test
  142. env:
  143. CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
  144. RUST_BACKTRACE: full
  145. run: |
  146. set -euxo pipefail
  147. cargo hack test --doc \
  148. --package aya-ebpf \
  149. --package aya-log-ebpf \
  150. --feature-powerset
  151. run-integration-test:
  152. strategy:
  153. fail-fast: false
  154. matrix:
  155. include:
  156. - target: x86_64-apple-darwin
  157. # macos-14 is arm64[0] which doesn't support nested
  158. # virtualization[1].
  159. #
  160. # [0] https://github.com/actions/runner-images#available-images
  161. #
  162. # [1] https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#limitations-for-arm64-macos-runners
  163. os: macos-13
  164. - target: x86_64-unknown-linux-gnu
  165. # We don't use ubuntu-latest because we care about the apt packages available.
  166. os: ubuntu-22.04
  167. runs-on: ${{ matrix.os }}
  168. steps:
  169. - uses: actions/checkout@v4
  170. with:
  171. submodules: recursive
  172. - name: Install prerequisites
  173. if: runner.os == 'Linux'
  174. # ubuntu-22.04 comes with clang 13-15[0]; support for signed and 64bit
  175. # enum values was added in clang 15[1] which isn't in `$PATH`.
  176. #
  177. # gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
  178. #
  179. # [0] https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
  180. #
  181. # [1] https://github.com/llvm/llvm-project/commit/dc1c43d
  182. run: |
  183. set -euxo pipefail
  184. sudo apt update
  185. sudo apt -y install gcc-multilib lynx qemu-system-{arm,x86}
  186. echo /usr/lib/llvm-15/bin >> $GITHUB_PATH
  187. - name: Install prerequisites
  188. if: runner.os == 'macOS'
  189. # The xargs shipped on macOS always exits 0 with -P0, so we need GNU findutils.
  190. #
  191. # The tar shipped on macOS doesn't support --wildcards, so we need GNU tar.
  192. #
  193. # The clang shipped on macOS doesn't support BPF, so we need LLVM from brew.
  194. run: |
  195. set -euxo pipefail
  196. brew update
  197. # https://github.com/actions/setup-python/issues/577
  198. find /usr/local/bin -type l -exec sh -c 'readlink -f "$1" \
  199. | grep -q ^/Library/Frameworks/Python.framework/Versions/' _ {} \; -exec rm -v {} \;
  200. brew install --formula dpkg gnu-tar llvm lynx pkg-config qemu
  201. echo $(brew --prefix)/opt/gnu-tar/libexec/gnubin >> $GITHUB_PATH
  202. echo $(brew --prefix)/opt/llvm/bin >> $GITHUB_PATH
  203. - uses: dtolnay/rust-toolchain@master
  204. with:
  205. toolchain: nightly
  206. components: rust-src
  207. targets: aarch64-unknown-linux-musl,x86_64-unknown-linux-musl
  208. - uses: Swatinem/rust-cache@v2
  209. - name: Install libLLVM
  210. # Download libLLVM from Rust CI to ensure that the libLLVM version
  211. # matches exactly with the version used by the current Rust nightly. A
  212. # mismatch between libLLVM (used by bpf-linker) and Rust's LLVM version
  213. # can lead to linking issues.
  214. run: |
  215. set -euxo pipefail
  216. # Get the partial SHA from Rust nightly.
  217. rustc_sha=$(rustc +nightly --version | grep -oE '[a-f0-9]{7,40}')
  218. # Get the full SHA from GitHub.
  219. rustc_sha=$(curl -sfSL https://api.github.com/repos/rust-lang/rust/commits/$rustc_sha \
  220. --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
  221. --header 'content-type: application/json' \
  222. | jq -r '.sha')
  223. mkdir -p /tmp/rustc-llvm
  224. curl -sfSL https://ci-artifacts.rust-lang.org/rustc-builds/$rustc_sha/rust-dev-nightly-${{ matrix.target }}.tar.xz | \
  225. tar -xJ --strip-components 2 -C /tmp/rustc-llvm
  226. echo /tmp/rustc-llvm/bin >> $GITHUB_PATH
  227. - name: bpf-linker
  228. # NB: rustc doesn't ship libLLVM.so on macOS, so disable proxying (default feature). We also
  229. # --force so that bpf-linker gets always relinked against the latest LLVM downloaded above.
  230. #
  231. # Do this on all system (not just macOS) to avoid relying on rustc-provided libLLVM.so.
  232. run: cargo install --force bpf-linker --git https://github.com/aya-rs/bpf-linker.git --no-default-features
  233. - name: Download debian kernels
  234. if: runner.arch == 'ARM64'
  235. # TODO: enable tests on kernels before 6.0.
  236. run: .github/scripts/download_kernel_images.sh test/.tmp/debian-kernels/arm64 arm64 6.1 6.10
  237. - name: Download debian kernels
  238. if: runner.arch == 'X64'
  239. # TODO: enable tests on kernels before 6.0.
  240. run: .github/scripts/download_kernel_images.sh test/.tmp/debian-kernels/amd64 amd64 6.1 6.10
  241. - name: Extract debian kernels
  242. run: |
  243. set -euxo pipefail
  244. find test/.tmp -name '*.deb' -print0 | xargs -t -0 -I {} \
  245. sh -c "dpkg --fsys-tarfile {} | tar -C test/.tmp --wildcards --extract '*vmlinuz*' --file -"
  246. - name: Run local integration tests
  247. if: runner.os == 'Linux'
  248. run: cargo xtask integration-test local
  249. - name: Run virtualized integration tests
  250. run: find test/.tmp -name 'vmlinuz-*' | xargs -t cargo xtask integration-test vm
  251. # Provides a single status check for the entire build workflow.
  252. # This is used for merge automation, like Mergify, since GH actions
  253. # has no concept of "when all status checks pass".
  254. # https://docs.mergify.com/conditions/#validating-all-status-checks
  255. build-workflow-complete:
  256. needs:
  257. - lint
  258. - build-test-aya
  259. - build-test-aya-ebpf
  260. - run-integration-test
  261. runs-on: ubuntu-latest
  262. steps:
  263. - name: Build Complete
  264. run: echo "Build Complete"