Skip to content

GitHub Action

msvc-kit provides an official GitHub Action for easily setting up the MSVC build environment in CI/CD pipelines.

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

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

Inputs

InputDescriptionDefault
msvc-versionMSVC version (empty = latest)""
sdk-versionWindows SDK version (empty = latest)""
archTarget architecturex64
host-archHost architecture (empty = auto-detect)""
install-dirInstallation directory$RUNNER_TEMP/msvc-kit
msvc-kit-versionmsvc-kit binary versionlatest
componentsComponents: all, msvc, or sdkall
verify-hashesVerify file hashestrue
export-envExport env vars to GITHUB_ENVtrue

Outputs

OutputDescription
msvc-versionInstalled MSVC version
sdk-versionInstalled SDK version
install-dirInstallation directory
cl-pathPath to cl.exe
link-pathPath to link.exe
rc-pathPath to rc.exe
include-pathINCLUDE env value
lib-pathLIB env value

Released under the MIT License.