fix: fold [build].defines into cflags/cxxflags before P1689 scan - #297
Conversation
[build].defines was parsed but never folded into the compile flags used by the P1689 module scanner. When imports were guarded by a macro from [build].defines, the scanner saw no imports while the planner (via scan_overrides) expected them, causing module-graph divergence. - Add defines to BuildConfig - Parse [build].defines in TOML loader - Fold defines into -D<x> on cflags/cxxflags before snapshot/fingerprint - Add unit test and E2E regression test - Update English and Chinese docs Closes mcpp-community#296
[build].defines was parsed but never folded into the compile flags used by the P1689 module scanner. When imports were guarded by a macro from [build].defines, the scanner saw no imports while the planner (via scan_overrides) expected them, causing module-graph divergence. - Add defines to BuildConfig - Parse [build].defines in TOML loader - Fold defines into -D<x> on cflags/cxxflags before snapshot/fingerprint - Add unit test and E2E regression test - Update English and Chinese docs Closes mcpp-community#296
…to fix/build-defines-p1689-scan # Conflicts: # tests/e2e/167_build_defines_module_scan.sh
…owing unknown keys (2026.7.28.1) Review follow-up on mcpp-community#297. The original fix routed `[build].defines` to the P1689 scan correctly — the mechanism was right and the fold sites already mirrored the mcpp-community#229 conditional-merge funnel. Two things were left open. 1. `defines` lived on BuildConfig, not BuildInputs. The cfg axis carries `ConditionalConfig::inputs`, a BuildInputs — that is the whole point of the type (mcpp-community#258): "membership here is the answer, and it is a type rather than a hand-kept list, so it cannot drift." A BuildConfig- only field is therefore inexpressible under `[target.'cfg(...)'.build]`, and since the conditional reader only reads keys it knows, a platform-only macro vanished without a word — mcpp-community#296's own failure mode, one section over. The fold's comment claimed conditional defines landed; they could not. `defines` is moved to BuildInputs, append() carries it, the conditional reader reads it, and the emptiness gate counts it (a section with only `defines` was being dropped before it was ever evaluated). 2. The root cause was never "defines wasn't folded" — it was that `[build]` read its keys with a bare if-chain and silently discarded everything else. That is mcpp-community#131's footgun, which `[targets.<name>]` already guards against with exactly the comment that describes mcpp-community#296: "a `[targets.x] cxxflags` typo on an older mcpp just vanished." `[build]` and `[target.<pred>.build]` now get the same treatment — a schema warning, an error under --strict. Verified against all 116 mcpp.toml in the repo and every heredoc manifest in tests/: zero false positives. (`build.default_*` in the e2e fixtures is the GLOBAL config.toml, parsed by config.cppm, and is untouched by this.) Also: the xpkg descriptor listed `defines` as a did-you-mean redirect to `flags`. The two manifest surfaces are two spellings of one schema, so a key accepted in an mcpp.toml must not be an unknown-key error in a descriptor — `defines` is now a real key there and in `target_cfg`, and only the singular misspelling still redirects. Tests — the new call sites had no coverage at all, and two thirds of the existing fold sites were untested: - conditional `defines` parse, defines-only section, append() merge, both unknown-key guards, and a manifest exercising every supported `[build]` key so the guard can't fire on one (129 -> 136 unit tests) - e2e 167 rewritten: toolchain-neutral (a LOCAL module, not `import std`, so it runs on Windows where mcpp-community#296 was reported), #error guards as the assertion, plus NAME=value, a value containing a space (the -D quoting path from mcpp-community#234), the cfg axis, a path DEPENDENCY's own defines, and non-propagation to the consumer - e2e 167 no longer masks a failing `mcpp run` behind `tail`'s exit status - e2e 93 asserts `defines` parses as a known descriptor key Version bumped to 2026.7.28.1 (check_version_pins.sh green; the bootstrap MCPP_PIN stays at the released 2026.7.27.1).
Review 跟进 —— 已 push 一个 follow-up commit先说结论:原修复方向是对的。我把链路实测追了一遍 —— fold 落在 在这个基础上补了两处。 1.
|
Summary
[build].defineswas parsed by the TOML loader but never folded into the compile flags used by the P1689 module scanner. Whenimportstatements were guarded by a macro declared in[build].defines, the scanner saw no imports, while the planner (viascan_overrides) expected them, causing a plan-vs-scan divergence.This PR fixes that by:
definestoBuildConfiginsrc/manifest/types.cppm.[build].definesinsrc/manifest/toml.cppm.fold_build_defines_into_flags()insrc/build/prepare.cppmto desugardefinesinto-D<x>on bothcflagsandcxxflagsbefore the manifest is snapshotted into packages and before fingerprinting.tests/e2e/167_build_defines_module_scan.sh) that mirrors the conditional-import +scan_overridesscenario.docs/05-mcpp-toml.mdanddocs/zh/05-mcpp-toml.md.Closes #296
Test plan
mcpp buildself-hosts successfully.mcpp test unit/test_manifestpasses.tests/e2e/167_build_defines_module_scan.shpasses.