Skip to content

[workspace.build] defines are lost for sibling path dependencies #690

Closed

Description

@julixian

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 = "llvm@20.1.7"

[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:

  1. mcpp build -p lib succeeds.
  2. mcpp build -p app fails compiling lib.cpp with WORKSPACE_DEFINE missing in library dependency. The failing compile command has no -DWORKSPACE_DEFINE=1.
  3. 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.

Activity

  1. Sunrisepeak commented on Sep 24, 2026

    @Sunrisepeak
    Member

    如果真的需要工作空间全局的宏, 目前先这样使用临时过度一下

    [workspace.build]
    cxxflags = ["-DWORKSPACE_DEFINE=1"]
    cflags   = ["-DWORKSPACE_DEFINE=1"]
    

    defines传递的一致性, 等下个版本修复发布

  2. self-assigned this
    on Sep 24, 2026
  3. added a commit that references this issue on Sep 25, 2026
  4. Sunrisepeak commented on Sep 25, 2026

    @Sunrisepeak
    Member

    @julixian 更新了传递的一致性, xlings update mcpp -y 使用最新版本再试一试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions