ci.yml 8.1 KB

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