Skip to content

Commit 2f7ee94

Browse files
committed
add CI configs for msvc build
1 parent f81d768 commit 2f7ee94

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

.ci/scripts/setup-windows-msvc.ps1

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
conda create --yes --quiet -n et python=3.12
2+
conda activate et
3+
4+
# Activate the VS environment - this is required for MSVC to work
5+
# There are a bunch of environment variables that it requires.
6+
# See https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line.
7+
& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64
8+
9+
# Install CI requirements
10+
pip install -r .ci/docker/requirements-ci.txt
11+
12+
# Create build directory
13+
$buildDir = "cmake-out-msvc"
14+
if (Test-Path -Path $buildDir) {
15+
Remove-Item -Path $buildDir -Recurse -Force
16+
}
17+
New-Item -Path $buildDir -ItemType Directory
18+
19+
# Configure CMake with MSVC (not ClangCL) and disable custom/quantized ops
20+
cmake -S . -B $buildDir `
21+
-DCMAKE_BUILD_TYPE=Release `
22+
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON `
23+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON `
24+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON `
25+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON `
26+
-DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON `
27+
-DEXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP=ON `
28+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON `
29+
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=OFF `
30+
-DEXECUTORCH_BUILD_KERNELS_CUSTOM_AOT=OFF `
31+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=OFF `
32+
-DEXECUTORCH_BUILD_XNNPACK=ON `
33+
-DEXECUTORCH_BUILD_EXTENSION_LLM=ON `
34+
-DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON
35+
36+
if ($LASTEXITCODE -ne 0) {
37+
Write-Host "CMake configuration failed. Exit code: $LASTEXITCODE."
38+
exit $LASTEXITCODE
39+
}
40+
41+
# Build with MSVC
42+
cmake --build $buildDir --config Release -j16
43+
44+
if ($LASTEXITCODE -ne 0) {
45+
Write-Host "Build failed. Exit code: $LASTEXITCODE."
46+
exit $LASTEXITCODE
47+
}
48+
49+
Write-Host "MSVC build completed successfully!"

.github/workflows/windows-msvc.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Windows MSVC Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release/*
8+
tags:
9+
- ciflow/trunk/*
10+
pull_request:
11+
paths:
12+
- .ci/docker/ci_commit_pins/pytorch.txt
13+
- .ci/scripts/**
14+
workflow_dispatch:
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
build-windows-msvc:
22+
name: build-windows-msvc
23+
uses: pytorch/test-infra/.github/workflows/windows_job.yml@main
24+
with:
25+
submodules: 'recursive'
26+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
27+
timeout: 60
28+
script: |
29+
conda init powershell
30+
31+
powershell -Command "& {
32+
Set-PSDebug -Trace 1
33+
\$ErrorActionPreference = 'Stop'
34+
\$PSNativeCommandUseErrorActionPreference = \$true
35+
36+
.ci/scripts/setup-windows-msvc.ps1
37+
}"

setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,14 @@ def run(self): # noqa C901
751751
f"-DCMAKE_BUILD_TYPE={cmake_build_type}",
752752
]
753753

754-
# Use ClangCL on Windows.
754+
# Use ClangCL on Windows by default, unless EXECUTORCH_USE_MSVC is set.
755755
if _is_windows():
756-
cmake_configuration_args += ["-T ClangCL"]
756+
if os.environ.get("EXECUTORCH_USE_MSVC"):
757+
# Use default MSVC toolchain
758+
pass
759+
else:
760+
# Use ClangCL toolchain
761+
cmake_configuration_args += ["-T ClangCL"]
757762

758763
# Allow adding extra cmake args through the environment. Used by some
759764
# tests and demos to expand the set of targets included in the pip

0 commit comments

Comments
 (0)