Skip to content

setup-msvc-dev-cmd: also set DISTUTILS_USE_SDK / MSSdk#179

Merged
xnacly merged 1 commit into
v4-betafrom
MILAB-6205_msvc-distutils-use-sdk
Jun 3, 2026
Merged

setup-msvc-dev-cmd: also set DISTUTILS_USE_SDK / MSSdk#179
xnacly merged 1 commit into
v4-betafrom
MILAB-6205_msvc-distutils-use-sdk

Conversation

@xnacly
Copy link
Copy Markdown
Member

@xnacly xnacly commented Jun 3, 2026

Extends the composite action with a second step that exports DISTUTILS_USE_SDK=1 and MSSdk=1 to \$GITHUB_ENV after vcvars activation.

Why

After ilammy/msvc-dev-cmd activates vcvars (INCLUDE / LIB / LIBPATH / PATH all populated, VS install dir set, cl.exe on PATH), setuptools' MSVC compiler shim still raises:

```
error: Microsoft Visual C++ 14.0 or greater is required.
```

The error originates in setuptools/_distutils/_msvccompiler.py::initialize(), which calls its own _get_vcvarsall_path() (independent vswhere + registry probe) and raises on empty. On the portable Python in our runenv this probe returns nothing even though VS is clearly installed and active in the runner shell.

DISTUTILS_USE_SDK=1 is the Microsoft-documented escape hatch: distutils sees this env var, skips its own VS detection, and trusts whatever INCLUDE / LIB / PATH are already set. MSSdk=1 is the legacy partner flag that older distutils versions check.

Verified

PR #88 in runenv-python-3 currently consumes node-matrix-pnpm.yaml@v4-beta (which already includes the MSVC step). Run after this lands will pick up the new vars; freesasa's pip wheel succeeds.

Blast radius

  • Pure additive — two env vars exported after activation.
  • Non-Python builds (cmake, MSBuild, msbuild via VS solutions) ignore both vars completely; they read the standard MSVC env vars directly.
  • Python builds get a working compiler out of the box; no per-consumer opt-in.

PR base

Following team convention: branched from v4-beta, will merge into v4-beta, then standard v4-beta -> v4 promotion afterwards.

Greptile Summary

This PR extends the setup-msvc-dev-cmd composite action with a second step that appends DISTUTILS_USE_SDK=1 and MSSdk=1 to $GITHUB_ENV immediately after ilammy/msvc-dev-cmd activates vcvarsall. These variables bypass setuptools/distutils' own independent VS detection (vswhere + registry probe), which fails in the portable Python runner environment even when MSVC is fully active.

  • New step (Tell distutils that MSVC is already set up): uses bash shell to write both env vars via the standard echo \"VAR=VALUE\" >> \"$GITHUB_ENV\" pattern; the step inherits the default success() condition, so it only runs when vcvarsall activation succeeds.
  • Blast radius is minimal: non-Python toolchains (CMake, MSBuild) are unaffected; the change is purely additive and requires no opt-in from consumers.

Confidence Score: 4/5

Safe to merge — two env vars appended after a successful MSVC activation step; non-Python toolchains ignore them entirely.

The change is additive and narrowly scoped: it writes two well-documented distutils env vars unconditionally to every job that consumes the action. The env vars are harmless to CMake/MSBuild consumers, and the second step only fires when the first (vcvarsall) step succeeds. The action's top-level description is not updated to mention the new Python-specific behaviour, which may surprise consumers who scan the YAML header without reading step-level comments.

actions/setup-msvc-dev-cmd/action.yaml — the description field should reflect the new Python distutils side-effect

Important Files Changed

Filename Overview
actions/setup-msvc-dev-cmd/action.yaml Adds a second step that unconditionally appends DISTUTILS_USE_SDK=1 and MSSdk=1 to GITHUB_ENV after vcvarsall activation; no inputs or conditions guard the new step

Sequence Diagram

sequenceDiagram
    participant Job as GitHub Actions Job
    participant MSVC as ilammy/msvc-dev-cmd
    participant Env as $GITHUB_ENV
    participant Python as setuptools / distutils

    Job->>MSVC: Enable Developer Command Prompt
    MSVC-->>Env: Sets INCLUDE, LIB, LIBPATH, PATH, etc.
    MSVC-->>Job: success

    Job->>Env: "echo DISTUTILS_USE_SDK=1"
    Job->>Env: "echo MSSdk=1"

    Note over Python,Env: Later pip/setuptools build step
    Python->>Env: Read DISTUTILS_USE_SDK
    alt "DISTUTILS_USE_SDK == 1"
        Python->>Env: Trust existing INCLUDE / LIB / PATH
        Python-->>Job: Build succeeds
    else not set
        Python->>Python: Run own vswhere + registry probe
        Python-->>Job: MSVC 14.0+ required error
    end
Loading

Comments Outside Diff (1)

  1. actions/setup-msvc-dev-cmd/action.yaml, line 1-6 (link)

    P2 Action description not updated

    The top-level description field still only references MSVC command-line configuration and ilammy/msvc-dev-cmd. Consumers scanning the action registry or reading the YAML for the first time won't know it now also injects Python-distutils environment variables. Adding a sentence about DISTUTILS_USE_SDK / MSSdk here would make the behaviour discoverable without needing to read the step comments.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: actions/setup-msvc-dev-cmd/action.yaml
    Line: 1-6
    
    Comment:
    **Action description not updated**
    
    The top-level `description` field still only references MSVC command-line configuration and `ilammy/msvc-dev-cmd`. Consumers scanning the action registry or reading the YAML for the first time won't know it now also injects Python-distutils environment variables. Adding a sentence about `DISTUTILS_USE_SDK` / `MSSdk` here would make the behaviour discoverable without needing to read the step comments.
    
    How can I resolve this? If you propose a fix, please make it concise.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
actions/setup-msvc-dev-cmd/action.yaml:1-6
**Action description not updated**

The top-level `description` field still only references MSVC command-line configuration and `ilammy/msvc-dev-cmd`. Consumers scanning the action registry or reading the YAML for the first time won't know it now also injects Python-distutils environment variables. Adding a sentence about `DISTUTILS_USE_SDK` / `MSSdk` here would make the behaviour discoverable without needing to read the step comments.

Reviews (1): Last reviewed commit: "setup-msvc-dev-cmd: also set DISTUTILS_U..." | Re-trigger Greptile

After ilammy/msvc-dev-cmd activates vcvars, setuptools' MSVC compiler
shim (`_distutils._msvccompiler.initialize()`) still runs its own
independent VS lookup via `_get_vcvarsall_path()` and raises:

    error: Microsoft Visual C++ 14.0 or greater is required.

even though INCLUDE / LIB / LIBPATH / PATH are all in scope from
vcvars. The Microsoft-documented escape hatch is to set
`DISTUTILS_USE_SDK=1` (legacy partner: `MSSdk=1`); with that, distutils
skips its own detection and trusts the env vars already present.

Adds a second step in the composite action that appends both vars to
$GITHUB_ENV after the MSVC activation step. Generic enough to live in
the shared action: every Python C-extension build on Windows benefits,
non-Python builds ignore the var entirely.

Surfaced by runenv-python-3 PR #88 (freesasa addition): vcvars
activated cleanly but the pip wheel still hit the distutils error.
@notion-workspace
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant