Skip to content

Commit 3fa6f87

Browse files
committed
feat(macos): built-in default deployment floor 14.0 (rustc-style)
cargo's key portability win on macOS is that every Apple target carries a built-in default deployment target (aarch64 = 11.0) instead of floating with the host SDK — artifacts run on older systems with zero configuration. Adopt the same: when neither MACOSX_DEPLOYMENT_TARGET nor [build] macos_deployment_target is set and staticStdlib is on, default the floor to 14.0 (the official LLVM static libc++ archives' own floor). Mirrored in the fingerprint rule. Without staticStdlib the toolchain/SDK default still applies (a dynamically-linked binary can't promise a lower floor than the host libc++ anyway).
1 parent 563c203 commit 3fa6f87

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

docs/05-mcpp-toml.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ macos_deployment_target = "14.0" # macOS 产物的最低支持系统版本(仅
9898
(`LC_BUILD_VERSION minos`),即二进制能运行的最老 macOS。优先级与各生态
9999
惯例一致:环境变量 `MACOSX_DEPLOYMENT_TARGET`(单次调用的显式覆盖,
100100
cargo/rustc、cc 等同样尊重该变量)> 本字段(项目默认,类似 SwiftPM 的
101-
`platforms:`)> 工具链/SDK 默认。该值会进入 BMI 指纹——切换 target 会
102-
自动重建模块缓存。
101+
`platforms:`)> **内建默认 14.0**(rustc 式:target 自带默认 floor 而非
102+
跟随构建机 SDK;14.0 是工具链静态 libc++ 的下限,`static_stdlib = false`
103+
时回退工具链/SDK 默认)。该值会进入 BMI 指纹——切换 target 会自动重建
104+
模块缓存。
103105

104106
C++ 标准不要通过 `build.cxxflags = ["-std=..."]` 配置。请使用:
105107

src/build/flags.cppm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ CompileFlags compute_flags(const BuildPlan& plan) {
109109
} else {
110110
macosDeploymentTarget = plan.manifest.buildConfig.macosDeploymentTarget;
111111
}
112+
// Built-in default floor (rustc-style: every Apple target carries a
113+
// default deployment target instead of floating with the host SDK).
114+
// When neither the env var nor the manifest pins one, default to the
115+
// floor of the toolchain's static libc++ archives (the official LLVM
116+
// darwin archives are built for macOS 14) — artifacts are portable by
117+
// default and don't silently change floor when the build host's SDK
118+
// moves. Resolved here so the value also reaches the fingerprint via
119+
// the same canonical-flags rule (see cli.cppm).
120+
if (macosDeploymentTarget.empty() && mcpp::platform::is_macos
121+
&& plan.manifest.buildConfig.staticStdlib) {
122+
macosDeploymentTarget = "14.0";
123+
}
112124

113125
f.cxxBinary = plan.toolchain.binaryPath;
114126
f.ccBinary = mcpp::toolchain::derive_c_compiler(plan.toolchain);

src/cli.cppm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,12 @@ std::string canonical_compile_flags(const mcpp::manifest::Manifest& m) {
600600
} else {
601601
dtv = m.buildConfig.macosDeploymentTarget;
602602
}
603+
// Mirror flags.cppm's built-in default floor (14.0 with
604+
// staticStdlib) so the fingerprint matches the flags actually
605+
// emitted.
606+
if (dtv.empty() && m.buildConfig.staticStdlib) {
607+
dtv = "14.0";
608+
}
603609
if (!dtv.empty()) {
604610
s += " macos_deployment_target=";
605611
s += dtv;

0 commit comments

Comments
 (0)