-
Notifications
You must be signed in to change notification settings - Fork 0
Description
I've been watching this project for months, waiting for it to go open source — and the day finally came! I cloned it almost immediately and couldn't wait to try it out. Unfortunately I hit this bug right out of the gate on my machine.
Fair warning: the body of this issue was drafted with AI assistance. That said, I'm pretty confident my own write-up wouldn't have been any clearer — so here we are.
Summary
On Windows, when the auto-detected MSVC vcvars64.bat path contains spaces (e.g. C:\Program Files\Microsoft Visual Studio\...), the compilation step fails.
Root Cause
The compiler path returned by list_auto_search_compiler_paths() is correctly quoted with double quotes to handle spaces:
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
However, when this quoted path is passed directly to system(), the C runtime invokes cmd.exe /c <command>. cmd.exe has a well-known parsing quirk: when the entire command string passed to cmd /c starts with a double-quote character, it strips the outermost matching pair of quotes before parsing the rest of the command line.
This means the command:
"C:\Program Files\...\vcvars64.bat" >nul 2>nul && cl ...
gets transformed by cmd.exe into:
C:\Program Files\...\vcvars64.bat >nul 2>nul && cl ...
The space in Program Files then causes C:\Program to be interpreted as the command name, and Files\... as an argument — resulting in the error above.
This affects all three places in the codebase where system() is called with a quoted MSVC path:
- Compiler availability check in
compiler_utils.cpp(_test_compile_simple_program) - Test compilation command in
compiler_utils.cpp(_test_compile_simple_program) - Actual codegen compilation command in
Compilation.cpp
Fix
Wrap the entire command string with an explicit cmd /c "..." invocation. When cmd.exe sees cmd /c "...", it correctly treats the outer quotes as delimiters for the full command block, and the inner quoted path is parsed properly.
Before:
// compiler_utils.cpp — availability check
std::string check_cmd = compiler_path + " >nul 2>nul";
// compiler_utils.cpp — test compile
compile_cmd = compiler_path + " >nul 2>nul && cd " + folder_name + " && cl test.cpp /LD /Ox " + avx_flag + " >nul 2>nul";
// Compilation.cpp — actual compile
command = compiler_path + enable_output;
command += " && cd /d \"" + folder + "\"";
command += " && cl " + name + ".cpp /LD /Ox /arch:AVX2 /bigobj" + enable_output;
// ...After:
// compiler_utils.cpp — availability check
std::string check_cmd = "cmd /c \"" + compiler_path + " >nul 2>nul\"";
// compiler_utils.cpp — test compile
compile_cmd = "cmd /c \"" + compiler_path + " >nul 2>nul && cd " + folder_name + " && cl test.cpp /LD /Ox " + avx_flag + " >nul 2>nul\"";
// Compilation.cpp — actual compile
std::string inner_command;
inner_command = compiler_path + enable_output;
inner_command += " && cd /d \"" + folder + "\"";
inner_command += " && cl " + name + ".cpp /LD /Ox /arch:AVX2 /bigobj" + enable_output;
inner_command += " && del " + name + ".exp && del " + name + ".lib && del " + name + ".obj";
command = "cmd /c \"" + inner_command + "\"";Impact
This bug affects any Windows machine where Visual Studio is installed in a path containing spaces, which includes the default installation path (C:\Program Files\...). The symptom is a hard failure at runtime with a misleading error message that looks like a missing compiler rather than a quoting issue.
References
- Microsoft Docs —
cmd /cand quote stripping behavior - Raymond Chen's blog: "The
cmd.execommand line quoting rules"