Skip to content
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
4bb3a6a
First windows build implementation draft
lorisercole Apr 8, 2026
f389884
Fix MSCVC Build Tools finder + vcpkg
lorisercole Apr 8, 2026
2e1214d
Add vcpkg installed folders to gitignore
lorisercole Apr 8, 2026
da340c4
force LF for patch files
lorisercole Apr 9, 2026
ff907c3
Add vcpkg-overlay of OpenBLAS to build LAPACK
lorisercole Apr 9, 2026
ce6b7ee
Debug compilation with clang-cl
lorisercole Apr 9, 2026
2017548
Script to test the build on Windows
lorisercole Apr 9, 2026
2b7670e
Fix HDF5 type portability bugs for Windows (LLP64)
lorisercole Apr 9, 2026
07cfa17
Fix Windows file locking in Hamiltonian FCIDUMP tests
lorisercole Apr 9, 2026
134e87e
Fix uninitialized Shell::rpowers and broken BasisSetMap test
lorisercole Apr 10, 2026
12fae31
adding additional warning-silence flags for deps
lorisercole Apr 10, 2026
5d3d3e7
Fix Python package build and DLL loading on Windows
lorisercole Apr 10, 2026
e1b2262
Fix encoding for reading example file content in tests
lorisercole Apr 10, 2026
cadd8ba
Fix Windows file locking in Python tests
lorisercole Apr 13, 2026
75bd327
Fix license header hook Unicode error on Windows
lorisercole Apr 13, 2026
2ecbe80
Fix spdlog Logger stdout capture on Windows for pytest capfd
lorisercole Apr 13, 2026
bb2214c
fix: harden Python package and tests against Windows encoding issues
lorisercole Apr 13, 2026
9ef5d29
test: skip PySCF-dependent MC entropy test if PySCF is not available
lorisercole Apr 13, 2026
c75ccc1
update build scripts and pyproject
lorisercole Apr 13, 2026
bbd0c0a
test_sample_workflow: add PySCF availability check
lorisercole Apr 14, 2026
37cba5c
fix: use non-interactive matplotlib backend in tests
lorisercole Apr 14, 2026
2f6e05c
enforce LF line endings for all text files via .gitattributes
lorisercole Apr 14, 2026
1b0de73
apply pre-commit hooks
lorisercole Apr 14, 2026
7a55684
test: run doc examples in a temporary directory
lorisercole Apr 14, 2026
9ae0e86
update PS scripts, build with pip directly
lorisercole Apr 14, 2026
f51b499
enable OpenMP on Windows, disable it for GauXC due to data race
lorisercole Apr 17, 2026
ebb1222
set and cleanup CMake compilation flags
lorisercole Apr 20, 2026
bdff54e
Reset pipeline files, move PS1 build scripts, cleanup
lorisercole Apr 20, 2026
fbcba9e
mypy: ignore type checking for DLL directory addition on Windows
lorisercole Apr 20, 2026
c7e4d1c
Address Copilot comments
lorisercole Apr 21, 2026
ff8e0ce
Bundle vcpkg DLLs into Python wheel on Windows
lorisercole Apr 21, 2026
ed5350b
macis types.hpp: add comparison and bitwise operators to uint128_t st…
lorisercole Apr 21, 2026
058dfa8
Merge branch 'main' into feature/ler/windows-build-part-1
lorisercole Apr 22, 2026
03638ca
Fix test_noise_models due to change in QuantumErrorProfile API
lorisercole Apr 22, 2026
a056aa1
Apply suggestion from @Copilot
lorisercole Apr 22, 2026
83875e4
Address Copilot's comments about coverage flags w/ MSVC
lorisercole Apr 22, 2026
f8de7de
fix @Copilot's badly formatted code
lorisercole Apr 22, 2026
1be559f
Refine Windows DLL bundling: explicit list, skip libomp, add toggle
lorisercole Apr 22, 2026
82be64b
Cleanup DLL loading in Python package
lorisercole Apr 24, 2026
3015e25
Use static linking of vcpkg deps on Windows (x64-windows-static-md) b…
lorisercole Apr 24, 2026
97d211b
Apply suggestion from @Copilot
lorisercole Apr 24, 2026
2f20859
address @Copilot's comments
lorisercole Apr 24, 2026
0e1ea14
MSVC build attempt
lorisercole Apr 24, 2026
bd3176b
Cleanup qdk-uarch cmake file
lorisercole Apr 29, 2026
563f0a0
add patches included by previous commit
lorisercole Apr 30, 2026
68ef68b
include catch2 ang gtest in vcpkg install
lorisercole Apr 30, 2026
649a35d
Patch libint2 to work with MSVC compiler
lorisercole Apr 30, 2026
be1c8dd
temporarily use patched GauXC branch
lorisercole Apr 30, 2026
e0ae7d5
Fix OpenMP flags for MSVC: use /openmp:llvm + /openmp:experimental
lorisercole Apr 30, 2026
5187a92
Replace GCC statement expressions with named lambdas for MSVC compat
lorisercole Apr 30, 2026
ec0e4e8
and also macis-uarch.cmake
lorisercole Apr 30, 2026
4122a8a
Merge branch 'feature/ler/windows-build-part-1' into feature/ler/wind…
lorisercole Apr 30, 2026
727f311
address several comments
lorisercole May 4, 2026
401d2e8
Move stdout_fd_sink class into logger module
lorisercole May 4, 2026
c5a071f
vcpkg: install catch2 & gtest
lorisercole May 5, 2026
027c2a8
pre-commit config: exclude patch files from trailing whitespace and e…
lorisercole May 6, 2026
77475bd
Fix blaspp BLAS_FORTRAN_ADD_ detection on reconfigure + lapackpp complex
lorisercole May 6, 2026
27df5dd
add MACIS_ENABLE_TESTS option to control building of MACIS tests
lorisercole May 6, 2026
043f620
Fix -Wdefaulted-function-deleted warnings in Structure and ERIMultipl…
lorisercole May 6, 2026
63a46a9
Add missing override specifiers to virtual function overrides
lorisercole May 6, 2026
971941a
Fix -Wreorder-ctor warnings by matching initializer list to declarati…
lorisercole May 6, 2026
0b7b049
Simplify CMake compiler flags and remove global warning suppression
lorisercole May 7, 2026
efea89b
Update Cmake, use /W3 and compliant warning flags
lorisercole Jun 11, 2026
8b85537
Merge branch 'feature/ler/windows-build-part-2-msvc' into feature/ler…
lorisercole Jun 12, 2026
6646c5f
Scope MSVC compile flags and suppress dependency warnings
lorisercole Jun 12, 2026
75dc780
Consolidate blaspp MSVC patches into single unified diff
lorisercole Jun 15, 2026
e4da238
small fixes
lorisercole Jun 16, 2026
ce3c7a7
Merge branch 'main' into feature/ler/windows-build-part-1
lorisercole Jun 16, 2026
cea1db2
Guard OpenMP array-section reductions for native MSVC
lorisercole Jun 17, 2026
fbce3e0
Tune Windows MSVC build parallelism and suppress noisy warnings
lorisercole Jun 17, 2026
08fdb71
Drop OpenMP 5.0 atomic memory-order modifier for native MSVC
lorisercole Jun 17, 2026
fc63a40
Raise gtest discovery timeout to 60s
lorisercole Jun 17, 2026
288355d
Add /Zc:__cplusplus to libint2 eritest target for MSVC
lorisercole Jun 17, 2026
2272ef9
Pass --force-local to tar on Windows to handle drive-letter paths
lorisercole Jun 17, 2026
2cc5974
Close H5File before std::filesystem::remove in HDF5 round-trip tests
lorisercole Jun 17, 2026
5b128d5
Skip MSVC target_compile_options on IMPORTED libint2/ecpint targets
lorisercole Jun 17, 2026
9af56ea
Scope HDF5 handles before remove() in symmetry tensor tests
lorisercole Jun 17, 2026
34f808a
Fix BasisSet copy constructor missing _ecp_name member
lorisercole Jun 17, 2026
ac140c7
Reduce OMP_NUM_THREADS to 2 for C++ and Python tests; log output to r…
lorisercole Jun 17, 2026
0481093
Add -Debug switch to MSVC build script
lorisercole Jun 17, 2026
b790005
Add MSVC compiler patches and build script fixes
lorisercole Jun 18, 2026
81cee61
Fix MSVC Release MACIS crash: replace omp atomic capture with critical
lorisercole Jun 18, 2026
72f4098
Fix Python extension crash: use LLVM OpenMP runtime to match C++ library
lorisercole Jun 18, 2026
fc8e3a5
Fix Windows file locking in test_majorana_mapping HDF5 tests
lorisercole Jun 18, 2026
30f806c
Enable MACIS tests
lorisercole Jun 18, 2026
6599515
Skip test_settings AlgorithmRef tests that require PySCF
lorisercole Jun 18, 2026
95ddd96
Skip notebook tests that require PySCF
lorisercole Jun 18, 2026
8c01976
Capture clang-cl ctest/pytest output to log files
lorisercole Jun 18, 2026
0faff74
Find clang-cl in standalone LLVM installations
lorisercole Jun 18, 2026
dbb68cb
Use [test] extra for Windows Python install and skip pyscf on Windows
lorisercole Jun 19, 2026
0d97589
fix: detect tar flavor at runtime before using --force-local on Windows
lorisercole Jun 22, 2026
12870e3
Merge branch 'main' into feature/ler/windows-build-part-1
lorisercole Jun 22, 2026
076ccb2
fix(C4700): remove collapse(2) from triangular OpenMP loop
lorisercole Jun 22, 2026
7dafc2c
fix(C4996): replace deprecated INSTANTIATE_TEST_CASE_P with INSTANTIA…
lorisercole Jun 22, 2026
575f794
fix(C4100): mark metis_kway_partitioning params [[maybe_unused]]
lorisercole Jun 23, 2026
21cdfd1
fix(C4267): use size_t{0} instead of 0ul in std::accumulate init
lorisercole Jun 23, 2026
9d75747
fix(C4996): use sscanf_s on MSVC in fcidump line parsers
lorisercole Jun 23, 2026
976fb39
fix(C4389): cast H.m()/H.nnz() to size_t before comparing to size_t l…
lorisercole Jun 23, 2026
d322b96
fix(C4018): fix signed/unsigned comparisons in mask_constraints.hpp
lorisercole Jun 23, 2026
b8974aa
fix(C4701): initialise nalpha/nbeta to 0 to suppress C4701
lorisercole Jun 23, 2026
572fec8
Merge branch 'main' into feature/ler/windows-build-part-1
lorisercole Jun 23, 2026
d8f92f1
fix(tests): use delete=False for NamedTemporaryFile in HDF5 test
lorisercole Jun 23, 2026
1e4f67d
test: mark test_spectral_validation_2x2_hubbard as slow
lorisercole Jun 23, 2026
c1617b3
fix(C4834): cast CHARGE_TO_SYMBOL.at() to void inside EXPECT_NO_THROW
lorisercole Jun 23, 2026
7bcd98d
fix(C4305): change MP2 reference values from float to double
lorisercole Jun 23, 2026
37149c0
fix(C4552): suppress unused-result warning for rdm_op.rdms() + E_inac…
lorisercole Jun 23, 2026
28f7238
fix(C4068): guard #pragma GCC diagnostic with #ifndef _MSC_VER
lorisercole Jun 23, 2026
8be399f
fix(build): pass full clang-cl path to uv pip install
lorisercole Jun 23, 2026
00c23a8
delete: remove Windows build script for Clang and pip
lorisercole Jun 23, 2026
dc8fd20
fix(build): silence -Wno-everything on blaspp/lapackpp under clang-cl
lorisercole Jun 23, 2026
ec09b0e
fix(build): silence clang-cl warnings in ecpint, gauxc, libint2 deps
lorisercole Jun 23, 2026
6b37d6f
fix(clang-cl): patch blaspp/lapackpp to not add -Wall on clang-cl
lorisercole Jun 24, 2026
9009217
fix(clang-cl): unify MSVC/clang-cl warning suppression for third-part…
lorisercole Jun 24, 2026
b3bbe49
fix(clang-cl): fix -Wreorder-ctor in BasisSet and WavefunctionContainer
lorisercole Jun 24, 2026
b55d9f2
fix(clang-cl): suppress -Wunused-variable in external/macis
lorisercole Jun 24, 2026
458fddb
update GHD runners
lorisercole Jun 24, 2026
1b3b542
temporarily disable C++ deps caching
lorisercole Jun 24, 2026
6474c4f
feat(build): add -BuildType parameter supporting RelWithDebInfo
lorisercole Jun 24, 2026
3e39610
Revert "temporarily disable C++ deps caching"
lorisercole Jun 24, 2026
9e8d8c9
Remove unused natom/nharmonics variables in GAUXC::eval_dd_psi
lorisercole Jun 24, 2026
b126f90
Fix pre-commit hook errors
lorisercole Jun 24, 2026
5706899
fix(tests): add docstrings to nested helpers in test_verstraete_cirac
lorisercole Jun 24, 2026
9d11aa3
fix(gcc): restore LAPACK_COMPLEX_CPP on non-MSVC to prevent C99 'I' m…
lorisercole Jun 24, 2026
d4471a9
fix(msvc): targeted fixes for sorted_double_loop.hpp, replacing bad w…
lorisercole Jun 24, 2026
cefd084
fix(msvc): silence C4018/C4389/C4701/C4177 in own code
lorisercole Jun 24, 2026
663f229
fix(build): enable OpenMP and MACIS tests in GHA
lorisercole Jun 24, 2026
5b3bc7d
fix(msvc): suppress libint2 header warnings in consumer TUs via libin…
lorisercole Jun 24, 2026
83cc19f
fix pre-commit hooks
lorisercole Jun 24, 2026
1541990
revert(openmp): remove OpenMP-on-Windows workarounds, disable OpenMP …
lorisercole Jun 25, 2026
66f89e2
Merge branch 'main' into feature/ler/windows-build-part-1
lorisercole Jun 25, 2026
ff5d97b
fix(hdf5): read is_restricted via hbool_t to avoid bool* UB
lorisercole Jun 25, 2026
2ff5dcf
refactor(autocas): hoist repeated size_t casts into named variables
lorisercole Jun 25, 2026
65179f9
fix(scf): assign basis_set_type via terminal else instead of default
lorisercole Jun 25, 2026
861c871
docs(install): mark native Windows builds experimental; note 64-bit r…
lorisercole Jun 25, 2026
d25c2ab
fix(vcpkg): drop hardcoded version-string and Windows-only description
lorisercole Jun 25, 2026
c7bb8ad
fix(vcpkg): trim openblas overlay to minimum (drop win32-uwp.diff, op…
lorisercole Jun 25, 2026
ef2572d
build(deps): point GauXC back to upstream wavefunction91/gauxc
lorisercole Jun 25, 2026
4922e43
fix(logger): don't flush stdout per message in stdout_fd_sink
lorisercole Jun 25, 2026
4df89f9
test(docs-examples): use TemporaryDirectory as context manager
lorisercole Jun 25, 2026
50563c8
build(cmake): move per-config flags into toolchain files
lorisercole Jun 25, 2026
f4cd108
ci(gha): use platform toolchain file for C++ build
lorisercole Jun 25, 2026
11e2dbd
build(cmake): enforce per-config flags via cache vars in toolchains
lorisercole Jun 25, 2026
9663b6a
Remove debug flag-printing message(STATUS) lines from cpp/CMakeLists.txt
lorisercole Jun 25, 2026
d7a7456
Remove MSVC/clang-cl warning suppressions from CMake files
lorisercole Jun 25, 2026
24cb8a6
ci(windows): enable slow Python tests in build scripts via QDK_CHEMIS…
lorisercole Jun 25, 2026
2f624c1
docs: trim verbose comments added for the Windows build
lorisercole Jun 25, 2026
2c675eb
build(uarch): skip /arch: auto-detection for native MSVC; clamp NCPUS>=1
lorisercole Jun 25, 2026
a1fd84c
Merge branch 'main' into feature/ler/windows-build-part-1
lorisercole Jun 26, 2026
31c6844
fix(macis): use std::max<size_t> to avoid unsigned-long/size_t mismat…
lorisercole Jun 26, 2026
483b532
fix(macis): harden 32-bit integer literals for Windows LLP64
lorisercole Jun 26, 2026
7b15b6e
fix(macis): gate ips4o/libatomic on OpenMP, skip atomic on Windows
lorisercole Jun 26, 2026
4617a28
fix pre-commit
lorisercole Jun 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Normalize all text files to LF in the repo and working copy.
* text=auto eol=lf
4 changes: 4 additions & 0 deletions .github/scripts/check_license_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
from pathlib import Path
from typing import List, Optional, Tuple

# Ensure emoji and other Unicode characters can be printed on Windows (cp1252)
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8")

# Expected license headers for different file types
CPP_LICENSE_PATTERNS = [
# Full MIT license header - standard C-style comment with line breaks
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ dist/
downloads/
eggs/
.eggs/
install/
lib/
lib64/
parts/
sdist/
var/
vcpkg_installed/
wheels/
share/python-wheels/
*.egg-info/
Expand Down
406 changes: 406 additions & 0 deletions .pipelines/pip-scripts/windows-build-clang-cmake.ps1

Large diffs are not rendered by default.

360 changes: 360 additions & 0 deletions .pipelines/pip-scripts/windows-build-clang-pip.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,360 @@
# windows-build-clang-pip.ps1
# Local script to build and test the QDK Chemistry Python package on Windows using Clang and pip.
# pip (via scikit-build-core) handles the full C++ and Python build in one step.
# Run from the repo root in an elevated PowerShell (admin) if VS Build Tools need installing.
#
# Usage:
# .\windows-build-clang-pip.ps1 # Full build (static vcpkg deps, default)
# .\windows-build-clang-pip.ps1 -DynamicDeps # Full build (dynamic vcpkg deps, bundles DLLs)
# .\windows-build-clang-pip.ps1 -SkipPrereqs # Skip prerequisite installation
# .\windows-build-clang-pip.ps1 -SkipBuild # Skip build, only run tests
# .\windows-build-clang-pip.ps1 -SkipTests # Skip test runs

param(
[switch]$DynamicDeps,
[switch]$SkipPrereqs,
[switch]$SkipBuild,
[switch]$SkipTests
)

$ErrorActionPreference = "Stop"
$RepoRoot = Get-Location
if (-not (Test-Path "$RepoRoot\cpp\CMakeLists.txt")) {
Write-Error "This script must be run from the repository root."
exit 1
}
$VcpkgInstalledDir = "$RepoRoot\vcpkg_installed"
# vcpkg triplets: https://learn.microsoft.com/en-us/vcpkg/users/platforms/windows
# Using dynamic (DLL) dependencies requires copying the corresponding DLL files to qdk-chemistry's Python package
# installation folder. Else, Windows won't find them at runtime and the Python package will fail to import.
# This is because Windows does not have a system-wide DLL search path configuration like Linux's ldconfig.
if ($DynamicDeps) {
$VcpkgTriplet = "x64-windows"
} else {
$VcpkgTriplet = "x64-windows-static-md"
}
$QDK_UARCH = "x86-64-v3"

$linkMode = if ($DynamicDeps) { "dynamic" } else { "static" }
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " QDK Chemistry - Windows Build (pip) " -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host "Repo root: $RepoRoot"
Write-Host "Triplet: $VcpkgTriplet ($linkMode)"
Write-Host ""

# --------------------------------------------------------------------------
# Helper: ensure a command exists
# --------------------------------------------------------------------------
function Assert-Command($Name) {
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
Write-Error "$Name not found in PATH. Please install it first."
exit 1
}
}

# ==========================================================================
# STEP 0 - Prerequisites
# ==========================================================================
if (-not $SkipPrereqs) {
Write-Host ""
Write-Host "=== Step 0: Checking / installing prerequisites ===" -ForegroundColor Yellow

# --- 0a. VS Build Tools with clang-cl ---
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$clangCl = $null

# Search existing VS installations for clang-cl (-products * includes BuildTools)
if (Test-Path $vswhere) {
$vsPath = & $vswhere -latest -products * -property installationPath 2>$null
if ($vsPath) {
$candidates = @(
"$vsPath\VC\Tools\Llvm\x64\bin\clang-cl.exe",
"$vsPath\VC\Tools\Llvm\bin\clang-cl.exe"
)
foreach ($c in $candidates) {
if (Test-Path $c) { $clangCl = $c; break }
}
}
}

if (-not $clangCl) {
Write-Host "clang-cl not found. Installing VS Build Tools with C++ and Clang components..." -ForegroundColor Magenta
Write-Host "This requires an elevated (admin) PowerShell and will take several minutes."
Write-Host ""

$installerUrl = "https://aka.ms/vs/17/release/vs_BuildTools.exe"
$installerPath = "$env:TEMP\vs_BuildTools.exe"

if (-not (Test-Path $installerPath)) {
Write-Host "Downloading VS Build Tools installer..."
Invoke-WebRequest -Uri $installerUrl -OutFile $installerPath -UseBasicParsing
}

Write-Host "Running VS Build Tools installer (this may take 10-20 minutes)..."
$installArgs = @(
"--quiet", "--wait", "--norestart",
"--add", "Microsoft.VisualStudio.Workload.VCTools",
"--add", "Microsoft.VisualStudio.Component.VC.Llvm.Clang",
"--add", "Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset",
"--add", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"--add", "Microsoft.VisualStudio.Component.Windows11SDK.26100",
"--includeRecommended"
)
$proc = Start-Process -FilePath $installerPath -ArgumentList $installArgs -Wait -PassThru
if ($proc.ExitCode -ne 0 -and $proc.ExitCode -ne 3010) {
Write-Error "VS Build Tools installation failed with exit code $($proc.ExitCode)"
exit 1
}
Write-Host "VS Build Tools installed successfully." -ForegroundColor Green

# Re-search for clang-cl
$vsPath = & $vswhere -latest -products * -property installationPath 2>$null
if ($vsPath) {
$candidates = @(
"$vsPath\VC\Tools\Llvm\x64\bin\clang-cl.exe",
"$vsPath\VC\Tools\Llvm\bin\clang-cl.exe"
)
foreach ($c in $candidates) {
if (Test-Path $c) { $clangCl = $c; break }
}
}

if (-not $clangCl) {
Write-Error "clang-cl still not found after installing VS Build Tools."
exit 1
}
}

$clangDir = Split-Path $clangCl
Write-Host "Using clang-cl: $clangCl" -ForegroundColor Green
& $clangCl --version

# Add clang-cl to PATH for this session
$env:PATH = "$clangDir;$env:PATH"

# --- 0b. Set up MSVC environment (vcvarsall) ---
Write-Host ""
Write-Host "Setting up MSVC developer environment..."
$vsPath = & $vswhere -latest -products * -property installationPath
$vcvarsall = "$vsPath\VC\Auxiliary\Build\vcvarsall.bat"
if (-not (Test-Path $vcvarsall)) {
Write-Error "vcvarsall.bat not found at $vcvarsall"
exit 1
}

# Capture environment from vcvarsall
$envBefore = @{}
Get-ChildItem env: | ForEach-Object { $envBefore[$_.Name] = $_.Value }

$tempFile = [System.IO.Path]::GetTempFileName()
cmd /c "`"$vcvarsall`" x64 && set > `"$tempFile`""
Get-Content $tempFile | ForEach-Object {
if ($_ -match "^([^=]+)=(.*)$") {
$name = $matches[1]
$value = $matches[2]
if ($envBefore[$name] -ne $value) {
[System.Environment]::SetEnvironmentVariable($name, $value, "Process")
}
}
}
Remove-Item $tempFile
Write-Host "MSVC developer environment configured." -ForegroundColor Green

# Re-add clang-cl to PATH (vcvarsall may have reset it)
$env:PATH = "$clangDir;$env:PATH"

# --- 0c. vcpkg ---
# Check VS-bundled vcpkg first, then VCPKG_INSTALLATION_ROOT, then bootstrap
$vcpkgRoot = $null
$vsVcpkg = "$vsPath\VC\vcpkg\vcpkg.exe"
if (Test-Path $vsVcpkg) {
$vcpkgRoot = Split-Path $vsVcpkg
} elseif ($env:VCPKG_INSTALLATION_ROOT -and (Test-Path "$($env:VCPKG_INSTALLATION_ROOT)\vcpkg.exe")) {
$vcpkgRoot = $env:VCPKG_INSTALLATION_ROOT
} else {
$vcpkgRoot = "$RepoRoot\vcpkg-tool"
if (-not (Test-Path "$vcpkgRoot\vcpkg.exe")) {
Write-Host ""
Write-Host "Bootstrapping vcpkg..."
git clone https://github.com/microsoft/vcpkg.git "$vcpkgRoot"
& "$vcpkgRoot\bootstrap-vcpkg.bat" -disableMetrics
}
}
Write-Host "Using vcpkg: $vcpkgRoot\vcpkg.exe" -ForegroundColor Green

# --- 0d. Install vcpkg packages ---
Write-Host ""
Write-Host "Installing vcpkg dependencies with triplet '$VcpkgTriplet' (this may take a while on first run)..."
& "$vcpkgRoot\vcpkg.exe" install `
--triplet $VcpkgTriplet `
--x-manifest-root="$RepoRoot" `
--x-install-root="$VcpkgInstalledDir" `
--overlay-ports="$RepoRoot\vcpkg-overlay\ports"
if ($LASTEXITCODE -ne 0) {
Write-Error "vcpkg install failed"
exit 1
}
Write-Host "vcpkg dependencies installed." -ForegroundColor Green

# --- 0e. Set CMake/vcpkg environment variables ---
$toolchainFile = "$vcpkgRoot\scripts\buildsystems\vcpkg.cmake"
$env:CMAKE_TOOLCHAIN_FILE = $toolchainFile
$env:VCPKG_TARGET_TRIPLET = $VcpkgTriplet
$env:VCPKG_INSTALLED_DIR = $VcpkgInstalledDir
$env:CMAKE_PREFIX_PATH = "$VcpkgInstalledDir\$VcpkgTriplet"
# Dynamic triplets produce runtime DLLs that must be on PATH for the build tools
if ($DynamicDeps) {
$env:PATH = "$VcpkgInstalledDir\$VcpkgTriplet\bin;$VcpkgInstalledDir\$VcpkgTriplet\debug\bin;$env:PATH"
}

# --- 0f. uv (Python package manager) ---
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
Write-Host "uv not found. Installing..." -ForegroundColor Magenta
Invoke-RestMethod https://astral.sh/uv/install.ps1 | Invoke-Expression
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
Write-Error "uv installation failed. Install manually: https://docs.astral.sh/uv/getting-started/installation/"
exit 1
}
}
Write-Host "Using uv: $(Get-Command uv | Select-Object -ExpandProperty Source) ($(uv --version))" -ForegroundColor Green

} else {
Write-Host "=== Skipping prerequisites (reusing previous environment) ===" -ForegroundColor DarkGray

# Even when skipping, we need the environment set up
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$vsPath = & $vswhere -latest -products * -property installationPath 2>$null
$candidates = @(
"$vsPath\VC\Tools\Llvm\x64\bin\clang-cl.exe",
"$vsPath\VC\Tools\Llvm\bin\clang-cl.exe"
)
foreach ($c in $candidates) {
if (Test-Path $c) {
$clangDir = Split-Path $c
$env:PATH = "$clangDir;$env:PATH"
break
}
}
Assert-Command "clang-cl"

# Set up MSVC env
$vcvarsall = "$vsPath\VC\Auxiliary\Build\vcvarsall.bat"
if (Test-Path $vcvarsall) {
$tempFile = [System.IO.Path]::GetTempFileName()
cmd /c "`"$vcvarsall`" x64 && set > `"$tempFile`""
Get-Content $tempFile | ForEach-Object {
if ($_ -match "^([^=]+)=(.*)$") {
[System.Environment]::SetEnvironmentVariable($matches[1], $matches[2], "Process")
}
}
Remove-Item $tempFile
# Re-add clang-cl to PATH
$env:PATH = "$clangDir;$env:PATH"
}

# vcpkg env - check VS-bundled vcpkg first
$vcpkgRoot = $null
$vsVcpkg = "$vsPath\VC\vcpkg\vcpkg.exe"
if (Test-Path $vsVcpkg) {
$vcpkgRoot = Split-Path $vsVcpkg
} elseif ($env:VCPKG_INSTALLATION_ROOT -and (Test-Path "$($env:VCPKG_INSTALLATION_ROOT)\vcpkg.exe")) {
$vcpkgRoot = $env:VCPKG_INSTALLATION_ROOT
} else {
$vcpkgRoot = "$RepoRoot\vcpkg-tool"
}
$env:CMAKE_TOOLCHAIN_FILE = "$vcpkgRoot\scripts\buildsystems\vcpkg.cmake"
$env:VCPKG_TARGET_TRIPLET = $VcpkgTriplet
$env:VCPKG_INSTALLED_DIR = $VcpkgInstalledDir
$env:CMAKE_PREFIX_PATH = "$VcpkgInstalledDir\$VcpkgTriplet"
# Dynamic triplets produce runtime DLLs that must be on PATH for the build tools
if ($DynamicDeps) {
$env:PATH = "$VcpkgInstalledDir\$VcpkgTriplet\bin;$VcpkgInstalledDir\$VcpkgTriplet\debug\bin;$env:PATH"
}
}

