4
0

ci.yml 11 KB

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