Skip to content

Commit e7a0db3

Browse files
committed
feat(flags): adopt mcpp.toolchain.provider in compute_flags()
Import mcpp.toolchain.provider and build a ProviderCapabilities value at the start of compute_flags(). Use caps.stdlib_id to drive the -fmodules flag decision (GCC/libstdc++ only) as a proof-of-adoption, replacing the ad-hoc isClang ternary with a semantically equivalent caps-based check. Future flag branching should use caps.* rather than adding new is_clang() or is_musl_target() call sites.
1 parent 0b379b6 commit e7a0db3

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/build/flags.cppm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import std;
1212
import mcpp.build.plan;
1313
import mcpp.toolchain.clang;
1414
import mcpp.toolchain.detect;
15+
import mcpp.toolchain.provider;
1516
import mcpp.toolchain.registry;
1617

1718
export namespace mcpp::build {
@@ -59,6 +60,12 @@ std::string escape_path(const std::filesystem::path& p) {
5960

6061
CompileFlags compute_flags(const BuildPlan& plan) {
6162
CompileFlags f;
63+
64+
// ProviderCapabilities: centralised query point for per-toolchain decisions.
65+
// Prefer caps.* checks over ad-hoc is_clang()/is_musl_target() calls for
66+
// any new branching added to this function.
67+
auto caps = mcpp::toolchain::capabilities_for(plan.toolchain);
68+
6269
f.cxxBinary = plan.toolchain.binaryPath;
6370
f.ccBinary = mcpp::toolchain::derive_c_compiler(plan.toolchain);
6471
f.toolEnv = mcpp::toolchain::compiler_env_prefix(plan.toolchain);
@@ -125,7 +132,10 @@ CompileFlags compute_flags(const BuildPlan& plan) {
125132
plan.manifest.buildConfig.cStandard.empty() ? "c11" : plan.manifest.buildConfig.cStandard;
126133

127134
// Assemble
128-
std::string module_flag = isClang ? "" : " -fmodules";
135+
// -fmodules is a GCC-only flag; Clang uses a different module ABI and does
136+
// not need it. caps.stdlib_id distinguishes GCC (libstdc++) from Clang
137+
// (libc++ / msvc-stl) without an extra is_clang() call.
138+
std::string module_flag = (caps.stdlib_id == "libstdc++") ? " -fmodules" : "";
129139
std::string std_module_flag;
130140
if (isClang && !plan.stdBmiPath.empty()) {
131141
std_module_flag = " -fmodule-file=std=" + escape_path(staged_std_bmi_path(plan));

0 commit comments

Comments
 (0)