@@ -92,6 +92,37 @@ If your `build.mcpp` also needs to *write* a generated file, mix in a textual
9292stdout protocol above remains the low-level substrate; ` import mcpp; ` is the typed
9393layer over it.
9494
95+ ## Environment contract (mcpp 0.0.95+)
96+
97+ The running program receives the build context as ` MCPP_* ` variables
98+ (Cargo's env-family equivalent), also exposed through typed readers:
99+
100+ | Variable | Typed reader | Value |
101+ | ---| ---| ---|
102+ | ` MCPP_TARGET ` | ` mcpp::target() ` | resolved canonical triple (the ` --target ` triple under cross; the host triple natively) |
103+ | ` MCPP_HOST ` | ` mcpp::host() ` | the host triple |
104+ | ` MCPP_PROFILE ` | ` mcpp::profile() ` | effective profile name (` dev ` /` release ` /…) |
105+ | ` MCPP_OUT_DIR ` | ` mcpp::out_dir() ` | a writable scratch/output dir owned by mcpp |
106+ | ` MCPP_MANIFEST_DIR ` | ` mcpp::manifest_dir() ` | the package root (= CWD) |
107+ | ` MCPP_FEATURE_<NAME> ` | ` mcpp::has_feature("name") ` | set to ` 1 ` per active feature (same ` <NAME> ` sanitization as the ` MCPP_FEATURE_ ` compile macro) |
108+ | ` MCPP_FEATURES ` | — | comma-separated active feature list |
109+
110+ These values are folded into the re-run key ** unconditionally** — changing the
111+ target, profile, or feature set re-runs the program without any
112+ ` rerun-if-env-changed ` declaration.
113+
114+ ## Dependencies' build.mcpp (mcpp 0.0.95+)
115+
116+ A dependency that ships a ` build.mcpp ` gets it compiled and run too (the
117+ Cargo ` build.rs ` model — building a package means trusting its build program),
118+ after its features are resolved and before the source scan. Scope follows
119+ Cargo: ` cxxflag ` /` cflag ` /` cfg ` directives color ** only that package's own
120+ TUs** ; ` link-lib ` /` link-search ` reach the final link. Its artifacts (binary,
121+ cache, ` MCPP_OUT_DIR ` ) live in the ** consuming project's**
122+ ` target/.build-mcpp/deps/<pkg>@<ver>/ ` — a registry package root is shared
123+ across projects (and may be read-only), so it is never written to; relative
124+ ` generated= ` paths resolve against ` MCPP_OUT_DIR ` , not the package root.
125+
95126## Incremental: declared inputs (no needless re-runs)
96127
97128mcpp does ** not** re-run ` build.mcpp ` on every build. It caches the program's
@@ -113,11 +144,11 @@ When nothing changed you'll see `build.mcpp up to date (cached)`; otherwise
113144
114145## Notes & limits
115146
116- - ** Runs on the host. ** ` build.mcpp ` compiles and runs with the host toolchain.
117- Under a cross build ( ` mcpp build --target <triple> ` ) it is ** skipped with a
118- warning ** for now ( host-toolchain-for-cross is a planned follow-up). Gate
119- * dependencies * on the target with ` [target.'cfg(...)'] ` tables instead — those
120- evaluate on the resolved target. See [ 05 - mcpp.toml Manifest Guide] ( 05-mcpp-toml.md ) .
147+ - ** Runs on the host — including under cross ** (mcpp 0.0.95+). Under
148+ ` mcpp build --target <triple> ` the program is compiled with a host-resolved
149+ toolchain, runs on the host, and sees ` MCPP_TARGET ` = the cross triple.
150+ For purely declarative target gating, ` [target.'cfg(...)'] ` tables remain
151+ the first choice — see [ 05 - mcpp.toml Manifest Guide] ( 05-mcpp-toml.md ) .
121152- ** CWD is the project root** , so relative paths (` src/generated.cpp ` ) land where
122153 you expect.
123154- A non-zero exit from ` build.mcpp ` aborts the build and prints its output.
0 commit comments