Skip to content

Commit 186bfd2

Browse files
committed
fix(build.mcpp): state the deployment target even when trusting clang's cfg; drop -x for cl
Two failures the local runs could not see, both the same shape — a branch that was dead while the MSVC gate existed, or a platform this machine is not. host_compile_tokens returned early on the trust-cfg path, which on macOS IS the build.mcpp path: no clang flags and no deployment target, so the std BMI (built for 14.0) was rejected by a TU compiled without it. Trusting the cfg means contributing no include paths or stdlib selection — not contributing nothing. The deployment target is emitted regardless now, which is what the hand-written host_base_flags did deliberately ("FIRST and unconditionally") before this refactor absorbed it. The `-x none` before the module objects was unconditional and harmless only while cl.exe could not reach it. Removing the module gate made the dead branch live, and cl answered `D9002: ignoring unknown option '-x'` — after compiling the .ifc and reaching the link, which is further than build.mcpp has ever gone under MSVC.
1 parent 03042a3 commit 186bfd2

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

src/build/build_program.cppm

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,13 @@ std::expected<void, std::string> run_build_program(
666666
for (auto f : dial.forceCxxLangArgv) compileArgv.emplace_back(f);
667667
compileArgv.push_back(src.string());
668668
if (usesModule || !stdObjects.empty()) {
669-
// Link the module objects (GNU: reset the input language first so the
670-
// .o isn't treated as C++ source; cl.exe infers by extension and is
671-
// unreachable here anyway, gated above).
672-
compileArgv.push_back("-x"); compileArgv.push_back("none");
669+
// Link the module objects. GNU drivers need the input language reset
670+
// first, or the .o that follows `-x c++` is handed to the frontend as
671+
// C++ source; cl.exe has no `-x` at all and infers from the extension.
672+
// This used to be unconditional and was only harmless while MSVC could
673+
// not reach it — removing that gate made the dead branch live, and cl
674+
// answered with `D9002: ignoring unknown option '-x'`.
675+
if (!msvcHost) { compileArgv.push_back("-x"); compileArgv.push_back("none"); }
673676
if (usesModule) compileArgv.push_back(mcppModuleObject.string());
674677
for (auto& so : stdObjects) compileArgv.push_back(so);
675678
}

src/toolchain/hostflags.cppm

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,28 @@ std::vector<std::string> host_compile_tokens(const Toolchain& tc,
126126
dm.hasCfg && (opt.cfgBypass == HostFlagOptions::CfgBypass::Always
127127
|| mcpp::platform::is_linux);
128128

129+
// Trusting the cfg means contributing no include paths, stdlib selection
130+
// or runtime choices — it already carries them. It does NOT mean
131+
// contributing nothing: the deployment target still has to be stated (see
132+
// below), which is why this suppresses the two blocks rather than
133+
// returning early.
134+
const bool trustCfg = !bypassCfg && dm.hasCfg;
135+
129136
if (bypassCfg) {
130137
for (auto& t : dm.compile_tokens(esc, opt.clangStdlibSelect))
131138
out.push_back(t);
132-
} else if (dm.hasCfg) {
133-
// Trusting the cfg means adding nothing at all: it already carries
134-
// the include paths, the stdlib selection and the runtime choices.
135-
return out;
136139
}
137140

141+
// Unconditional on macOS, cfg or no cfg. clang refuses to load a module
142+
// built for a different deployment target, and this result feeds every
143+
// compile that touches one — the bundled mcpp module's precompile, its
144+
// object step, and the build.mcpp compile. Skipping it on the trust-cfg
145+
// path is exactly the mismatch e2e 181 catches: the std BMI is built for
146+
// 14.0 while the TU importing it is not.
138147
if (mcpp::platform::is_macos && !opt.macosDeploymentTarget.empty())
139148
out.push_back("-mmacosx-version-min=" + opt.macosDeploymentTarget);
140149

141-
if (bypassCfg || lm.mode != CLibMode::None)
150+
if (!trustCfg && (bypassCfg || lm.mode != CLibMode::None))
142151
for (auto& t : lm.compile_tokens(esc)) out.push_back(t);
143152

144153
return out;

0 commit comments

Comments
 (0)