rust.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. name: CI
  2. on:
  3. push:
  4. branches: [ "main" ]
  5. pull_request:
  6. branches: [ "main" ]
  7. workflow_dispatch:
  8. env:
  9. CARGO_UNSTABLE_SPARSE_REGISTRY: true
  10. CARGO_TERM_COLOR: always
  11. jobs:
  12. fmt:
  13. name: Rustfmt
  14. runs-on: ubuntu-latest
  15. steps:
  16. - uses: actions/checkout@v4
  17. - uses: actions-rs/toolchain@v1
  18. with:
  19. profile: minimal
  20. toolchain: stable
  21. override: true
  22. components: rustfmt
  23. - name: Cache Dependencies
  24. uses: Swatinem/rust-cache@v2
  25. - uses: actions-rs/cargo@v1
  26. with:
  27. command: fmt
  28. args: --all -- --check
  29. check-stable:
  30. name: Check rustsbi (stable)
  31. runs-on: ubuntu-latest
  32. needs: fmt
  33. strategy:
  34. matrix:
  35. TARGET: [riscv64imac-unknown-none-elf, riscv32imac-unknown-none-elf]
  36. steps:
  37. - uses: actions/checkout@v4
  38. - uses: actions-rs/toolchain@v1
  39. with:
  40. profile: minimal
  41. toolchain: stable
  42. override: true
  43. target: ${{ matrix.TARGET }}
  44. - name: Cache Dependencies
  45. uses: Swatinem/rust-cache@v2
  46. with:
  47. key: ${{ matrix.TARGET }}
  48. - name: Check (no default features)
  49. uses: actions-rs/cargo@v1
  50. with:
  51. command: check
  52. args: --target ${{ matrix.TARGET }} --verbose -p rustsbi
  53. - name: Check crate rustsbi (machine)
  54. uses: actions-rs/cargo@v1
  55. with:
  56. command: check
  57. args: --target ${{ matrix.TARGET }} --features "machine" --verbose -p rustsbi
  58. - name: Check crate rustsbi (forward)
  59. uses: actions-rs/cargo@v1
  60. with:
  61. command: check
  62. args: --target ${{ matrix.TARGET }} --features "forward" --verbose -p rustsbi
  63. - name: Check crate rustsbi (machine + forward)
  64. uses: actions-rs/cargo@v1
  65. with:
  66. command: check
  67. args: --target ${{ matrix.TARGET }} --features "machine, forward" --verbose -p rustsbi
  68. check-nightly:
  69. name: Check rustsbi (nightly)
  70. runs-on: ubuntu-latest
  71. needs: fmt
  72. strategy:
  73. matrix:
  74. TARGET: [riscv64imac-unknown-none-elf, riscv32imac-unknown-none-elf]
  75. steps:
  76. - uses: actions/checkout@v4
  77. - uses: actions-rs/toolchain@v1
  78. with:
  79. profile: minimal
  80. toolchain: nightly
  81. override: true
  82. target: ${{ matrix.TARGET }}
  83. - name: Cache Dependencies
  84. uses: Swatinem/rust-cache@v2
  85. with:
  86. key: ${{ matrix.TARGET }}
  87. tests:
  88. name: Test rustsbi
  89. needs: fmt
  90. runs-on: ubuntu-latest
  91. steps:
  92. - uses: actions/checkout@v4
  93. - uses: actions-rs/toolchain@v1
  94. with:
  95. profile: minimal
  96. toolchain: stable
  97. components: clippy
  98. override: true
  99. - name: Cache Dependencies
  100. uses: Swatinem/rust-cache@v2
  101. - name: Clippy
  102. uses: actions-rs/cargo@v1
  103. with:
  104. command: clippy
  105. args: -p rustsbi
  106. - name: Run tests (no default features)
  107. uses: actions-rs/cargo@v1
  108. with:
  109. command: test
  110. args: --verbose -p rustsbi
  111. - name: Run tests (machine)
  112. uses: actions-rs/cargo@v1
  113. with:
  114. command: test
  115. args: --features "machine" --verbose -p rustsbi
  116. sbi-spec:
  117. name: Test sbi-spec
  118. needs: fmt
  119. runs-on: ubuntu-latest
  120. strategy:
  121. fail-fast: false
  122. matrix:
  123. target:
  124. [
  125. riscv32imac-unknown-none-elf,
  126. riscv64imac-unknown-none-elf,
  127. x86_64-unknown-none,
  128. ]
  129. steps:
  130. - uses: actions/checkout@v3
  131. # Cache REF:
  132. # - https://github.com/actions/cache/blob/main/examples.md#rust---cargo
  133. # - https://github.com/actions-rs/toolchain/issues/54
  134. - name: Cache Rust
  135. uses: actions/cache@v3
  136. with:
  137. key: rust-toolchain-${{ matrix.target }}
  138. path: |
  139. ~/.rustup/settings.toml
  140. ~/.rustup/toolchains/stable-*
  141. ~/.rustup/update-hashes/stable-*
  142. ~/.cargo/bin/
  143. ~/.cargo/registry/index/
  144. ~/.cargo/registry/cache/
  145. ~/.cargo/git/db/
  146. target/
  147. - name: Setup Rust
  148. run: |
  149. rustup toolchain install stable --profile minimal
  150. rustup component add rustfmt clippy
  151. rustup target add ${{ matrix.target }}
  152. - name: Check format
  153. run: cargo fmt --all --check -p sbi-spec
  154. - name: Check clippy
  155. run: cargo clippy -- -D warnings -p sbi-spec
  156. - name: Check build
  157. run: cargo build -p sbi-spec
  158. - name: Check test
  159. run: cargo test -p sbi-spec