From e5ba7a1d14ef6f8afa2491b4dc0131169aaa4a76 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 21 Jul 2024 16:48:40 +0200 Subject: [PATCH] add a policy to disable module culling --- tests/projects/c++/modules/culling/src/hello.mpp | 10 ++++++++++ tests/projects/c++/modules/culling/test.lua | 1 + tests/projects/c++/modules/culling/xmake.lua | 7 +++++++ xmake/core/project/policy.lua | 2 ++ .../modules/modules_support/dependency_scanner.lua | 14 +++++++++----- 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 tests/projects/c++/modules/culling/src/hello.mpp create mode 100644 tests/projects/c++/modules/culling/test.lua create mode 100644 tests/projects/c++/modules/culling/xmake.lua diff --git a/tests/projects/c++/modules/culling/src/hello.mpp b/tests/projects/c++/modules/culling/src/hello.mpp new file mode 100644 index 00000000000..124bd72bc37 --- /dev/null +++ b/tests/projects/c++/modules/culling/src/hello.mpp @@ -0,0 +1,10 @@ +module; +#include + +export module hello; + +export namespace hello { + void say(const char* str) { + printf("%s\n", str); + } +} diff --git a/tests/projects/c++/modules/culling/test.lua b/tests/projects/c++/modules/culling/test.lua new file mode 100644 index 00000000000..7717f804997 --- /dev/null +++ b/tests/projects/c++/modules/culling/test.lua @@ -0,0 +1 @@ +inherit(".test_base") diff --git a/tests/projects/c++/modules/culling/xmake.lua b/tests/projects/c++/modules/culling/xmake.lua new file mode 100644 index 00000000000..33d3934b9ff --- /dev/null +++ b/tests/projects/c++/modules/culling/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") + +target("culling") + set_kind("static") + add_files("src/*.mpp") + set_policy("build.c++.modules.culling", false) diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 4b5ef9dae6f..2eb2c119387 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -72,6 +72,8 @@ function policy.policies() ["build.c++.modules"] = {description = "Enable C++ modules for C++ building.", type = "boolean"}, -- Enable std module ["build.c++.modules.std"] = {description = "Enable std modules.", default = true, type = "boolean"}, + -- Enable unreferenced and non-public named module culling + ["build.c++.modules.culling"] = {description = "Enable unrefereced and non-public named module culling.", default = true, type = "boolean"}, -- Try to reuse compiled module bmi file if targets flags permit it ["build.c++.modules.tryreuse"] = {description = "Try to reuse compiled module if possible.", default = true, type = "boolean"}, -- Enable module taking defines acbount for bmi reuse discrimination diff --git a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua index d59a4436a60..cef55fbd5ec 100644 --- a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua @@ -422,11 +422,15 @@ function sort_modules_by_dependencies(target, objectfiles, modules) local objectfiles_sorted_set = hashset.from(objectfiles_sorted) for _, objectfile in ipairs(objectfiles) do if not objectfiles_sorted_set:has(objectfile) then - -- cull unreferenced non-public named module but add non-module files and implementation modules - local _, provide, cppfile = compiler_support.get_provided_module(modules[objectfile]) - local fileconfig = target:fileconfig(cppfile) - local public = fileconfig and fileconfig.public - if not provide or public then + if target:policy("build.c++.modules.culling") then + -- cull unreferenced non-public named module but add non-module files and implementation modules + local _, provide, cppfile = compiler_support.get_provided_module(modules[objectfile]) + local fileconfig = target:fileconfig(cppfile) + local public = fileconfig and fileconfig.public + if not provide or public then + table.insert(result, objectfile) + end + else table.insert(result, objectfile) end end