ci.yml 8.5 KB

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