Skip to content

Commit 8bb8167

Browse files
committed
fix: Clang needs -x c++-module for MSVC STL .ixx files + hard self-host
Clang doesn't recognize .ixx as a module source — add -x c++-module flag when compiling MSVC STL's std.ixx. Also make self-host a hard CI requirement: mcpp must successfully build itself, and the self-hosted binary is what gets packaged.
1 parent 0b50602 commit 8bb8167

2 files changed

Lines changed: 25 additions & 28 deletions

File tree

.github/workflows/ci-windows.yml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ name: ci-windows
33
# Windows validation CI for mcpp.
44
# Step 1: Verify xlings LLVM toolchain capabilities on Windows.
55
# Step 2: xmake bootstrap to produce first mcpp.exe.
6-
# Step 3: Self-host attempt — try using mcpp.exe to build itself (via LLVM).
7-
# Currently blocked by Clang on Windows lacking import std support.
8-
# Falls back to xmake bootstrap binary for packaging.
9-
# Step 4: Package into a distributable zip (same layout as Linux/macOS).
6+
# Step 3: Self-host — use the bootstrapped mcpp.exe to build itself (LLVM + MSVC STL).
7+
# Step 4: Package the self-hosted binary into a distributable zip.
108

119
on:
1210
push:
@@ -276,25 +274,20 @@ jobs:
276274
ls "$MCPP_XPKGS/xim-x-llvm/20.1.7/bin/" | head -5
277275
fi
278276
279-
"$MCPP_EXE" build && SELF_HOST_OK=1 || SELF_HOST_OK=0
280-
281-
if [ "$SELF_HOST_OK" = "1" ]; then
282-
# Find the self-hosted binary
283-
SELF_MCPP=$(find target -name "mcpp.exe" -path "*/bin/*" | head -1)
284-
if [ -n "$SELF_MCPP" ]; then
285-
SELF_MCPP=$(cd "$(dirname "$SELF_MCPP")" && pwd)/$(basename "$SELF_MCPP")
286-
echo "Self-hosted binary: $SELF_MCPP"
287-
"$SELF_MCPP" --version
288-
echo "MCPP_SELF=$SELF_MCPP" >> "$GITHUB_ENV"
289-
else
290-
echo "::warning::self-host build succeeded but mcpp.exe not found in target/"
291-
SELF_HOST_OK=0
292-
fi
293-
fi
277+
"$MCPP_EXE" build
294278
295-
if [ "$SELF_HOST_OK" = "0" ]; then
296-
echo "::warning::Self-host build not yet possible (Clang on Windows lacks import std support). Using xmake bootstrap binary."
297-
fi
279+
# Find the self-hosted binary
280+
SELF_MCPP=$(find target -name "mcpp.exe" -path "*/bin/*" | head -1)
281+
test -n "$SELF_MCPP" || {
282+
echo "FAIL: self-host build did not produce mcpp.exe"
283+
find target -name "*.exe" 2>/dev/null
284+
exit 1
285+
}
286+
SELF_MCPP=$(cd "$(dirname "$SELF_MCPP")" && pwd)/$(basename "$SELF_MCPP")
287+
echo "Self-hosted binary: $SELF_MCPP"
288+
"$SELF_MCPP" --version
289+
290+
echo "MCPP_SELF=$SELF_MCPP" >> "$GITHUB_ENV"
298291
299292
- name: Package Windows release zip
300293
id: package
@@ -311,10 +304,9 @@ jobs:
311304
mkdir -p "$STAGING/$WRAPPER/bin"
312305
mkdir -p "$STAGING/$WRAPPER/registry/bin"
313306
314-
# Binary: prefer self-hosted build, fall back to saved bootstrap copy
315-
MCPP_BIN="${MCPP_SELF:-/tmp/mcpp-bootstrap/mcpp.exe}"
316-
echo "Packaging binary: $MCPP_BIN"
317-
cp "$MCPP_BIN" "$STAGING/$WRAPPER/bin/mcpp.exe"
307+
# Binary: use the self-hosted build
308+
echo "Packaging binary: $MCPP_SELF"
309+
cp "$MCPP_SELF" "$STAGING/$WRAPPER/bin/mcpp.exe"
318310
319311
# Launcher batch script (equivalent to the shell wrapper on Linux/macOS)
320312
printf '@echo off\r\n"%%~dp0bin\\mcpp.exe" %%*\r\n' > "$STAGING/$WRAPPER/mcpp.bat"

src/toolchain/clang.cppm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,22 @@ std::vector<std::string> std_module_build_commands(const Toolchain& tc,
197197
#if defined(_WIN32)
198198
// Windows: use absolute paths, raw binary path as first token
199199
// (cmd.exe strips leading quotes), shq for args with spaces.
200+
// -x c++-module is needed for MSVC STL's .ixx files (Clang doesn't
201+
// recognize the .ixx extension as a module source by default).
200202
auto absBmi = (cacheDir / relBmi).string();
203+
auto ext = tc.stdModuleSource.extension().string();
204+
std::string langFlag = (ext == ".ixx") ? " -x c++-module" : "";
201205
return {
202206
std::format(
203-
"{} -std=c++23 -Wno-reserved-module-identifier{} "
207+
"{} -std=c++23{}{} "
204208
"--precompile {} -o {}",
205209
tc.binaryPath.string(),
210+
langFlag,
206211
sysrootFlag,
207212
mcpp::xlings::shq(tc.stdModuleSource.string()),
208213
mcpp::xlings::shq(absBmi)),
209214
std::format(
210-
"{} -std=c++23 -Wno-reserved-module-identifier{} "
215+
"{} -std=c++23{} "
211216
"{} -c -o {}",
212217
tc.binaryPath.string(),
213218
sysrootFlag,

0 commit comments

Comments
 (0)