Skip to content

Commit 5c725c7

Browse files
committed
fix(build.mcpp,ci): one deployment target for every host compile; restore xlings in the no-VS job
macOS rejected `import std;` together with `import mcpp;`: mcpp.pcm had been built at the host default (15.0) while the compile consuming it now carried 14.0. Putting the flag on the std path alone just moved the mismatch to the other module — clang refuses either direction. The deployment target now lives in host_base_flags, which feeds every compile in this file: the bundled mcpp module's precompile, its object step, and the build.mcpp compile. One resolution, one place, and the same value goes to stdmod so the std BMI agrees too. The bare-Windows job also needs xlings back — masking Visual Studio worked (the postcondition and e2e 182's own self-check both confirm it), but dropping the build step took bootstrap-mcpp with it, so mcpp had no backend to install the winlibs toolchain through. It runs after masking, where nothing it does can hold Visual Studio open.
1 parent ab630fd commit 5c725c7

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

.github/workflows/ci-windows.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ jobs:
206206
}
207207
Write-Host "Visual Studio masked: no VC\Tools\MSVC remains."
208208
209+
# After masking, so nothing this action does can be holding Visual
210+
# Studio open. It installs xlings (which mcpp resolves the winlibs
211+
# toolchain through) and a released mcpp; neither needs a C++ compiler,
212+
# so a masked VS is irrelevant to it.
213+
- uses: ./.github/actions/bootstrap-mcpp
214+
209215
- name: "No Visual Studio: fallback to winlibs GCC (e2e 182)"
210216
shell: bash
211217
env:

src/build/build_program.cppm

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,24 @@ std::string env_value(const std::string& name) {
184184
// --target, prepare.cppm resolves the spec a second time without the target axis
185185
// (host_tc_for_build_program) and passes that here, so the native cases are the
186186
// only ones needed. Passed as separate argv tokens (no shell).
187-
std::vector<std::string> host_base_flags(const mcpp::toolchain::Toolchain& tc) {
187+
std::vector<std::string> host_base_flags(const mcpp::toolchain::Toolchain& tc,
188+
std::string_view macosDeploymentTarget) {
188189
std::vector<std::string> f;
189190

191+
// macOS deployment target, FIRST and unconditionally, because clang
192+
// refuses to load a module built for a different one and this function's
193+
// result feeds every compile in this file: the bundled `mcpp` module's
194+
// precompile, its object step, and the build.mcpp compile itself. Putting
195+
// it anywhere narrower produced the mismatch in whichever direction was
196+
// left out — first the std BMI (built for 14.0) against a compile with no
197+
// version-min, then mcpp.pcm (built at the host default 15.0) against a
198+
// compile that had just been given 14.0.
199+
if constexpr (mcpp::platform::is_macos) {
200+
if (!macosDeploymentTarget.empty())
201+
f.push_back(std::string("-mmacosx-version-min=")
202+
+ std::string(macosDeploymentTarget));
203+
}
204+
190205
// MSVC carries none of this on the command line: cl.exe and link.exe find
191206
// headers and import libraries through INCLUDE / LIB, which detection
192207
// synthesized into tc.envOverrides. Emitting the GNU shapes below would
@@ -712,7 +727,13 @@ std::expected<void, std::string> run_build_program(
712727
tc, cppStandard.canonical.empty() ? std::string_view("c++23")
713728
: std::string_view(cppStandard.canonical),
714729
cppStandard.level);
715-
auto base = host_base_flags(tc);
730+
// One resolution of the deployment target, used by every compile below
731+
// and by the std module it asks stdmod to build — they must agree or
732+
// clang rejects the BMI.
733+
const std::string macosDeploymentTarget =
734+
mcpp::platform::macos::deployment_target(
735+
m.buildConfig.macosDeploymentTarget);
736+
auto base = host_base_flags(tc, macosDeploymentTarget);
716737

717738
// The host compile has always been spelled in GNU driver syntax with no
718739
// dialect branch at all — `grep -i msvc` over this file used to hit only
@@ -781,9 +802,6 @@ std::expected<void, std::string> run_build_program(
781802
" Use #include in build.mcpp, or switch to a toolchain "
782803
"that provides one.", tc.label()));
783804
}
784-
const std::string macosDeploymentTarget =
785-
mcpp::platform::macos::deployment_target(
786-
m.buildConfig.macosDeploymentTarget);
787805
auto sm = mcpp::toolchain::ensure_built(
788806
tc, cppStandard.canonical, std_flag, macosDeploymentTarget);
789807
if (!sm) {
@@ -792,19 +810,6 @@ std::expected<void, std::string> run_build_program(
792810
"built for the host toolchain: {}", sm.error().message));
793811
}
794812

795-
// The std BMI was built FOR a deployment target, and clang refuses to
796-
// load a module built for a different one ("compiled for the target
797-
// 'arm64-apple-macosx14.0.0' but the current translation unit is
798-
// being compiled for …"). The main build makes the value explicit on
799-
// every TU for exactly this reason (flags.cppm); the build.mcpp
800-
// compile has to say the same thing or the BMI it just asked for is
801-
// rejected. host_base_flags contributes nothing here — on macOS it
802-
// trusts the clang cfg and returns empty.
803-
if constexpr (mcpp::platform::is_macos) {
804-
if (!macosDeploymentTarget.empty())
805-
stdFlags.push_back("-mmacosx-version-min=" + macosDeploymentTarget);
806-
}
807-
808813
auto traits = mcpp::toolchain::bmi_traits(tc);
809814
if (traits.stdBmiUsePrefix.empty()) {
810815
// GCC: BMIs are found implicitly under <cwd>/gcm.cache, so stage

0 commit comments

Comments
 (0)