feat(build.mcpp): typed import mcpp; build module bundled in the binary (v0.0.81)#193
Merged
Conversation
…ry (v0.0.81) build.mcpp can be written modules-first — import mcpp; (no #include, no import std;) — calling a typed API (mcpp::cxxflag/define/link_lib/generated/…) that emits the same mcpp: wire protocol the engine already parses. Architecture (see .agents/docs/2026-06-30-build-mcpp-module-library-design.md): the helper IS part of the engine's ABI (it speaks this mcpp's protocol), so it ships WITH the engine, not as a versioned package — the Zig std.Build model, not Cargo's build-dep model. Embed the module SOURCE (constexpr string), not a BMI (BMIs are compiler-version-locked); compile on demand against the resolved host toolchain into target/.build-mcpp/ (GCC: -fmodules gcm.cache; Clang: --precompile .pcm). I/O is C-level so the module needs no import std. Gated on actual use: mcpp only builds/links the module when build.mcpp contains 'import mcpp' — a #include-based program compiles byte-identically to before (zero blast radius). Uses the 0.0.79 capture_exec cwd to let GCC find gcm.cache/. - src/build/build_program.cppm: kMcppModuleSource + build_mcpp_module + use-gating - tests/e2e/92_build_mcpp_import.sh (GCC path); docs/07-build-mcpp.md (+zh) - design doc; version -> 0.0.81. Clang path covered by the mcpp-index build-mcpp member's workspace job on macOS/Windows.
…anner doesn't misread it The Windows self-host build uses the default regex module scanner, which read the 'export module mcpp;' line inside kMcppModuleSource (a raw string literal) as build_program.cppm exporting a second module -> 'file already exports module ... cannot export mcpp'. Use a @module@ placeholder in the embedded source, substituted with 'export module' when written. No behavior change; the generated mcpp.cppm is identical.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
build.mcppcan now be written modules-first —import mcpp;(no#include, noimport std;) — calling a typed API that emits the samemcpp:wire protocol the engine parses:Completes the L3 follow-up (task #20).
Architecture (design doc included)
The helper speaks this mcpp's protocol → it's part of the engine's ABI, not a third-party library. So it ships with the engine (Zig
std.Buildmodel), not as a versioned registry package (Cargo build-dep model) — eliminating version skew. And we embed the source (constexpr std::string_view), not a prebuilt BMI: BMIs are compiler-version-locked (a matrix nightmare), whereas one source string compiles against whatever host toolchain resolved. Compiled on demand intotarget/.build-mcpp/(GCC-fmodulesgcm.cache; Clang--precompile.pcm); I/O is C-level so the module needs noimport std;.Gated on use — mcpp only builds/links the module when
build.mcppcontainsimport mcpp; a#include-based program compiles byte-identically to before (zero blast radius). Uses the 0.0.79capture_execcwd so GCC findsgcm.cache/.See
.agents/docs/2026-06-30-build-mcpp-module-library-design.mdfor the full five-axis (简洁/覆盖/优化/稳定/适配) comparison of the four options considered.Files
src/build/build_program.cppm—kMcppModuleSource+build_mcpp_module(GCC/Clang) + use-gating.tests/e2e/92_build_mcpp_import.sh— GCC path (typed directives + generated source reach the build).docs/07-build-mcpp.md(+zh) — new typed-API section.Verified locally (0.0.81)
92passes;89/90/91regress clean (the#includepath is unchanged). The Clang path is covered by the mcpp-indexbuild-mcppmember's workspace job on macOS/Windows (a follow-up PR converts it toimport mcpp;).🤖 Generated with Claude Code