← Back to Pull requests

Build and run Windows like Linux: shared LLVM build and jobs, sccache + S3, unique CAPI name #466

Closed
unknown closed this pull request without merging on Nov 16, 2026 21:19 UTC
View on GitHub
unknown unknown commented on Nov 15, 2026 23:30 UTC
Author

Description

Windows had its own LLVM build script, its own CI jobs, a devcontainer, and its own way of turning MLIR into libNVVM IR, and none of its LLVM builds had a compiler cache or the S3 tier. Every LLVM cache-key change meant a cold MSVC build: about 50 min per Python on win-64 and about 70 min on win-arm64, versus a ~3 min build step on Linux, where sccache hits.

This PR makes Windows build and run the way Linux does, keeping only what MSVC strictly needs, and gives every platform the same cache tiers.

Same LLVM build on every platform

  • ci/build-llvm-modern.sh and ci/build-llvm7.sh now run on Linux and on Windows (Git Bash with MSVC on PATH); ci/build-windows.sh is removed. What remains Windows-only is the MSVC CMake flags (cl, /MT, fallback TypeIDs, zlib/zstd off) and, for LLVM 7, the LLVM-C.dll link step, because MSVC cannot build LLVM 7 as a DLL.

  • build-llvm.yml has one build-llvm-modern job and one build-llvm7 job for all four platforms, with the same steps: setup-hardened-python (now on Linux too), sccache, AWS credentials, then GHA cache, S3 tarball (ci/llvm-cache.sh), build. Linux still builds inside manylinux (container: is empty on Windows); only the MSVC setup step is Windows-only. win-64 moves from a devcontainer on a self-hosted runner to windows-2022, like win-arm64 and the wheel builds; the devcontainer and its PowerShell wrappers are removed.

  • Both scripts fetch only the commit they build (the pinned commit, or the LLVM 7 tag) with --depth 1 --filter=blob:none and a sparse checkout of the directories the build reads (llvm mlir cmake third-party; llvm for LLVM 7). They used to clone the default branch and then fetch the pinned commit, which took 73 s on Linux, 137 s on win-64 and 404 s on WoA. The source path is unchanged, so compile commands and sccache keys are too.

  • On Windows the modern build no longer copies files out of the build tree, builds a bridge DLL, or runs a smoke import: at our LLVM pin cmake --install already installs the .pyd, CAPI and nanobind DLLs. The wheel therefore no longer picks up build-tree leftovers (.exp and .lib files for every extension, __pycache__), and setup.py leaves the remaining import libraries out of the wheel; they are only needed to link cext at build time.

  • LLVM 7 on Windows builds without installing and links LLVM-C.dll straight into llvm7-install/bin/, so the artifact is one DLL instead of a full install. The linker comes from CMake's cache (Git Bash's coreutils link.exe shadows MSVC's), and gen-llvm-c-exports.py reads symbol names from the .lib archive index instead of running dumpbin.

  • ci/llvm-cache.sh reports S3 errors instead of discarding them; only a missing tarball is a quiet miss, and a failed download or extraction now counts as a miss instead of a hit.
  • Same MLIR-to-libNVVM path on every platform

  • Windows now uses cext/launcher/llvm_downgrade.cpp, as Linux does. That code loads the LLVM C API from the MLIR Python CAPI library, which a Linux .so exports by default but a Windows DLL did not. A small CMake hook, cext/mlir-python/CMakeLists.txt, loaded through LLVM_EXTERNAL_PROJECTS, adds /EXPORT: for the 81 functions it uses and installs the import library next to the DLL.

  • This removes the Windows-only MLIRModernToNVVM bridge (cext/mlir-modern/, a C++ copy of the same passes with its own LLVM/MLIR copy; it exchanged only MLIR text with the rest of the process) and the Windows-only branches in mlir_optimization.py and llvm_utils.py. This does not address #208, which is about MLIRToLLVM70.dll and is unchanged here.

  • Both Windows loaders (llvm_downgrade.cpp, and the LLVM 7 bridge's CAPILoader.h) now open their UTF-8 library paths with LoadLibraryW; LoadLibraryA read them in the ANSI code page and failed for installs under non-ASCII paths.
  • Unique name for the MLIR Python CAPI library

  • The library is now MLIRPythonCAPI-numba_cuda_mlir, like our nanobind and support libraries. With upstream's default name, an MLIR-based package imported first would capture our bindings, because glibc reuses an already-loaded library with a matching soname (Windows does the same by module name). test_same_named_capi_library_does_not_hijack_bindings loads a decoy libMLIRPythonCAPI.so first; on main it fails with libMLIRPythonSupport-numba_cuda_mlir.so: undefined symbol: mlirTypeIsAShaped. A bare make -C tests/data now builds the decoy too.
  • sccache and S3 everywhere

  • .github/actions/install-sccache is ported verbatim from NVIDIA/cuda-python@ba7dcd05e545b7bf8a1a8fdfb451b406c03459cb (first commit), then extended to Windows x64/arm64. Every sccache install uses it, so Linux moves from unpinned latest to the SHA-256-verified v0.18.0-rapids.7. CMake launches cl through sccache directly, so the setuptools shim from NVIDIA/cuda-python#1185 is not needed. ci/setup-sccache.sh writes its config to %APPDATA%\Mozilla\sccache\config\config on Windows.

  • Each LLVM job writes its sccache stats as JSON and shows them in the job summary with the existing sccache-summary action, as the wheel builds do. The action now writes the summary as UTF-8 and prefers python, since Windows defaults to cp1252 and Windows venvs have no python3.exe.

  • configure-aws-credentials uses special-characters-workaround. When the AWS secret key starts with /, Git Bash rewrites it into a Windows path before aws.exe and sccache.exe see it, and every S3 request in that job fails with SignatureDoesNotMatch (see aws-actions/configure-aws-credentials#528). This hit two Windows jobs during this PR.

  • Both LLVM jobs set SCCACHE_SKIP_CACHE_CHECK and the rate-limit-on-error variables as cuda-python does (NVIDIA/cuda-python#3273), so a cache-backend error at server startup cannot fail the build.

  • MSVC is pinned to 14.44 on both Windows arches (LLVM_WINDOWS_MSVC_TOOLSET, LLVM and wheel builds) and is part of the Windows cache keys.
  • All LLVM cache keys change, so LLVM rebuilds everywhere once. Linux compile commands are unchanged, so that rebuild hits sccache.

    Not in scope: sccache for the Windows wheel builds and multi-level sccache (GHA + S3). #463 adds its own cext/mlir-python/ and will need to carry the CAPI name and Windows exports from here.

    Testing

  • CI is green on the latest commit (138 jobs, including the Windows GPU test suite on the Linux code path).

  • - sccache with a warm cache: 98.8% hits for Linux modern LLVM (about 6 min per job), 100% for LLVM 7 (win-64 LLVM 7 in 2.9 min instead of 21 min cold), and 97.9% for a WoA modern build (16 min instead of 125 min cold). For comparison, main's last full WoA build without sccache took 98 min.
    - The GitHub-hosted Windows runners assume the AWS role through OIDC and read and write the S3 caches; the empty container: runs the Windows jobs on the host.
    - win-64 wheels against main (cp312): 47.0 → 41.7 MB compressed and 140.8 → 115.2 MB unpacked. The CAPI DLL keeps its size and gains exactly the 81 LLVM C exports, plus _Avx2WmemEnabledWeakValue, which the Windows SDK's ucrt/wchar.h defines and main's MLIRToLLVM70.dll already exports. LLVM-C.dll has the same 938 exports. Every _mlir*.pyd, the support DLL and MLIRToLLVM70.dll import the new CAPI name.
  • Linux, locally (A6000/Ada): built LLVM with the new script, built the wheel, and ran the full test suite and tests/test_symbol_isolation.py. 5751 passed, 89 skipped, 289 xfailed; the only failures are the 2 test_multigpu tests, because this host mixes GPU models. All 4 isolation tests pass, including the new one, which fails on main.

  • Old and new build scripts were run on the Linux and Windows code paths with logging stubs for the external tools. On Linux, the CMake arguments differ only by the hook and LLVM_PARALLEL_LINK_JOBS, which add no compile flags; LLVM 7 is identical.

  • The sparse checkout was compared against everything a full local Linux build reads (sources, headers, CMake files): nothing the build uses is missing. gen-llvm-c-exports.py was checked against real archives, and the ci/llvm-cache.sh error paths with a stub aws.

  • actionlint reports no new findings; shellcheck is clean on the changed scripts; ruff, the YAML, whitespace and SPDX hooks pass.
  • -- Leo's bot

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: atmnp Review duration: 1309m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #466"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%