diff options
| author | ruki <[email protected]> | 2025-08-19 10:59:05 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-19 10:59:05 +0800 |
| commit | c31cd67e1815e37620a1b8b252240d5dbbc1ed85 (patch) | |
| tree | 08b139dda7dbdc9095d2c77e66704ffa5833db79 | |
| parent | 56eaa5721cb8408013ebde1d95b84a3b3872d9d7 (diff) | |
| parent | de2dd38726f49b8bdedd17641486a3d3a39907aa (diff) | |
Merge pull request #6712 from Arthapz/fix-moduleonly-installation
fix(c++ modules) fix disabled target getting configured for module compilation
6 files changed, 53 insertions, 7 deletions
diff --git a/tests/projects/c++/modules/install_with_false_default/src/foo.mpp b/tests/projects/c++/modules/install_with_false_default/src/foo.mpp new file mode 100644 index 000000000..1945fd300 --- /dev/null +++ b/tests/projects/c++/modules/install_with_false_default/src/foo.mpp @@ -0,0 +1,5 @@ +export module foo; + +export namespace foo { + void foo() {} +} diff --git a/tests/projects/c++/modules/install_with_false_default/src/main.cpp b/tests/projects/c++/modules/install_with_false_default/src/main.cpp new file mode 100644 index 000000000..d201aa1a2 --- /dev/null +++ b/tests/projects/c++/modules/install_with_false_default/src/main.cpp @@ -0,0 +1,6 @@ +import foo; + +int main() { + foo::foo(); + return 0; +} diff --git a/tests/projects/c++/modules/install_with_false_default/test.lua b/tests/projects/c++/modules/install_with_false_default/test.lua new file mode 100644 index 000000000..14ef968af --- /dev/null +++ b/tests/projects/c++/modules/install_with_false_default/test.lua @@ -0,0 +1,23 @@ +inherit(".test_base") +import("utils.ci.is_running", {alias = "ci_is_running"}) + +CLANG_MIN_VER = is_subhost("windows") and "19" or "17" +GCC_MIN_VER = "11" +MSVC_MIN_VER = "14.29" + +function _build(check_outdata) + local flags = "" + if ci_is_running() then + flags = "-vD" + end + os.run("xmake -r " .. flags) + os.run("xmake b -r " .. flags .. " module_test1") + os.run("xmake install " .. flags .. " --installdir=out") +end + +function main(_) + local clang_options = {compiler = "clang", version = CLANG_MIN_VER, build = _build} + local gcc_options = {compiler = "gcc", version = GCC_MIN_VER, build = _build} + local msvc_options = {version = MSVC_MIN_VER, build = _build} + run_tests(clang_options, gcc_options, msvc_options) +end diff --git a/tests/projects/c++/modules/install_with_false_default/xmake.lua b/tests/projects/c++/modules/install_with_false_default/xmake.lua new file mode 100644 index 000000000..6274cda01 --- /dev/null +++ b/tests/projects/c++/modules/install_with_false_default/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") + +target("module_test") + set_kind("moduleonly") + add_files("src/*.mpp") + +target("module_test1") + set_kind("binary") + set_default(false) + add_deps("module_test") + add_files("src/*.cpp") diff --git a/xmake/rules/c++/modules/config.lua b/xmake/rules/c++/modules/config.lua index 401f3ebc0..a0f7dcc33 100644 --- a/xmake/rules/c++/modules/config.lua +++ b/xmake/rules/c++/modules/config.lua @@ -76,11 +76,6 @@ function main(target) target:add("files") end - local memcache = support.memcache() - local targets = memcache:get("targets") or {} - targets[target:fullname()] = {} - targets[target:fullname()].finished_parsing = false - memcache:set("targets", targets) -- moduleonly modules are implicitly public if target:is_moduleonly() then local sourcebatches = target:sourcebatches() diff --git a/xmake/rules/c++/modules/scanner.lua b/xmake/rules/c++/modules/scanner.lua index 294d73e21..fa2c3b98b 100644 --- a/xmake/rules/c++/modules/scanner.lua +++ b/xmake/rules/c++/modules/scanner.lua @@ -507,7 +507,6 @@ function _do_computedag(target, modules, sourcebatch) localcache:save() end profiler.leave(target:fullname(), "c++ modules", "scanner", "compute dag") - -- jobgraph:dump() end function _do_scan(target, sourcefile, opt) @@ -879,7 +878,7 @@ end function get_modules(target) local modules = support.localcache():get2(target:fullname(), "c++.modules") - assert(modules, "no modules!") + assert(modules, "no modules! (" .. target:fullname() .. ")") return modules end @@ -914,6 +913,12 @@ function main(target, jobgraph, sourcebatch) profiler.enter(target:fullname(), "c++ modules", "scanner", "scan") local compile_commands = os.getenv("XMAKE_IN_PROJECT_GENERATOR") and os.getenv("XMAKE_IN_COMPILE_COMMANDS_PROJECT_GENERATOR") if target:data("cxx.has_modules") and (not os.getenv("XMAKE_IN_PROJECT_GENERATOR") or compile_commands) then + local memcache = support.memcache() + local targets = memcache:get("targets") or {} + targets[target:fullname()] = {} + targets[target:fullname()].finished_parsing = false + memcache:set("targets", targets) + _patch_sourcebatch(target, sourcebatch) _schedule_module_dependencies_scan(target, jobgraph, sourcebatch) end |