# Verify tools
Write-Host ""
Write-Host "=== Environment summary ===" -ForegroundColor Yellow
Write-Host " clang-cl: $(Get-Command clang-cl | Select-Object -ExpandProperty Source)"
Write-Host " cmake: $(Get-Command cmake | Select-Object -ExpandProperty Source)"
Write-Host " ninja: $(Get-Command ninja | Select-Object -ExpandProperty Source)"
Write-Host " python: $(Get-Command python | Select-Object -ExpandProperty Source) ($(python --version 2>&1))"
Write-Host " uv: $(Get-Command uv | Select-Object -ExpandProperty Source) ($(uv --version 2>&1))"
Write-Host " TOOLCHAIN_FILE: $env:CMAKE_TOOLCHAIN_FILE"
Write-Host " VCPKG_TRIPLET: $env:VCPKG_TARGET_TRIPLET"
Write-Host " VCPKG_INSTALLED: $env:VCPKG_INSTALLED_DIR"
Write-Host ""

# ==========================================================================
# STEP 1 - Build and install Python package (C++ is built by scikit-build-core)
# ==========================================================================
if (-not $SkipBuild) {
Write-Host "=== Step 1: Build and install Python package ===" -ForegroundColor Yellow
Push-Location "$RepoRoot\python"

$env:CMAKE_BUILD_PARALLEL_LEVEL = "6"
if (-not (Test-Path .\venv)) {
uv venv .\venv
}
.\venv\Scripts\activate.ps1
# pip drives the full build: scikit-build-core invokes CMake to compile the
# C++ library and pybind11 bindings, then packages everything into a wheel.
# Do not install:
# - plugins: pyscf does not build on Windows
# - jupyter: requires plugins
uv pip install -v .[coverage,dev,docs,qiskit-extras,openfermion-extras] `
-C cmake.args=-GNinja `
-C cmake.define.QDK_UARCH="$QDK_UARCH" `
-C cmake.define.QDK_CHEMISTRY_ENABLE_COVERAGE=OFF `
-C cmake.define.QDK_CHEMISTRY_ENABLE_MPI=OFF `
-C cmake.define.QDK_ENABLE_OPENMP=ON `
-C cmake.define.BUILD_SHARED_LIBS=OFF `
-C cmake.define.BUILD_TESTING=OFF `
-C cmake.define.CMAKE_BUILD_TYPE=Release `
-C cmake.define.CMAKE_C_COMPILER=clang-cl `
-C cmake.define.CMAKE_CXX_COMPILER=clang-cl `
-C cmake.define.CMAKE_TOOLCHAIN_FILE="$env:CMAKE_TOOLCHAIN_FILE" `
-C cmake.define.VCPKG_TARGET_TRIPLET="$env:VCPKG_TARGET_TRIPLET" `
-C cmake.define.VCPKG_INSTALLED_DIR="$env:VCPKG_INSTALLED_DIR"
if ($LASTEXITCODE -ne 0) { Pop-Location; Write-Error "Python package install failed"; exit 1 }

python -c "import qdk_chemistry; print('qdk_chemistry version:', qdk_chemistry.__version__)"
if ($LASTEXITCODE -ne 0) { Pop-Location; Write-Error "Python import check failed"; exit 1 }
Write-Host "Python package installed successfully." -ForegroundColor Green

Pop-Location
} else {
Write-Host "=== Skipping build ===" -ForegroundColor DarkGray
}

# ==========================================================================
# STEP 2 - Run Python tests
# ==========================================================================
if (-not $SkipTests) {
Write-Host ""
Write-Host "=== Step 2: Run Python tests ===" -ForegroundColor Yellow
Push-Location "$RepoRoot\python"

# Ensure venv is activated
if (Test-Path .\venv\Scripts\activate.ps1) {
.\venv\Scripts\activate
}

$env:OMP_NUM_THREADS = 2
pytest -v --tb=short
$pytestExit = $LASTEXITCODE
Pop-Location
if ($pytestExit -ne 0) {
Write-Warning "Some Python tests failed (exit code: $pytestExit)"
} else {
Write-Host "All Python tests passed." -ForegroundColor Green
}
} else {
Write-Host "=== Skipping tests ===" -ForegroundColor DarkGray
}

Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " Build script finished! " -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Loading
Loading