Skip to content

Commit 0b50602

Browse files
committed
fix: Windows std module build — restore shq outer quotes + absolute paths
shq() needs outer double quotes for arguments with spaces (like MSVC's std.ixx path in "Program Files"). Restored outer quotes in shq() with a note: don't use shq for the first token (binary path). std_module_build_commands on Windows uses absolute paths and raw binary path as first token to avoid cmd.exe quote-stripping.
1 parent 8ee2933 commit 0b50602

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/toolchain/clang.cppm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,27 @@ std::vector<std::string> std_module_build_commands(const Toolchain& tc,
194194
const std::filesystem::path& bmiPath,
195195
std::string_view sysrootFlag) {
196196
auto relBmi = std::filesystem::relative(bmiPath, cacheDir).string();
197+
#if defined(_WIN32)
198+
// Windows: use absolute paths, raw binary path as first token
199+
// (cmd.exe strips leading quotes), shq for args with spaces.
200+
auto absBmi = (cacheDir / relBmi).string();
201+
return {
202+
std::format(
203+
"{} -std=c++23 -Wno-reserved-module-identifier{} "
204+
"--precompile {} -o {}",
205+
tc.binaryPath.string(),
206+
sysrootFlag,
207+
mcpp::xlings::shq(tc.stdModuleSource.string()),
208+
mcpp::xlings::shq(absBmi)),
209+
std::format(
210+
"{} -std=c++23 -Wno-reserved-module-identifier{} "
211+
"{} -c -o {}",
212+
tc.binaryPath.string(),
213+
sysrootFlag,
214+
mcpp::xlings::shq(absBmi),
215+
mcpp::xlings::shq((cacheDir / "std.o").string()))
216+
};
217+
#else
197218
return {
198219
std::format(
199220
"cd {} && {}{} -std=c++23 -Wno-reserved-module-identifier{} "
@@ -213,6 +234,7 @@ std::vector<std::string> std_module_build_commands(const Toolchain& tc,
213234
sysrootFlag,
214235
mcpp::xlings::shq(relBmi))
215236
};
237+
#endif
216238
}
217239

218240
std::filesystem::path archive_tool(const Toolchain& tc) {

src/xlings.cppm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,16 @@ std::string shq(std::string_view s) {
321321
std::string out;
322322
out.reserve(s.size() + 2);
323323
#if defined(_WIN32)
324-
// Windows: popen/system go through cmd.exe /c. To avoid cmd.exe's
325-
// special quote-stripping when the command starts with ", we don't
326-
// wrap in outer quotes. Instead, escape inner " as \" which the
327-
// MSVC C runtime's argv parser understands.
324+
// Windows: wrap in double quotes, escape inner " as \".
325+
// IMPORTANT: avoid placing a shq'd token as the FIRST token in a
326+
// popen/system command — cmd.exe strips a leading " pair. For
327+
// binary paths, use the raw string; shq is safe for arguments.
328+
out.push_back('"');
328329
for (char c : s) {
329330
if (c == '"') out += "\\\"";
330331
else out.push_back(c);
331332
}
332-
return out;
333+
out.push_back('"');
333334
#else
334335
out.push_back('\'');
335336
for (char c : s) {

0 commit comments

Comments
 (0)