# CI/CD Integration
msvc-kit is designed for CI/CD pipelines where installing Visual Studio is impractical.
## GitHub Actions (Recommended)
The easiest way to use msvc-kit in GitHub Actions is the official action:
### Basic Usage
```yaml
name: Build
on: [push, pull_request]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup MSVC Build Tools
uses: loonghao/msvc-kit@v1
with:
arch: x64
- name: Build
run: |
cl /nologo test.c
```
### With Specific Versions
```yaml
- name: Setup MSVC Build Tools
uses: loonghao/msvc-kit@v1
with:
msvc-version: "14.44"
sdk-version: "10.0.26100.0"
arch: x64
```
### Matrix Build
```yaml
name: Matrix Build
on: [push]
jobs:
build:
runs-on: windows-latest
strategy:
matrix:
arch: [x64, x86, arm64]
steps:
- uses: actions/checkout@v4
- name: Setup MSVC Build Tools
id: msvc
uses: loonghao/msvc-kit@v1
with:
arch: ${{ matrix.arch }}
- name: Show installed versions
run: |
echo "MSVC: ${{ steps.msvc.outputs.msvc-version }}"
echo "SDK: ${{ steps.msvc.outputs.sdk-version }}"
echo "cl.exe: ${{ steps.msvc.outputs.cl-path }}"
```
### With Caching
```yaml
- name: Cache MSVC
uses: actions/cache@v4
with:
path: ${{ steps.msvc.outputs.install-dir }}
key: msvc-${{ matrix.arch }}-${{ steps.msvc.outputs.msvc-version }}
- name: Setup MSVC Build Tools
id: msvc
uses: loonghao/msvc-kit@v1
with:
arch: ${{ matrix.arch }}
```
### Rust + cc-rs Integration
The action automatically sets `CC` and `CXX` environment variables for seamless Rust/cc-rs compatibility:
```yaml
- name: Setup MSVC Build Tools
uses: loonghao/msvc-kit@v1
with:
arch: x64
- name: Build Rust project with C dependencies
run: cargo build --release
```
### Action Inputs
| `msvc-version` | MSVC version (empty = latest) | `""` |
| `sdk-version` | Windows SDK version (empty = latest) | `""` |
| `arch` | Target architecture | `x64` |
| `host-arch` | Host architecture (empty = auto-detect) | `""` |
| `install-dir` | Installation directory | `$RUNNER_TEMP/msvc-kit` |
| `msvc-kit-version` | msvc-kit binary version | `latest` |
| `components` | Components: `all`, `msvc`, or `sdk` | `all` |
| `verify-hashes` | Verify file hashes | `true` |
| `export-env` | Export env vars to GITHUB_ENV | `true` |
### Action Outputs
| `msvc-version` | Installed MSVC version |
| `sdk-version` | Installed SDK version |
| `install-dir` | Installation directory |
| `cl-path` | Path to cl.exe |
| `link-path` | Path to link.exe |
| `rc-path` | Path to rc.exe |
| `include-path` | INCLUDE env value |
| `lib-path` | LIB env value |
## GitHub Actions (Manual CLI)
If you prefer manual control, you can use the CLI directly:
### Basic Setup
```yaml
name: Build
on: [push, pull_request]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-action@stable
- name: Install msvc-kit
run: cargo install msvc-kit
- name: Download MSVC
run: msvc-kit download
- name: Setup Environment
run: msvc-kit setup --script --shell powershell | Invoke-Expression
- name: Build
run: cargo build --release
```
### With Caching
```yaml
name: Build with Cache
on: [push, pull_request]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Cache msvc-kit
uses: actions/cache@v4
with:
path: |
~\AppData\Local\loonghao\msvc-kit
key: msvc-kit-${{ runner.os }}-v14.44
- name: Install msvc-kit
run: cargo install msvc-kit
- name: Download MSVC (cached)
run: msvc-kit download --msvc-version 14.44 --sdk-version 10.0.26100.0
- name: Setup Environment
run: msvc-kit setup --script --shell powershell | Invoke-Expression
- name: Build
run: cargo build --release
```
### Matrix Build
```yaml
name: Matrix Build
on: [push]
jobs:
build:
runs-on: windows-latest
strategy:
matrix:
arch: [x64, x86, arm64]
steps:
- uses: actions/checkout@v4
- name: Install msvc-kit
run: cargo install msvc-kit
- name: Download MSVC for ${{ matrix.arch }}
run: msvc-kit download --arch ${{ matrix.arch }}
- name: Setup Environment
run: msvc-kit setup --script --shell powershell | Invoke-Expression
- name: Build
run: cargo build --release --target ${{ matrix.arch }}-pc-windows-msvc
```
## Azure Pipelines
```yaml
trigger:
- main
pool:
vmImage: 'windows-latest'
steps:
- task: RustInstaller@1
inputs:
rustVersion: 'stable'
- script: cargo install msvc-kit
displayName: 'Install msvc-kit'
- script: msvc-kit download
displayName: 'Download MSVC'
- powershell: msvc-kit setup --script --shell powershell | Invoke-Expression
displayName: 'Setup Environment'
- script: cargo build --release
displayName: 'Build'
```
## GitLab CI
```yaml
build:
image: mcr.microsoft.com/windows/servercore:ltsc2022
tags:
- windows
script:
- choco install rust -y
- cargo install msvc-kit
- msvc-kit download
- $env = msvc-kit env --format json | ConvertFrom-Json
- $env.PSObject.Properties | ForEach-Object { Set-Item "env:$($_.Name)" $_.Value }
- cargo build --release
```
## Docker
### Dockerfile
```dockerfile
FROM mcr.microsoft.com/windows/servercore:ltsc2022
# Install Rust
RUN powershell -Command \
Invoke-WebRequest -Uri https://win.rustup.rs -OutFile rustup-init.exe; \
./rustup-init.exe -y --default-toolchain stable
# Install msvc-kit
RUN cargo install msvc-kit
# Download MSVC (cached in image layer)
RUN msvc-kit download
# Setup environment
SHELL ["powershell", "-Command"]
RUN msvc-kit setup --persistent
WORKDIR /app
```
## Tips
### Reduce Download Time
1. **Cache aggressively** - MSVC downloads are large but stable
2. **Pin versions** - Avoid re-downloading when versions change
3. **Use parallel downloads** - `--parallel-downloads 8`
### Reduce Image Size
1. **Clear cache after install** - `msvc-kit clean --cache`
2. **Download only what you need** - `--no-sdk` if SDK not needed
### Debugging
Enable verbose logging:
```yaml
- name: Download MSVC (verbose)
run: |
$env:RUST_LOG = "msvc_kit=debug"
msvc-kit download
```