|
| 1 | +name: Build Rust SDK |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + platform: |
| 7 | + required: false |
| 8 | + type: string |
| 9 | + default: 'ubuntu' # or 'windows' or 'macos' |
| 10 | + useWinML: |
| 11 | + required: false |
| 12 | + type: boolean |
| 13 | + default: false |
| 14 | + run-integration-tests: |
| 15 | + required: false |
| 16 | + type: boolean |
| 17 | + default: true |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + runs-on: ${{ inputs.platform }}-latest |
| 25 | + |
| 26 | + defaults: |
| 27 | + run: |
| 28 | + working-directory: sdk_v2/rust |
| 29 | + |
| 30 | + env: |
| 31 | + CARGO_FEATURES: ${{ inputs.useWinML && '--features winml' || '' }} |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Checkout repository |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + clean: true |
| 38 | + |
| 39 | + - name: Install Rust toolchain |
| 40 | + uses: dtolnay/rust-toolchain@stable |
| 41 | + with: |
| 42 | + components: clippy, rustfmt |
| 43 | + |
| 44 | + - name: Cache cargo dependencies |
| 45 | + uses: Swatinem/rust-cache@v2 |
| 46 | + with: |
| 47 | + workspaces: sdk_v2/rust -> target |
| 48 | + |
| 49 | + - name: Checkout test-data-shared from Azure DevOps |
| 50 | + if: ${{ inputs.run-integration-tests }} |
| 51 | + shell: pwsh |
| 52 | + working-directory: ${{ github.workspace }}/.. |
| 53 | + run: | |
| 54 | + $pat = "${{ secrets.AZURE_DEVOPS_PAT }}" |
| 55 | + $encodedPat = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat")) |
| 56 | + |
| 57 | + # Configure git to use the PAT |
| 58 | + git config --global http.https://dev.azure.com.extraheader "AUTHORIZATION: Basic $encodedPat" |
| 59 | + |
| 60 | + # Clone with LFS to parent directory |
| 61 | + git lfs install |
| 62 | + git clone --depth 1 https://dev.azure.com/microsoft/windows.ai.toolkit/_git/test-data-shared test-data-shared |
| 63 | + |
| 64 | + Write-Host "Clone completed successfully to ${{ github.workspace }}/../test-data-shared" |
| 65 | +
|
| 66 | + - name: Checkout specific commit in test-data-shared |
| 67 | + if: ${{ inputs.run-integration-tests }} |
| 68 | + shell: pwsh |
| 69 | + working-directory: ${{ github.workspace }}/../test-data-shared |
| 70 | + run: | |
| 71 | + Write-Host "Current directory: $(Get-Location)" |
| 72 | + git checkout 231f820fe285145b7ea4a449b112c1228ce66a41 |
| 73 | + if ($LASTEXITCODE -ne 0) { |
| 74 | + Write-Error "Git checkout failed." |
| 75 | + exit 1 |
| 76 | + } |
| 77 | + Write-Host "`nDirectory contents:" |
| 78 | + Get-ChildItem -Recurse -Depth 2 | ForEach-Object { Write-Host " $($_.FullName)" } |
| 79 | +
|
| 80 | + - name: Check formatting |
| 81 | + run: cargo fmt --all -- --check |
| 82 | + |
| 83 | + # Run Clippy - Rust's official linter for catching common mistakes, enforcing idioms, and improving code quality |
| 84 | + - name: Run clippy |
| 85 | + run: cargo clippy --all-targets ${{ env.CARGO_FEATURES }} -- -D warnings |
| 86 | + |
| 87 | + - name: Build |
| 88 | + run: cargo build ${{ env.CARGO_FEATURES }} |
| 89 | + |
| 90 | + - name: Run unit tests |
| 91 | + run: cargo test --lib ${{ env.CARGO_FEATURES }} |
| 92 | + |
| 93 | + - name: Run integration tests |
| 94 | + if: ${{ inputs.run-integration-tests }} |
| 95 | + run: cargo test --tests ${{ env.CARGO_FEATURES }} -- --include-ignored --test-threads=1 --nocapture |
| 96 | + |
| 97 | + # --allow-dirty allows publishing with uncommitted changes, needed because the build process modifies generated files |
| 98 | + - name: Package crate |
| 99 | + run: cargo package ${{ env.CARGO_FEATURES }} --allow-dirty |
| 100 | + |
| 101 | + - name: Upload SDK artifact |
| 102 | + uses: actions/upload-artifact@v4 |
| 103 | + with: |
| 104 | + name: rust-sdk-${{ inputs.platform }}${{ inputs.useWinML == true && '-winml' || '' }} |
| 105 | + path: sdk_v2/rust/target/package/*.crate |
| 106 | + |
| 107 | + - name: Upload flcore logs |
| 108 | + uses: actions/upload-artifact@v4 |
| 109 | + if: always() |
| 110 | + with: |
| 111 | + name: rust-sdk-${{ inputs.platform }}${{ inputs.useWinML == true && '-winml' || '' }}-logs |
| 112 | + path: sdk_v2/rust/logs/** |
0 commit comments