fix: improve Visual Studio Build Tools installation process in Window… #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build-extended-artifacts | |
| on: | |
| push: | |
| branches: | |
| - feature/docker | |
| tags: | |
| - "v*" | |
| pull_request: | |
| branches: | |
| - master | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| docker-images: | |
| name: Build ${{ matrix.variant }} Docker image | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - variant: alpine | |
| dockerfile: docker/Dockerfile.alpine | |
| artifact-name: deepseek-ocr-alpine-bin | |
| - variant: cuda | |
| dockerfile: docker/Dockerfile.cuda | |
| artifact-name: deepseek-ocr-cuda-bin | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build image (${{ matrix.variant }}) | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ${{ matrix.dockerfile }} | |
| push: false | |
| load: true | |
| cache-from: type=gha,scope=${{ matrix.variant }} | |
| cache-to: type=gha,scope=${{ matrix.variant }},mode=max | |
| - name: Extract binaries from image | |
| run: | | |
| mkdir -p artifacts/${{ matrix.variant }} | |
| cid=$(docker create ${{ steps.build.outputs.imageid }}) | |
| docker cp "$cid":/usr/local/bin/deepseek-ocr-cli artifacts/${{ matrix.variant }}/ | |
| docker cp "$cid":/usr/local/bin/deepseek-ocr-server artifacts/${{ matrix.variant }}/ | |
| docker rm "$cid" | |
| - name: Upload binaries (${{ matrix.variant }}) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact-name }} | |
| path: artifacts/${{ matrix.variant }} | |
| - name: Archive binaries (${{ matrix.variant }}) | |
| run: tar -czf ${{ matrix.variant }}-linux.tar.gz -C artifacts/${{ matrix.variant }} . | |
| - name: Publish release asset (${{ matrix.variant }}) | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: ${{ matrix.variant }}-linux.tar.gz | |
| windows-cuda-binaries: | |
| name: Build Windows CUDA binaries | |
| runs-on: windows-latest | |
| timeout-minutes: 120 | |
| env: | |
| CUDA_COMPUTE_CAP: "80" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~\.cargo\registry | |
| ~\.cargo\git | |
| key: windows-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| windows-cargo- | |
| - name: Install CUDA Toolkit 12.2 | |
| shell: pwsh | |
| run: | | |
| choco install cuda --version=12.2.0.53625 --no-progress -y --params '"/NoDriver"' | |
| - name: Install Visual Studio Build Tools components | |
| shell: pwsh | |
| run: | | |
| choco install visualstudio2022buildtools --no-progress -y --installargs '--add Microsoft.VisualStudio.Workload.VCTools --quiet --norestart' | |
| $vsInstaller = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" | |
| if (Test-Path $vsInstaller) { | |
| Start-Process -FilePath $vsInstaller -ArgumentList @( | |
| 'modify', | |
| '--installPath', 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools', | |
| '--add', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', | |
| '--quiet', '--norestart' | |
| ) -Wait | |
| } | |
| $vsInstallRoot = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" | |
| if (-not (Test-Path $vsInstallRoot)) { | |
| $vsInstallRoot = "C:\Program Files\Microsoft Visual Studio\2022\BuildTools" | |
| } | |
| $clRoot = Join-Path $vsInstallRoot 'VC\Tools\MSVC' | |
| if (-not (Test-Path $clRoot)) { throw "MSVC toolchain not found after installation" } | |
| $vcVersion = Get-ChildItem $clRoot | Sort-Object Name -Descending | Select-Object -First 1 | |
| if (-not $vcVersion) { throw "Unable to locate installed MSVC version" } | |
| $binDir = Join-Path $vcVersion.FullName 'bin\Hostx64\x64' | |
| Add-Content $env:GITHUB_PATH $binDir | |
| Add-Content $env:GITHUB_ENV "VCToolsInstallDir=$($vcVersion.FullName)" | |
| - name: Configure CUDA environment | |
| shell: pwsh | |
| run: | | |
| $defaultPath = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA" | |
| if (Test-Path $defaultPath) { | |
| $versions = Get-ChildItem $defaultPath -Directory | Sort-Object Name -Descending | |
| $match = $versions | Where-Object { $_.Name -eq 'v12.2' } | Select-Object -First 1 | |
| if (-not $match) { $match = $versions | Select-Object -First 1 } | |
| if ($match) { | |
| Add-Content $env:GITHUB_ENV "CUDA_PATH=$($match.FullName)" | |
| Add-Content $env:GITHUB_PATH "$($match.FullName)\bin" | |
| Add-Content $env:GITHUB_PATH "$($match.FullName)\libnvvp" | |
| return | |
| } | |
| } | |
| throw "Unable to locate CUDA installation under $defaultPath" | |
| - name: Build CLI with CUDA | |
| shell: pwsh | |
| run: cargo build --locked --release --no-default-features --features cuda -p deepseek-ocr-cli | |
| - name: Build server with CUDA | |
| shell: pwsh | |
| run: cargo build --locked --release --no-default-features --features cuda -p deepseek-ocr-server | |
| - name: Collect CUDA binaries | |
| shell: pwsh | |
| run: | | |
| New-Item -ItemType Directory -Force -Path artifacts\windows-cuda | Out-Null | |
| Copy-Item target\release\deepseek-ocr-cli.exe artifacts\windows-cuda\ | |
| Copy-Item target\release\deepseek-ocr-server.exe artifacts\windows-cuda\ | |
| - name: Upload CUDA Windows binaries | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: deepseek-ocr-windows-cuda | |
| path: artifacts\windows-cuda | |
| - name: Package CUDA Windows binaries | |
| shell: pwsh | |
| run: | | |
| Compress-Archive -Path artifacts\windows-cuda\* -DestinationPath windows-cuda.zip -Force | |
| - name: Publish release asset (Windows CUDA) | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: windows-cuda.zip |