ci.yml 12 KB

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