Repository navigation
Description
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 libsucceeds.mcpp build -p appfails compilinglib.cppwithWORKSPACE_DEFINE missing in library dependency. The failing compile command has no-DWORKSPACE_DEFINE=1.- Replace
defines = ["WORKSPACE_DEFINE=1"]withcxxflags = ["-DWORKSPACE_DEFINE=1"]in[workspace.build].mcpp build -p appsucceeds.
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.
Activity
Sunrisepeak commentedon Sep 24, 2026
如果真的需要工作空间全局的宏, 目前先这样使用临时过度一下
defines传递的一致性, 等下个版本修复发布
fix: a host-tool sub-build merges its dependency's conditional sectio…
2026.9.25.1: workspace members compile the same way in every position…
docs: #690 records landed, with the release and ecosystem readings (#692
Sunrisepeak commentedon Sep 25, 2026
@julixian 更新了传递的一致性, xlings update mcpp -y 使用最新版本再试一试