diff options
| author | ruki <[email protected]> | 2024-03-10 21:41:48 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-10 21:41:48 +0800 |
| commit | 979b1216dcd7f3f9fe8b220ac050901b42f5cae9 (patch) | |
| tree | 8f3557ab6056416e3550df60e469dd83016c2a52 | |
| parent | 9acdd03fd2460a100c90fd3d765d298413a1b1c9 (diff) | |
| parent | 326e26a5268233f3573b6104f69122b1ef5148eb (diff) | |
Merge pull request #4814 from Arthapz/fix-moduleonly-private-dep-objectfiles
Fix moduleonly private dep objectfiles
10 files changed, 51 insertions, 8 deletions
diff --git a/tests/projects/c++/modules/moduleonly_private_dep/src/main.cpp b/tests/projects/c++/modules/moduleonly_private_dep/src/main.cpp new file mode 100644 index 000000000..0fdfc6d11 --- /dev/null +++ b/tests/projects/c++/modules/moduleonly_private_dep/src/main.cpp @@ -0,0 +1,5 @@ +import B; + +int main() { + return func(); +} diff --git a/tests/projects/c++/modules/moduleonly_private_dep/src/modA.mpp b/tests/projects/c++/modules/moduleonly_private_dep/src/modA.mpp new file mode 100644 index 000000000..03a8f6ae1 --- /dev/null +++ b/tests/projects/c++/modules/moduleonly_private_dep/src/modA.mpp @@ -0,0 +1,3 @@ +export module A; + +export inline constexpr auto foo = 1; diff --git a/tests/projects/c++/modules/moduleonly_private_dep/src/modB.cpp b/tests/projects/c++/modules/moduleonly_private_dep/src/modB.cpp new file mode 100644 index 000000000..6e7a8de49 --- /dev/null +++ b/tests/projects/c++/modules/moduleonly_private_dep/src/modB.cpp @@ -0,0 +1,7 @@ +module B; + +import A; + +int func() { + return foo; +} diff --git a/tests/projects/c++/modules/moduleonly_private_dep/src/modB.mpp b/tests/projects/c++/modules/moduleonly_private_dep/src/modB.mpp new file mode 100644 index 000000000..9fbbcbfbb --- /dev/null +++ b/tests/projects/c++/modules/moduleonly_private_dep/src/modB.mpp @@ -0,0 +1,3 @@ +export module B; + +export int func(); diff --git a/tests/projects/c++/modules/moduleonly_private_dep/xmake.lua b/tests/projects/c++/modules/moduleonly_private_dep/xmake.lua new file mode 100644 index 000000000..0150aef8e --- /dev/null +++ b/tests/projects/c++/modules/moduleonly_private_dep/xmake.lua @@ -0,0 +1,17 @@ +set_languages("c++20") + +target("A") + set_kind("moduleonly") + add_files("src/modA.mpp") + +target("B") + add_deps("A") + set_kind("static") + add_files("src/modB.mpp", { public = true }) + add_files("src/modB.cpp") + +target("test") + set_kind("binary") + add_deps("B") + add_files("src/main.cpp") + diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index 6a912bed4..6c36feff6 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -248,6 +248,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local fileconfig = target:fileconfig(opt.cppfile) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external + local private_dep = fileconfig and fileconfig.private_dep local bmifile = mapped_bmi or bmifile if target:is_binary() then if mapped_bmi then @@ -258,7 +259,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, {std = (name == "std" or name == "std.compat")}) end else - if not public and not external then + if (not public and not external) or (external and private_dep) then progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, {std = (name == "std" or name == "std.compat")}) else @@ -317,6 +318,7 @@ function make_module_buildcmds(target, batchcmds, opt) local fileconfig = target:fileconfig(opt.cppfile) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external + local private_dep = fileconfig and fileconfig.private_dep local bmifile = mapped_bmi or bmifile if target:is_binary() then if mapped_bmi then @@ -327,7 +329,7 @@ function make_module_buildcmds(target, batchcmds, opt) _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, {std = (name == "std" or name == "std.compat"), batchcmds = batchcmds}) end else - if not public and not external then + if (not public and not external) or (external and private_dep) then batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, {std = (name == "std" or name == "std.compat"), batchcmds = batchcmds}) else diff --git a/xmake/rules/c++/modules/modules_support/compiler_support.lua b/xmake/rules/c++/modules/modules_support/compiler_support.lua index 9d3d4fadf..d7cf0b262 100644 --- a/xmake/rules/c++/modules/modules_support/compiler_support.lua +++ b/xmake/rules/c++/modules/modules_support/compiler_support.lua @@ -85,7 +85,8 @@ function cull_objectfiles(target, modules, sourcebatch) local fileconfig = target:fileconfig(sourcefile) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external - if not public and not external then + local private_dep = fileconfig and fileconfig.private_dep + if (not public and not external) or (external and private_dep) then table.insert(sourcebatch.objectfiles, objectfile) end else diff --git a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua index ef0e66cc6..d59a4436a 100644 --- a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua @@ -439,6 +439,7 @@ function get_targetdeps_modules(target) local sourcefiles for _, dep in ipairs(target:orderdeps()) do local sourcebatch = dep:sourcebatches()["c++.build.modules.builder"] + local private_dep = target:extraconf("deps", dep:name(), "private") or not target:extraconf("deps", dep:name(), "public") if sourcebatch and sourcebatch.sourcefiles then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local fileconfig = dep:fileconfig(sourcefile) @@ -446,7 +447,7 @@ function get_targetdeps_modules(target) if public then sourcefiles = sourcefiles or {} table.insert(sourcefiles, sourcefile) - target:fileconfig_add(sourcefile, {external = true}) + target:fileconfig_add(sourcefile, {external = true, private_dep = private_dep}) end end end diff --git a/xmake/rules/c++/modules/modules_support/gcc/builder.lua b/xmake/rules/c++/modules/modules_support/gcc/builder.lua index f290ed262..0c9b8c1b1 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/builder.lua @@ -214,6 +214,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local fileconfig = target:fileconfig(opt.cppfile) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external + local private_dep = fileconfig and fileconfig.private_dep local bmifile = mapped_bmi or bmifile local flags = {"-x", "c++"} local sourcefile @@ -226,7 +227,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) sourcefile = opt.cppfile end else - if not public and not external then + if (not public and not external) or (external and private_dep) then progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) sourcefile = opt.cppfile else @@ -286,6 +287,7 @@ function make_module_buildcmds(target, batchcmds, opt) local fileconfig = target:fileconfig(opt.cppfile) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external + local private_dep = fileconfig and fileconfig.private_dep local bmifile = mapped_bmi or bmifile local flags = {"-x", "c++"} local sourcefile @@ -298,7 +300,7 @@ function make_module_buildcmds(target, batchcmds, opt) sourcefile = opt.cppfile end else - if not public and not external then + if (not public and not external) or (external and private_dep) then batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) sourcefile = opt.cppfile else diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index 5bb9fc4d8..a46dae34a 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -312,6 +312,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local fileconfig = target:fileconfig(opt.cppfile) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external + local private_dep = fileconfig and fileconfig.private_dep local bmifile = mapped_bmi or bmifile if target:is_binary() then if mapped_bmi then @@ -322,7 +323,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, provide) end else - if not public and not external then + if (not public and not external) or (external and private_dep) then progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, provide) else @@ -381,6 +382,7 @@ function make_module_buildcmds(target, batchcmds, opt) local fileconfig = target:fileconfig(opt.cppfile) local public = fileconfig and fileconfig.public local external = fileconfig and fileconfig.external + local private_dep = fileconfig and fileconfig.private_dep local bmifile = mapped_bmi or bmifile if target:is_binary() then if mapped_bmi then @@ -391,7 +393,7 @@ function make_module_buildcmds(target, batchcmds, opt) _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, provide, {batchcmds = batchcmds}) end else - if not public and not external then + if (not public and not external) or (external and private_dep) then batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) _compile_one_step(target, bmifile, opt.cppfile, opt.objectfile, provide {batchcmds = batchcmds}) else |
