From 390cc8a262468cd6381ef2193d1bc257a36d0917 Mon Sep 17 00:00:00 2001 From: Chris Eibl <138194463+chris-eibl@users.noreply.github.com> Date: Mon, 23 Mar 2026 20:06:56 +0100 Subject: [PATCH 1/3] fix building the jit stencils on Windows when the interpreter is built with a different clang version. --- ...-03-23-20-06-35.gh-issue-146210.C01Rmq.rst | 2 ++ Tools/jit/_llvm.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Build/2026-03-23-20-06-35.gh-issue-146210.C01Rmq.rst diff --git a/Misc/NEWS.d/next/Build/2026-03-23-20-06-35.gh-issue-146210.C01Rmq.rst b/Misc/NEWS.d/next/Build/2026-03-23-20-06-35.gh-issue-146210.C01Rmq.rst new file mode 100644 index 00000000000000..ce59a9a3a571b4 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-03-23-20-06-35.gh-issue-146210.C01Rmq.rst @@ -0,0 +1,2 @@ +Fix building the jit stencils on Windows when the interpreter is built with +a different clang version. Patch by Chris Eibl. diff --git a/Tools/jit/_llvm.py b/Tools/jit/_llvm.py index 8b68c1e8636af7..215013aa213305 100644 --- a/Tools/jit/_llvm.py +++ b/Tools/jit/_llvm.py @@ -42,9 +42,26 @@ async def _run(tool: str, args: typing.Iterable[str], echo: bool = False) -> str async with _CORES: if echo: print(shlex.join(command)) + + if os.name == "nt": + env = os.environ.copy() + try: + # https://github.com/python/cpython/issues/146210 + # When the Python iterpreter is built with + # "/p:PlatformToolset=ClangCL" "/p:LLVMInstallDir=..."" + # msbuild populates the INCLUDE variable based on this + # clang version, which might be different to the one used + # for building the jit stencils. Mixing those include paths + # can cause mysterious build errors, so we remove the + # variable from the environment when invoking LLVM tools. + del env["INCLUDE"] + except KeyError: + pass + else: + env = None try: process = await asyncio.create_subprocess_exec( - *command, stdout=subprocess.PIPE + *command, stdout=subprocess.PIPE, env=env ) except FileNotFoundError: return None From 1a08565b76a82707e61ff4ecbe6c80823262e611 Mon Sep 17 00:00:00 2001 From: Chris Eibl <138194463+chris-eibl@users.noreply.github.com> Date: Fri, 3 Apr 2026 18:02:27 +0200 Subject: [PATCH 2/3] Use Savannah's much better and shorter description Co-authored-by: Savannah Ostrowski --- Tools/jit/_llvm.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Tools/jit/_llvm.py b/Tools/jit/_llvm.py index 215013aa213305..0f7d7af640c26f 100644 --- a/Tools/jit/_llvm.py +++ b/Tools/jit/_llvm.py @@ -46,14 +46,10 @@ async def _run(tool: str, args: typing.Iterable[str], echo: bool = False) -> str if os.name == "nt": env = os.environ.copy() try: - # https://github.com/python/cpython/issues/146210 - # When the Python iterpreter is built with - # "/p:PlatformToolset=ClangCL" "/p:LLVMInstallDir=..."" - # msbuild populates the INCLUDE variable based on this - # clang version, which might be different to the one used - # for building the jit stencils. Mixing those include paths - # can cause mysterious build errors, so we remove the - # variable from the environment when invoking LLVM tools. + # When building with /p:PlatformToolset=ClangCL, the VS build + # system puts that clang's include path into INCLUDE. The JIT's + # clang may be a different version, and mismatched headers cause + # build errors. See https://github.com/python/cpython/issues/146210 del env["INCLUDE"] except KeyError: pass From 3c001368b0c1d853fc47c2b4f17f887c121a93c7 Mon Sep 17 00:00:00 2001 From: Chris Eibl <138194463+chris-eibl@users.noreply.github.com> Date: Fri, 3 Apr 2026 18:07:29 +0200 Subject: [PATCH 3/3] env.pop("INCLUDE", None) --- Tools/jit/_llvm.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Tools/jit/_llvm.py b/Tools/jit/_llvm.py index 0f7d7af640c26f..a4aaacdf41249d 100644 --- a/Tools/jit/_llvm.py +++ b/Tools/jit/_llvm.py @@ -44,15 +44,12 @@ async def _run(tool: str, args: typing.Iterable[str], echo: bool = False) -> str print(shlex.join(command)) if os.name == "nt": + # When building with /p:PlatformToolset=ClangCL, the VS build + # system puts that clang's include path into INCLUDE. The JIT's + # clang may be a different version, and mismatched headers cause + # build errors. See https://github.com/python/cpython/issues/146210. env = os.environ.copy() - try: - # When building with /p:PlatformToolset=ClangCL, the VS build - # system puts that clang's include path into INCLUDE. The JIT's - # clang may be a different version, and mismatched headers cause - # build errors. See https://github.com/python/cpython/issues/146210 - del env["INCLUDE"] - except KeyError: - pass + env.pop("INCLUDE", None) else: env = None try: