Summary
[workspace.build] defines reaches a workspace member built as the selected root, but does not reach the same member when it is a sibling path dependency. The documented inheritance rule says vectors including defines are inherited by every member. In contrast, [workspace.build] cxxflags = ["-D..."] works in both positions.
Environment
- mcpp 2026.9.24.1 (repository commit
b4824697)
- Windows x86_64, LLVM 20.1.7, MSVC system sysroot 14.51.36231
Minimal reproduction
Root mcpp.toml:
[workspace]
members = ["lib", "app"]
[workspace.package]
version = "0.1.0"
standard = "c++23"
[toolchain]
windows = "[email protected]"
[workspace.build]
defines = ["WORKSPACE_DEFINE=1"]
lib/mcpp.toml:
[package]
namespace = "probe"
name = "lib"
[targets.probe_lib]
kind = "lib"
[build]
sources = ["lib.cpp"]
lib/lib.cpp:
#ifndef WORKSPACE_DEFINE
#error WORKSPACE_DEFINE missing in library dependency
#endif
int probe_lib() { return WORKSPACE_DEFINE; }
app/mcpp.toml:
[package]
namespace = "probe"
name = "app"
[dependencies]
"probe.lib" = { path = "../lib" }
[targets.probe_app]
kind = "bin"
main = "main.cpp"
app/main.cpp:
int probe_lib();
int main() { return probe_lib() != 1; }
From the workspace root:
mcpp build -p lib succeeds.
mcpp build -p app fails compiling lib.cpp with WORKSPACE_DEFINE missing in library dependency. The failing compile command has no -DWORKSPACE_DEFINE=1.
- Replace
defines = ["WORKSPACE_DEFINE=1"] with cxxflags = ["-DWORKSPACE_DEFINE=1"] in [workspace.build]. mcpp build -p app succeeds.
Expected
The lib member receives workspace defines in both builds, as documented in docs/07-workspace.md under the [workspace.build] merge rule.
Suspected cause
In src/build/prepare.cppm, fold_build_defines_into_flags(dep_manifest->buildConfig) runs for a path dependency before makePackageRoot calls inherit_workspace_build. The latter prepends the workspace defines after that fold, while makePackageRoot copies cflags and cxxflags to privateBuild without folding defines again. Thus inherited cxxflags reach the compiler, but inherited defines remain unused. The selected root takes a different path and works.
Summary
[workspace.build] definesreaches a workspace member built as the selected root, but does not reach the same member when it is a siblingpathdependency. The documented inheritance rule says vectors includingdefinesare inherited by every member. In contrast,[workspace.build] cxxflags = ["-D..."]works in both positions.Environment
b4824697)Minimal reproduction
Root
mcpp.toml:lib/mcpp.toml:lib/lib.cpp:app/mcpp.toml:app/main.cpp:From the workspace root:
mcpp build -p libsucceeds.mcpp build -p appfails compilinglib.cppwithWORKSPACE_DEFINE missing in library dependency. The failing compile command has no-DWORKSPACE_DEFINE=1.defines = ["WORKSPACE_DEFINE=1"]withcxxflags = ["-DWORKSPACE_DEFINE=1"]in[workspace.build].mcpp build -p appsucceeds.Expected
The
libmember receives workspacedefinesin both builds, as documented indocs/07-workspace.mdunder the[workspace.build]merge rule.Suspected cause
In
src/build/prepare.cppm,fold_build_defines_into_flags(dep_manifest->buildConfig)runs for a path dependency beforemakePackageRootcallsinherit_workspace_build. The latter prepends the workspacedefinesafter that fold, whilemakePackageRootcopiescflagsandcxxflagstoprivateBuildwithout foldingdefinesagain. Thus inheritedcxxflagsreach the compiler, but inheriteddefinesremain unused. The selected root takes a different path and works.