ci.yml 10 KB

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