_build-rust.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Reusable GitHub CI workflow:
  2. # More info: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iduses
  3. # Common Rust CI setup that checkout the repo, installs the common toolchain
  4. # and set's up the cargo cache. It builds, tests, and lints the code, but is
  5. # configurable. This way, the same workflow can be used to build, test, and lint
  6. # all in different steps, but with the same cache.
  7. on:
  8. workflow_call:
  9. inputs:
  10. runs-on:
  11. type: string
  12. required: false
  13. default: ubuntu-latest
  14. description: |
  15. The value for the "runs-on" property: e.g.
  16. - ubuntu-latest
  17. - windows-latest
  18. rust-version:
  19. type: string
  20. required: false
  21. default: stable
  22. description: Rust version
  23. rust-target:
  24. type: string
  25. required: false
  26. default: x86_64-unknown-linux-gnu
  27. description: Rust target for the build step. Clippy and tests are still executed with the default target.
  28. features:
  29. type: string
  30. required: false
  31. # Make sure we always an empty string to "--features <FEATURES>"
  32. default: '""'
  33. description: >
  34. Comma-separated string with additional crate features. Empty string by
  35. default. CAUTION: For Windows CI runners, this must be '""' as is,
  36. i.e., the string itself must be "". This is a limitation of the
  37. Windows power shell. This might be configured like this:
  38. features: >
  39. '""'
  40. do-style-check:
  41. type: boolean
  42. required: false
  43. default: true
  44. description: Perform code and doc style checks.
  45. do-test:
  46. type: boolean
  47. required: false
  48. default: true
  49. description: Execute tests.
  50. do-miri:
  51. type: boolean
  52. required: false
  53. default: false
  54. description: Execute unit tests with miri.
  55. jobs:
  56. rust:
  57. runs-on: ${{ inputs.runs-on }}
  58. steps:
  59. - name: Check out
  60. uses: actions/checkout@v4
  61. - name: Setup Rust toolchain
  62. uses: dtolnay/rust-toolchain@stable
  63. with:
  64. toolchain: ${{ inputs.rust-version }}
  65. targets: ${{ inputs.rust-target }}
  66. components: clippy, rustfmt
  67. - name: Set up cargo cache
  68. uses: actions/cache@v4
  69. continue-on-error: false
  70. with:
  71. path: |
  72. ~/.cargo/bin/
  73. ~/.cargo/registry/index/
  74. ~/.cargo/registry/cache/
  75. ~/.cargo/git/db/
  76. target/
  77. # Hash over Cargo.toml and Cargo.lock, as this might be copied to
  78. # projects that do not have a Cargo.lock in their repository tree!
  79. key: ${{ runner.os }}-rust-${{ inputs.rust-version }}-cargo-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
  80. - run: cargo version
  81. - name: Build (library)
  82. run: cargo build --target ${{ inputs.rust-target }} --features ${{ inputs.features }} --no-default-features
  83. - name: Build (all targets)
  84. run: cargo build --all-targets --features ${{ inputs.features }} --no-default-features
  85. - name: Code Formatting
  86. if: inputs.do-style-check
  87. run: cargo fmt --all -- --check
  88. - name: Code Style and Doc Style
  89. if: inputs.do-style-check
  90. run: |
  91. cargo doc --no-deps --document-private-items --features ${{ inputs.features }} --no-default-features
  92. cargo clippy --all-targets --features ${{ inputs.features }} --no-default-features
  93. - name: Unit Test
  94. run: cargo test --verbose
  95. - name: Unit Test with Miri
  96. if: inputs.do-miri
  97. run: |
  98. rustup component add miri
  99. # Run with stack-borrow model
  100. # XXX Temporarily, just for multiboot2 crate.
  101. cargo miri test -p multiboot2
  102. # Run with tree-borrow model
  103. # XXX Temporarily, just for multiboot2 crate.
  104. MIRIFLAGS=-Zmiri-tree-borrows cargo +nightly miri test -p multiboot2