Skip to content

Preserve Unicode paths in the Windows LLVM builder - #2515

Merged
ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
DanielDeGiorgio:fix/windows-llvm-unicode-batch
Nov 23, 2026
Merged

ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
DanielDeGiorgio:fix/windows-llvm-unicode-batch

Conversation

@DanielDeGiorgio

Copy link
Copy Markdown
Contributor

Summary

The native Windows LLVM builder writes _build.cmd as ASCII. With a non-ASCII -Temp or tool path, that replaces characters with question marks before CMake starts. Write the batch file as UTF-8 without a BOM and switch cmd.exe to code page 65001 before the first path-bearing command.

Coordination claim in #2300. This change is independently based on main. #2497 covers the separate runtime wrapper.

Verification

  • python -I -B tests/test_build_llvm_mc_batch.py -v reproduced the ASCII corruption before the fix and passed afterward. It checks the emitted bytes and runs the generated batch file with real Windows PowerShell and cmd.exe.
  • python -I -B tests/test_llvm_install_destination.py -v, python -I -B tests/test_text_write_line_endings.py, and git diff --check passed.
  • Ran the actual installer from a synthetic CMake project with a Unicode -Temp path, MSVC 19.44, and the official Ninja 1.13.2 Windows binary. Configure, compilation, the probe call, and installation all completed. The WinLibs Ninja binary installed on this machine still mangled the path internally. This PR fixes the wrapper's encoding. The smoke test used a stand-in program and did not compile LLVM.

AI-assisted with Codex.

@tupacfan04

Copy link
Copy Markdown
Contributor

Code read of 7db5591f (I didn't run it). Looks right. Writing _build.cmd as UTF-8 without a BOM keeps the non-ASCII paths intact, and putting chcp 65001 on the line after @echo off means cmd.exe has switched before it reads the first line with a path.

One side effect, new for this script (build_runtime.ps1 already does it): chcp changes the code page of the shared console. Since the batch runs with -NoNewWindow, the user's PowerShell window stays on 65001 after the build. That's mostly harmless on current Windows, but if you want to leave the console as it was, read the old code page first (for /f "tokens=2 delims=:." %%c in ('chcp') do set "_cp=%%c") and chcp %_cp% >nul at the end. setlocal doesn't scope chcp.

AI-assisted review (Claude Code).

@ezbyDev

ezbyDev commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

The new test_non_ascii_paths_survive_the_batch_writer fails when NoDefaultCurrentDirectoryInExePath is set, because both batch files are started by bare name and cmd.exe then won't look in the current folder.

Reproduce on this branch (cc29f9be), Windows 11, Python 3.12:

set NoDefaultCurrentDirectoryInExePath=1
python -I tests\test_build_llvm_mc_batch.py

Result: AssertionError: 1 != 0 : b'"check-console.cmd" is not recognized as an internal or external command...' (passes with the variable unset). Making only the outer call a full path then fails the same way on the inner call _build.cmd.

Both of these make it pass with the variable set and unset (checked here):

-                b"call _build.cmd\r\nset \"build_exit=%errorlevel%\"\r\nchcp >after.txt\r\nexit /b %build_exit%\r\n"
+                b"call \"%~dp0_build.cmd\"\r\nset \"build_exit=%errorlevel%\"\r\nchcp >after.txt\r\nexit /b %build_exit%\r\n"
-                        ["cmd.exe", "/d", "/c", "check-console.cmd"], cwd=work, timeout=30,
+                        ["cmd.exe", "/d", "/c", str(work / "check-console.cmd")], cwd=work, timeout=30,

build_llvm_mc.ps1 itself already starts _build.cmd by full path, so this is only the test. #3380 fixes the same pattern in the current main version of this file and in test_build_runtime_fallback.py; whichever lands second will need a small rebase. AI-assisted (Claude Code).

@ezbyDev

ezbyDev commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Correction to my suggestion above, sorry: the absolute paths I proposed (now in 6648b5ff) break a temp folder that holds &, because cmd.exe /c splits the full path there (found in review of #3380). Reproduced on 6648b5ff: test_build_llvm_mc_batch.py fails (2 failures) with TEMP set to such a folder, variable set or unset, and passes with the default, (x) and 東京 folders.

An explicit relative name for the outer call avoids it. Your call "%~dp0_build.cmd" inner line is fine:

-                        ["cmd.exe", "/d", "/c", str(console_check)], cwd=work, timeout=30,
+                        ["cmd.exe", "/d", "/c", r".\check-console.cmd"], cwd=work, timeout=30,

Checked: this diff on 6648b5ff passes 8/8 across the default, &, (x) and 東京 temp folders, each with NoDefaultCurrentDirectoryInExePath set and unset.

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
ezbyDev added a commit to ezbyDev/Leonida that referenced this pull request Nov 22, 2026
Rebased on main (aa2988c). Since ItsNotRexed#2515 the llvm-mc test starts a
check-console.cmd wrapper that calls _build.cmd, and the runtime half
moved to tests/test_build_runtime_batch.py, which passes the full path.

- test_build_llvm_mc_batch.py: r".\check-console.cmd" in Python and
  `call .\_build.cmd` in the wrapper, run with
  NoDefaultCurrentDirectoryInExePath=1. With that set, cmd.exe skips the
  current folder for a bare name; qualifying only the outer name still
  fails both exit-status subtests.
- test_build_runtime_batch.py: r".\_build.cmd" instead of the full path,
  which cmd.exe /c splits when the temp folder holds ` & `.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ItsNotRexed
ItsNotRexed merged commit 221e385 into ItsNotRexed:main Nov 23, 2026
2 of 4 checks passed
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.

4 participants