ci.yml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. on:
  2. pull_request:
  3. workflow_dispatch:
  4. push:
  5. branches: ["main"]
  6. env:
  7. # disable incremental compilation.
  8. #
  9. # incremental compilation is useful as part of an edit-build-test-edit cycle,
  10. # as it lets the compiler avoid recompiling code that hasn't changed. however,
  11. # on CI, we're not making small edits; we're almost always building the entire
  12. # project from scratch. thus, incremental compilation on CI actually
  13. # introduces *additional* overhead to support making future builds
  14. # faster...but no future builds will ever occur in any given CI environment.
  15. #
  16. # see https://matklad.github.io/2021/09/04/fast-rust-builds.html#ci-workflow
  17. # for details.
  18. CARGO_INCREMENTAL: 0
  19. # allow more retries for network requests in cargo (downloading crates) and
  20. # rustup (installing toolchains). this should help to reduce flaky CI failures
  21. # from transient network timeouts or other issues.
  22. CARGO_NET_RETRY: 10
  23. RUSTUP_MAX_RETRIES: 10
  24. # don't emit giant backtraces in the CI logs.
  25. RUST_BACKTRACE: short
  26. RUSTFLAGS: -Dwarnings
  27. msrv: 1.57.0
  28. LOOM_LOG: 'thingbuf=trace,debug'
  29. name: CI
  30. jobs:
  31. changed_paths:
  32. continue-on-error: true
  33. runs-on: ubuntu-latest
  34. outputs:
  35. should_skip: ${{ steps.skip_check.outputs.should_skip }}
  36. steps:
  37. - id: skip_check
  38. uses: fkirc/skip-duplicate-actions@master
  39. with:
  40. do_not_skip: '["workflow_dispatch", "push"]'
  41. paths: '["**/*.rs", "**/Cargo.toml", ".github/workflows/ci.yml"]'
  42. build_no_std:
  43. name: Check no_std
  44. needs: changed_paths
  45. if: needs.changed_paths.outputs.should_skip != 'true'
  46. strategy:
  47. matrix:
  48. feature: [alloc, static]
  49. runs-on: ubuntu-latest
  50. steps:
  51. - uses: actions/checkout@v2
  52. - name: Install toolchain
  53. uses: actions-rs/toolchain@v1
  54. with:
  55. profile: minimal
  56. toolchain: stable
  57. override: true
  58. components: rustfmt
  59. - uses: actions-rs/cargo@v1
  60. with:
  61. command: check
  62. args: --no-default-features --features ${{ matrix.feature }}
  63. tests:
  64. name: Tests
  65. needs: changed_paths
  66. if: needs.changed_paths.outputs.should_skip != 'true'
  67. strategy:
  68. matrix:
  69. # test all Rust versions on Ubuntu
  70. rust: [stable, 1.57.0]
  71. os: [ubuntu-latest]
  72. # test stable Rust on Windows and MacOS as well
  73. include:
  74. - rust: stable
  75. os: windows-latest
  76. - rust: stable
  77. os: macos-latest
  78. runs-on: ${{ matrix.os }}
  79. steps:
  80. - uses: actions/checkout@v2
  81. - name: Install toolchain
  82. uses: actions-rs/toolchain@v1
  83. with:
  84. profile: minimal
  85. toolchain: ${{ matrix.rust }}
  86. override: true
  87. components: rustfmt
  88. - name: Run cargo test (with static APIs)
  89. if: ${{ matrix.rust != env.msrv }}
  90. uses: actions-rs/cargo@v1
  91. with:
  92. command: test
  93. args: --all-features
  94. - name: Run cargo test (no static APIs)
  95. if: ${{ matrix.rust == env.msrv }}
  96. uses: actions-rs/cargo@v1
  97. with:
  98. command: test
  99. # skip doctests, which require all features to be enabled
  100. args: --lib --tests
  101. benches:
  102. name: Compile benchmarks
  103. needs: changed_paths
  104. if: needs.changed_paths.outputs.should_skip != 'true'
  105. runs-on: ubuntu-latest
  106. steps:
  107. - uses: actions/checkout@v2
  108. - name: Install stable toolchain
  109. uses: actions-rs/toolchain@v1
  110. with:
  111. profile: minimal
  112. toolchain: stable
  113. override: true
  114. components: rustfmt
  115. - name: Run cargo check
  116. uses: actions-rs/cargo@v1
  117. with:
  118. command: check
  119. args: -p bench --benches
  120. rustfmt:
  121. runs-on: ubuntu-latest
  122. needs: changed_paths
  123. if: needs.changed_paths.outputs.should_skip != 'true'
  124. steps:
  125. - uses: actions/checkout@v2
  126. - name: Install stable toolchain
  127. uses: actions-rs/toolchain@v1
  128. with:
  129. profile: minimal
  130. toolchain: stable
  131. override: true
  132. components: rustfmt
  133. - name: Run cargo fmt
  134. uses: actions-rs/cargo@v1
  135. with:
  136. command: fmt
  137. args: --all -- --check
  138. clippy_check:
  139. name: Clippy check
  140. needs: changed_paths
  141. if: needs.changed_paths.outputs.should_skip != 'true'
  142. runs-on: ubuntu-latest
  143. steps:
  144. - uses: actions/checkout@v2
  145. - name: Install stable toolchain
  146. uses: actions-rs/toolchain@v1
  147. with:
  148. toolchain: stable
  149. components: clippy
  150. override: true
  151. - uses: actions-rs/clippy-check@v1
  152. with:
  153. token: ${{ secrets.GITHUB_TOKEN }}
  154. # Run particularly slow loom models individually
  155. slow_models:
  156. needs: changed_paths
  157. if: needs.changed_paths.outputs.should_skip != 'true'
  158. strategy:
  159. matrix:
  160. model:
  161. - mpsc_send_recv_wrap
  162. - mpsc_try_send_recv
  163. - mpsc_try_recv_ref
  164. - mpsc_async::rx_close_unconsumed
  165. - mpsc_blocking::rx_close_unconsumed
  166. name: model '${{ matrix.model }}''
  167. runs-on: ubuntu-latest
  168. steps:
  169. - uses: actions/checkout@v2
  170. - name: Install stable toolchain
  171. uses: actions-rs/toolchain@v1
  172. with:
  173. profile: minimal
  174. toolchain: stable
  175. override: true
  176. - name: Run model
  177. run: cargo test --profile loom --lib -- ${{ matrix.model }}
  178. env:
  179. # it would be nice to run these with more preemptions, but
  180. # that makes these models super slow...and LOOM_MAX_PREEMPTIONS=1 is
  181. # good enough for Tokio's CI, so...
  182. LOOM_MAX_PREEMPTIONS: 1
  183. RUSTFLAGS: "--cfg loom"
  184. # Run other loom models by scope
  185. models:
  186. needs: changed_paths
  187. if: needs.changed_paths.outputs.should_skip != 'true'
  188. strategy:
  189. matrix:
  190. scope:
  191. # NOTE: if adding loom models in a new module, that module needs to be
  192. # added to this list!
  193. - mpsc_blocking
  194. - mpsc_async
  195. - thingbuf
  196. - util
  197. name: models in '${{ matrix.scope }}'
  198. runs-on: ubuntu-latest
  199. steps:
  200. - uses: actions/checkout@v2
  201. - name: Install stable toolchain
  202. uses: actions-rs/toolchain@v1
  203. with:
  204. profile: minimal
  205. toolchain: stable
  206. override: true
  207. - name: Run models
  208. run: cargo test --profile loom --lib -- ${{ matrix.scope }}
  209. env:
  210. LOOM_MAX_PREEMPTIONS: 2
  211. # `--cfg ci_skip_slow_models` will exclude the loom models that are
  212. # tested in `slow-models`.
  213. RUSTFLAGS: "--cfg loom --cfg ci_skip_slow_models"
  214. # Dummy job that requires all loom models to pass
  215. all_models:
  216. name: all loom models
  217. runs-on: ubuntu-latest
  218. needs:
  219. - slow_models
  220. - models
  221. steps:
  222. - run: exit 0
  223. miri:
  224. name: Miri tests
  225. needs: changed_paths
  226. if: needs.changed_paths.outputs.should_skip != 'true'
  227. runs-on: ubuntu-latest
  228. steps:
  229. - uses: actions/checkout@v2
  230. - name: Install nightly toolchain
  231. uses: actions-rs/toolchain@v1
  232. with:
  233. profile: minimal
  234. toolchain: nightly
  235. override: true
  236. components: miri
  237. - name: Run Miri tests
  238. run: cargo miri test --lib --no-fail-fast
  239. env:
  240. MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-tag-raw-pointers