ci.yml 11 KB

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