c++modules: Fix transitive import of object producing BMIs

Fixes: #28185
This commit is contained in:
Vito Gamberini committed 2026-10-18 12:10:56 -04:00
1 parent 1cdd7458c0
commit af81311ce6
4 files changed
+36 -5

No files matched your search

+10 -5
View File
@@ -3243,18 +3243,23 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
forward_info(transitiveInterfaceObjects, fmft["interface-objects"]);
}
// Compute the set of modules actually imported by sources in this target.
// Compute the set of modules imported directly or transitively by sources in
// this target.
std::set<std::string> usedModules;
for (cmScanDepInfo const& object : objects) {
for (auto const& r : object.Requires) {
usedModules.insert(r.LogicalName);
auto usage = usages.Usage.find(r.LogicalName);
if (usage != usages.Usage.end()) {
usedModules.insert(usage->second.begin(), usage->second.end());
}
}
}
// Merge direct interface objects into the accumulated set.
// Direct objects are filtered: only keep those for modules that are
// actually imported by sources in this target. Transitive objects from
// linked targets were already filtered in their originating target.
// Merge interface objects into the accumulated set.
// Objects are filtered: only keep those for modules that are imported
// directly or transitively by sources in this target. Transitive objects
// from linked targets were already filtered in their originating target.
if (cxx_interface_objects && cxx_interface_objects->isObject()) {
Json::Value const& directObjects =
(*cxx_interface_objects)["module-objects"];
@@ -246,6 +246,7 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
if ("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES AND
"import_std23" IN_LIST CMake_TEST_MODULE_COMPILATION)
run_cxx_module_test(imp-std)
run_cxx_module_test(imp-std-compat)
set(RunCMake_CXXModules_NO_TEST 1)
run_cxx_module_test(imp-std-no-std-json)
unset(RunCMake_CXXModules_NO_TEST)
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.29)
project(cxx_modules_import_std_compat CXX)
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
add_executable(main
main.cxx)
target_compile_features(main PRIVATE cxx_std_23)
add_test(NAME main COMMAND main)
@@ -0,0 +1,15 @@
import std.compat;
int main(int argc, char* argv[])
{
// std::chrono::current_zone() references _Global_tzdb_list, which is
// provided by std.ixx.obj on MSVC. Ensure we get a failed link if this
// definition isn't available through the transitive import of std.
static_cast<void>(std::chrono::current_zone());
if (argc > 0 && argv[0]) {
std::string argv0 = argv[0];
std::cout << "program: " << argv0 << std::endl;
}
return 0;
}