Skip to content

fix: [build].defines 未被传入 P1689 模块扫描,导致条件 import 与 scan_overrides 冲突 #296

Description

@ZheFeng7110

复现步骤

  1. 创建如下项目:

    src/main.cpp:

    #ifdef TEST_USE_MODULES
    import std;
    import lib;
    #else
    #include <print>
    #endif
    
    int main(int argc, char* argv[]) {
        std::println("Hello from hello!");
        printHello();
        return 0;
    }

    src/lib.cppm:

    #ifndef TEST_USE_MODULES
    module;
    #include <print>
    #endif
    
    export module lib;
    
    #ifdef TEST_USE_MODULES
    import std;
    #endif
    
    export void printHello() {
        std::println("Hello world in lib.cppm!");
    }

    mcpp.toml:

    [package]
    name        = "hello"
    version     = "0.1.0"
    description = "A modular C++23 package"
    license     = "Apache-2.0"
    
    [build]
    defines = ["TEST_USE_MODULES"]
    
    [scan_overrides."src/lib.cppm"]
    provides = ["lib"]
    imports = ["std"]
    
    [scan_overrides."src/main.cpp"]
    imports = ["std", "lib"]
  2. 运行 mcpp build。

实际行为

构建失败,报错:

error: module-graph divergence in obj/lib.m.o:
  planned : provides [lib] imports [std]
  compiler: provides [lib] imports [<none>]
  The compiler's P1689 scan disagrees with the planner's assumption
...
error: module-graph divergence in obj/main.o:
  planned : provides [<none>] imports [lib, std]
  compiler: provides [<none>] imports [<none>]

期望行为

[build].defines 应该被脱糖为 -D<x> 并传递给 P1689 模块扫描和普通编译命令,使条件 import 被正确识别,构建成功。

环境

  • mcpp 版本:2026.7.27.1
  • OS:Windows(根因跨平台)
  • 工具链:llvm@20.1.7

Activity

  1. added a commit that references this issue on Jul 28, 2026
    b6eadc1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions