From 3fc650750d19020568c17aa2d5540e48faf92d63 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Aug 2024 18:07:24 +0200 Subject: [PATCH 01/21] fix clang module scanning when buildflags are updated --- .../modules/modules_support/clang/dependency_scanner.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua index 4bc15dbde9d..03c86eaa342 100644 --- a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua @@ -31,6 +31,7 @@ function generate_dependency_for(target, sourcefile, opt) local compinst = target:compiler("cxx") local changed = false local dependfile = target:dependfile(sourcefile) + local compflags = compinst:compflags({sourcefile = file, target = target}) depend.on_changed(function() if opt.progress then progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile) @@ -47,7 +48,6 @@ function generate_dependency_for(target, sourcefile, opt) clang_path = compiler_support.get_clang_path(target) or compinst:program() end local clangscandeps = compiler_support.get_clang_scan_deps(target) - local compflags = compinst:compflags({sourcefile = sourcefile, target = target}) local flags = table.join({"--format=p1689", "--", clang_path, "-x", "c++", "-c", sourcefile, "-o", target:objectfile(sourcefile)}, compflags or {}) if option.get("verbose") then @@ -63,7 +63,6 @@ function generate_dependency_for(target, sourcefile, opt) end fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) local keepsystemincludesflag = compiler_support.get_keepsystemincludesflag(target) - local compflags = compinst:compflags({sourcefile = file, target = target}) -- exclude -fmodule* and -std=c++/gnu++* flags because -- when they are set clang try to find bmi of imported modules but they don't exists in this point of compilation table.remove_if(compflags, function(_, flag) @@ -81,8 +80,7 @@ function generate_dependency_for(target, sourcefile, opt) local rawdependinfo = io.readfile(jsonfile) return {moduleinfo = rawdependinfo} - end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt()}) - + end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt(), values = compflags}) return changed end From ad7371e54e67376b4b4c11ae16a0020f0d0f6a1c Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Aug 2024 18:10:10 +0200 Subject: [PATCH 02/21] cleanup unused variables --- xmake/rules/c++/modules/modules_support/clang/builder.lua | 4 ++-- .../rules/c++/modules/modules_support/dependency_scanner.lua | 2 +- xmake/rules/c++/modules/modules_support/msvc/builder.lua | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index 91534a11e3a..8981911bd67 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -125,7 +125,7 @@ function _get_requiresflags(target, module, opt) local requiresflags = compiler_support.memcache():get2(cachekey, "requiresflags") or compiler_support.localcache():get2(cachekey, "requiresflags") - if not requiresflags or (opt and opt.regenerate) then + if not requiresflags then requiresflags = {} for required, _ in table.orderpairs(module.requires) do local dep_module = get_from_target_mapper(target, required) @@ -154,7 +154,7 @@ end function _append_requires_flags(target, module, name, cppfile, bmifile, opt) local cxxflags = {} - local requiresflags = _get_requiresflags(target, {name = (name or cppfile), bmi = bmifile, requires = module.requires}, {regenerate = opt.build}) + local requiresflags = _get_requiresflags(target, {name = (name or cppfile), bmi = bmifile, requires = module.requires}) for _, flag in ipairs(requiresflags) do -- we need to wrap flag to support flag with space if type(flag) == "string" and flag:find(" ", 1, true) then diff --git a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua index c8da6793a0e..3287628ef40 100644 --- a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua @@ -237,7 +237,7 @@ end function get_module_dependencies(target, sourcebatch, opt) local cachekey = target:name() .. "/" .. sourcebatch.rulename local modules = compiler_support.memcache():get2("modules", cachekey) - if modules == nil or opt.regenerate then + if modules == nil then modules = compiler_support.localcache():get2("modules", cachekey) opt.progress = opt.progress or 0 local changed = _generate_dependencies(target, sourcebatch, opt) diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index 89d9b6b606b..2d17d2a3948 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -171,7 +171,7 @@ function _get_requiresflags(target, module, opt) local requiresflags = compiler_support.memcache():get2(cachekey, "requiresflags") or compiler_support.localcache():get2(cachekey, "requiresflags") - if not requiresflags or (opt and opt.regenerate) then + if not requiresflags then local deps_flags = {} for required, _ in table.orderpairs(module.requires) do local dep_module = get_from_target_mapper(target, required) @@ -219,7 +219,7 @@ end function _append_requires_flags(target, module, name, cppfile, bmifile, opt) local cxxflags = {} - local requiresflags = _get_requiresflags(target, {name = (name or cppfile), bmi = bmifile, requires = module.requires}, {regenerate = opt.build}) + local requiresflags = _get_requiresflags(target, {name = (name or cppfile), bmi = bmifile, requires = module.requires}) for _, flag in ipairs(requiresflags) do -- we need to wrap flag to support flag with space if type(flag) == "string" and flag:find(" ", 1, true) then From 17df4ff02b20cb21498ba7274f3d33aa0918368e Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Aug 2024 18:23:09 +0200 Subject: [PATCH 03/21] fix clang module scanning when buildflags are updated --- .../modules/modules_support/clang/dependency_scanner.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua index 03c86eaa342..8d64e3a70e0 100644 --- a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua @@ -31,7 +31,7 @@ function generate_dependency_for(target, sourcefile, opt) local compinst = target:compiler("cxx") local changed = false local dependfile = target:dependfile(sourcefile) - local compflags = compinst:compflags({sourcefile = file, target = target}) + local flags = compinst:compflags({sourcefile = file, target = target}) or {} depend.on_changed(function() if opt.progress then progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile) @@ -49,7 +49,7 @@ function generate_dependency_for(target, sourcefile, opt) end local clangscandeps = compiler_support.get_clang_scan_deps(target) local flags = table.join({"--format=p1689", "--", - clang_path, "-x", "c++", "-c", sourcefile, "-o", target:objectfile(sourcefile)}, compflags or {}) + clang_path, "-x", "c++", "-c", sourcefile, "-o", target:objectfile(sourcefile)}, flags or {}) if option.get("verbose") then print(os.args(table.join(clangscandeps, flags))) end @@ -63,6 +63,7 @@ function generate_dependency_for(target, sourcefile, opt) end fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) local keepsystemincludesflag = compiler_support.get_keepsystemincludesflag(target) + local compflags = flags -- exclude -fmodule* and -std=c++/gnu++* flags because -- when they are set clang try to find bmi of imported modules but they don't exists in this point of compilation table.remove_if(compflags, function(_, flag) @@ -80,7 +81,7 @@ function generate_dependency_for(target, sourcefile, opt) local rawdependinfo = io.readfile(jsonfile) return {moduleinfo = rawdependinfo} - end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt(), values = compflags}) + end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt(), values = flags}) return changed end From 758fcd4b98944108663cbf80e6417966c30caa6d Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Aug 2024 18:23:20 +0200 Subject: [PATCH 04/21] fix msvc module scanning when buildflags are updated --- .../modules_support/msvc/dependency_scanner.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua index 90906fb0e7e..489ca1d9793 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua @@ -35,6 +35,7 @@ function generate_dependency_for(target, sourcefile, opt) local ifcoutputflag = compiler_support.get_ifcoutputflag(target) local common_flags = {"-TP", scandependenciesflag} local dependfile = target:dependfile(sourcefile) + local flags = compinst:compflags({sourcefile = file, target = target}) or {} local changed = false depend.on_changed(function () @@ -43,16 +44,15 @@ function generate_dependency_for(target, sourcefile, opt) local jsonfile = path.join(outputdir, path.filename(sourcefile) .. ".module.json") if scandependenciesflag and not target:policy("build.c++.msvc.fallbackscanner") then - local flags = {jsonfile, sourcefile, ifcoutputflag, outputdir, "-Fo" .. target:objectfile(sourcefile)} + local dependency_flags = {jsonfile, sourcefile, ifcoutputflag, outputdir, "-Fo" .. target:objectfile(sourcefile)} local compinst = target:compiler("cxx") - local compflags = table.join(compinst:compflags({sourcefile = sourcefile, target = target}) or {}, common_flags, flags) + local compflags = table.join(flags, common_flags, dependency_flags) os.vrunv(compinst:program(), winos.cmdargv(compflags), {envs = msvc:runenvs()}) else fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) local compinst = target:compiler("cxx") - local compflags = compinst:compflags({sourcefile = file, target = target}) local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) - os.vrunv(compinst:program(), table.join(compflags, + os.vrunv(compinst:program(), table.join(flags, {"/P", "-TP", file, "/Fi" .. ifile}), {envs = msvc:runenvs()}) local content = io.readfile(ifile) os.rm(ifile) @@ -63,7 +63,7 @@ function generate_dependency_for(target, sourcefile, opt) local dependinfo = io.readfile(jsonfile) return { moduleinfo = dependinfo } - end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt()}) + end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt(), values = flags}) return changed end From d3a75d4be2aa50a1dfdf5b7708c08409b5e28fcb Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Aug 2024 18:23:32 +0200 Subject: [PATCH 05/21] fix gcc module scanning when buildflags are updated --- .../modules/modules_support/gcc/dependency_scanner.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua index 38d7c6069a5..237e2262760 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua @@ -35,6 +35,7 @@ function generate_dependency_for(target, sourcefile, opt) local depsfileflag = compiler_support.get_depsfileflag(target) local depstargetflag = compiler_support.get_depstargetflag(target) local dependfile = target:dependfile(sourcefile) + local flags = compinst:compflags({sourcefile = file, target = target}) or {} local changed = false depend.on_changed(function() @@ -48,8 +49,7 @@ function generate_dependency_for(target, sourcefile, opt) if has_depsflags and not target:policy("build.c++.gcc.fallbackscanner") then local ifile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".i")) local dfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".d")) - local compflags = compinst:compflags({sourcefile = sourcefile, target = target}) - local flags = table.join(compflags or {}, baselineflags, {sourcefile, "-MT", jsonfile, "-MD", "-MF", dfile, depsformatflag, depsfileflag .. jsonfile, depstargetflag .. target:objectfile(sourcefile), "-o", ifile}) + local flags = table.join(flags or {}, baselineflags, {sourcefile, "-MT", jsonfile, "-MD", "-MF", dfile, depsformatflag, depsfileflag .. jsonfile, depstargetflag .. target:objectfile(sourcefile), "-o", ifile}) os.vrunv(compinst:program(), flags) os.rm(ifile) os.rm(dfile) @@ -58,7 +58,7 @@ function generate_dependency_for(target, sourcefile, opt) wprint("GCC doesn't support module scanning ! using fallback scanner") end fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) - local compflags = compinst:compflags({sourcefile = file, target = target}) + local compflags = flags -- exclude -fmodule* flags because, when they are set gcc try to find bmi of imported modules but they don't exists a this point of compilation table.remove_if(compflags, function(_, flag) return flag:startswith("-fmodule") end) local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) @@ -73,7 +73,7 @@ function generate_dependency_for(target, sourcefile, opt) local dependinfo = io.readfile(jsonfile) return { moduleinfo = dependinfo } - end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt()}) + end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt(), values = flags}) return changed end From d7d57888d888d32d5367d1c076fdb5210fdda4b2 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Aug 2024 18:35:14 +0200 Subject: [PATCH 06/21] add test for dependency scanner regeneration --- .../dependency_flag_update/src/bar.mpp | 9 +++ .../dependency_flag_update/src/foo.mpp | 9 +++ .../dependency_flag_update/src/main.cpp | 12 +++ .../modules/dependency_flag_update/test.lua | 1 + .../modules/dependency_flag_update/xmake.lua | 11 +++ .../dependency_flag_update2/src/bar.mpp | 9 +++ .../dependency_flag_update2/src/foo.mpp | 9 +++ .../dependency_flag_update2/src/foobar.mpp | 11 +++ .../dependency_flag_update2/src/main.cpp | 6 ++ .../modules/dependency_flag_update2/test.lua | 1 + .../modules/dependency_flag_update2/xmake.lua | 12 +++ .../c++/modules/test_dependency_scanner.lua | 76 +++++++++++++++++++ 12 files changed, 166 insertions(+) create mode 100644 tests/projects/c++/modules/dependency_flag_update/src/bar.mpp create mode 100644 tests/projects/c++/modules/dependency_flag_update/src/foo.mpp create mode 100644 tests/projects/c++/modules/dependency_flag_update/src/main.cpp create mode 100644 tests/projects/c++/modules/dependency_flag_update/test.lua create mode 100644 tests/projects/c++/modules/dependency_flag_update/xmake.lua create mode 100644 tests/projects/c++/modules/dependency_flag_update2/src/bar.mpp create mode 100644 tests/projects/c++/modules/dependency_flag_update2/src/foo.mpp create mode 100644 tests/projects/c++/modules/dependency_flag_update2/src/foobar.mpp create mode 100644 tests/projects/c++/modules/dependency_flag_update2/src/main.cpp create mode 100644 tests/projects/c++/modules/dependency_flag_update2/test.lua create mode 100644 tests/projects/c++/modules/dependency_flag_update2/xmake.lua create mode 100644 tests/projects/c++/modules/test_dependency_scanner.lua diff --git a/tests/projects/c++/modules/dependency_flag_update/src/bar.mpp b/tests/projects/c++/modules/dependency_flag_update/src/bar.mpp new file mode 100644 index 00000000000..812572d6901 --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update/src/bar.mpp @@ -0,0 +1,9 @@ +module; + +#include + +export module bar; + +namespace bar { +export void hello() { std::cout << "Hello world2" << std::endl; } +} // namespace bar diff --git a/tests/projects/c++/modules/dependency_flag_update/src/foo.mpp b/tests/projects/c++/modules/dependency_flag_update/src/foo.mpp new file mode 100644 index 00000000000..904d3805e6a --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update/src/foo.mpp @@ -0,0 +1,9 @@ +module; + +#include + +export module foo; + +namespace foo { +export void hello() { std::cout << "Hello world" << std::endl; } +} // namespace foo diff --git a/tests/projects/c++/modules/dependency_flag_update/src/main.cpp b/tests/projects/c++/modules/dependency_flag_update/src/main.cpp new file mode 100644 index 00000000000..80953606520 --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update/src/main.cpp @@ -0,0 +1,12 @@ +#if defined(FOO) +import foo; +using namespace foo; +#else +import bar; +using namespace bar; +#endif + +int main() { + hello(); + return 0; +} diff --git a/tests/projects/c++/modules/dependency_flag_update/test.lua b/tests/projects/c++/modules/dependency_flag_update/test.lua new file mode 100644 index 00000000000..16312f26a67 --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update/test.lua @@ -0,0 +1 @@ +inherit(".test_dependency_scanner") diff --git a/tests/projects/c++/modules/dependency_flag_update/xmake.lua b/tests/projects/c++/modules/dependency_flag_update/xmake.lua new file mode 100644 index 00000000000..d2e88976593 --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update/xmake.lua @@ -0,0 +1,11 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") + +option("foo") + set_default("true") + add_defines("FOO") + +target("dependency_flag_update") + set_kind("binary") + add_files("src/*.cpp", "src/*.mpp") + add_options("foo") diff --git a/tests/projects/c++/modules/dependency_flag_update2/src/bar.mpp b/tests/projects/c++/modules/dependency_flag_update2/src/bar.mpp new file mode 100644 index 00000000000..812572d6901 --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update2/src/bar.mpp @@ -0,0 +1,9 @@ +module; + +#include + +export module bar; + +namespace bar { +export void hello() { std::cout << "Hello world2" << std::endl; } +} // namespace bar diff --git a/tests/projects/c++/modules/dependency_flag_update2/src/foo.mpp b/tests/projects/c++/modules/dependency_flag_update2/src/foo.mpp new file mode 100644 index 00000000000..904d3805e6a --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update2/src/foo.mpp @@ -0,0 +1,9 @@ +module; + +#include + +export module foo; + +namespace foo { +export void hello() { std::cout << "Hello world" << std::endl; } +} // namespace foo diff --git a/tests/projects/c++/modules/dependency_flag_update2/src/foobar.mpp b/tests/projects/c++/modules/dependency_flag_update2/src/foobar.mpp new file mode 100644 index 00000000000..1a5fd39caf4 --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update2/src/foobar.mpp @@ -0,0 +1,11 @@ +export module foobar; + +#if defined(FOO) +import foo; +namespace impl = foo; +#else +import bar; +namespace impl = bar; +#endif + +export void hello() { impl::hello(); } diff --git a/tests/projects/c++/modules/dependency_flag_update2/src/main.cpp b/tests/projects/c++/modules/dependency_flag_update2/src/main.cpp new file mode 100644 index 00000000000..d34cba0805c --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update2/src/main.cpp @@ -0,0 +1,6 @@ +import foobar; + +int main() { + hello(); + return 0; +} diff --git a/tests/projects/c++/modules/dependency_flag_update2/test.lua b/tests/projects/c++/modules/dependency_flag_update2/test.lua new file mode 100644 index 00000000000..16312f26a67 --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update2/test.lua @@ -0,0 +1 @@ +inherit(".test_dependency_scanner") diff --git a/tests/projects/c++/modules/dependency_flag_update2/xmake.lua b/tests/projects/c++/modules/dependency_flag_update2/xmake.lua new file mode 100644 index 00000000000..819ef7263c4 --- /dev/null +++ b/tests/projects/c++/modules/dependency_flag_update2/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") + +option("foo") + set_default("true") + add_defines("FOO") + +target("dependency_flag_update3") + set_kind("binary") + add_files("src/*.cpp", "src/*.mpp") + add_options("foo") + diff --git a/tests/projects/c++/modules/test_dependency_scanner.lua b/tests/projects/c++/modules/test_dependency_scanner.lua new file mode 100644 index 00000000000..c37cc0beb5c --- /dev/null +++ b/tests/projects/c++/modules/test_dependency_scanner.lua @@ -0,0 +1,76 @@ +import("lib.detect.find_tool") +import("core.base.semver") +import("utils.ci.is_running", {alias = "ci_is_running"}) + +function _build() + os.run("xmake f --foo=n") + local outdata + if ci_is_running() then + outdata = os.iorun("xmake -rvD") + else + outdata = os.iorun("xmake -rv") + end + if outdata then + if outdata:find("FOO") then + raise("Modules dependency scanner update does not work\n%s", outdata) + end + end + outdata = os.iorun("xmake") + if outdata then + if outdata:find("compiling") or outdata:find("linking") or outdata:find("generating") then + raise("Modules incremental compilation does not work\n%s", outdata) + end + end +end + +function can_build() + if is_subhost("windows") then + return true + elseif is_subhost("msys") then + return true + elseif is_host("linux") then + local gcc = find_tool("gcc", {version = true}) + if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then + return true + end + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then + return true + end + end +end + +function main(t) + if is_subhost("windows") then + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "17.0") >= 0 then + os.exec("xmake f --toolchain=clang -c --yes") + _build() + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang --runtimes=c++_shared -c --yes") + _build() + end + + os.exec("xmake clean -a") + os.exec("xmake f -c --yes") + _build() + elseif is_subhost("msys") then + os.exec("xmake f -c -p mingw --yes") + _build() + elseif is_host("linux") then + local gcc = find_tool("gcc", {version = true}) + if gcc and gcc.version and semver.compare(gcc.version, "11.0") >= 0 then + os.exec("xmake f -c --yes") + _build() + end + local clang = find_tool("clang", {version = true}) + if clang and clang.version and semver.compare(clang.version, "14.0") >= 0 then + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang -c --yes") + _build() + os.exec("xmake clean -a") + os.exec("xmake f --toolchain=clang --runtimes=c++_shared -c --yes") + _build() + end + end +end From aad386b8e891bc8b0aa6d6db03c1f6bbaf97a15b Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Aug 2024 18:58:38 +0200 Subject: [PATCH 07/21] improve dependency scanner for clang --- .../modules_support/clang/dependency_scanner.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua index 8d64e3a70e0..e6f3763656e 100644 --- a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua @@ -48,12 +48,16 @@ function generate_dependency_for(target, sourcefile, opt) clang_path = compiler_support.get_clang_path(target) or compinst:program() end local clangscandeps = compiler_support.get_clang_scan_deps(target) - local flags = table.join({"--format=p1689", "--", - clang_path, "-x", "c++", "-c", sourcefile, "-o", target:objectfile(sourcefile)}, flags or {}) + local dependency_flags = table.join({"--format=p1689", "--", + clang_path, "-x", "c++", "-c", sourcefile, "-o", target:objectfile(sourcefile)}, flags) + if sourcefile:match("frozen") then + print(os.args(table.join(clangscandeps, dependency_flags))) + assert(false) + end if option.get("verbose") then - print(os.args(table.join(clangscandeps, flags))) + print(os.args(table.join(clangscandeps, dependency_flags))) end - local outdata, errdata = os.iorunv(clangscandeps, flags) + local outdata, errdata = os.iorunv(clangscandeps, dependency_flags) assert(errdata, errdata) io.writefile(jsonfile, outdata) From fb0286bc3d912dc83a92260db1b82dac2990b971 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Aug 2024 18:59:53 +0200 Subject: [PATCH 08/21] fix msvc dependency scanner --- .../c++/modules/modules_support/msvc/dependency_scanner.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua index 489ca1d9793..cd0928f49b6 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua @@ -35,6 +35,7 @@ function generate_dependency_for(target, sourcefile, opt) local ifcoutputflag = compiler_support.get_ifcoutputflag(target) local common_flags = {"-TP", scandependenciesflag} local dependfile = target:dependfile(sourcefile) + local compinst = target:compiler("cxx") local flags = compinst:compflags({sourcefile = file, target = target}) or {} local changed = false @@ -45,12 +46,10 @@ function generate_dependency_for(target, sourcefile, opt) local jsonfile = path.join(outputdir, path.filename(sourcefile) .. ".module.json") if scandependenciesflag and not target:policy("build.c++.msvc.fallbackscanner") then local dependency_flags = {jsonfile, sourcefile, ifcoutputflag, outputdir, "-Fo" .. target:objectfile(sourcefile)} - local compinst = target:compiler("cxx") local compflags = table.join(flags, common_flags, dependency_flags) os.vrunv(compinst:program(), winos.cmdargv(compflags), {envs = msvc:runenvs()}) else fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) - local compinst = target:compiler("cxx") local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) os.vrunv(compinst:program(), table.join(flags, {"/P", "-TP", file, "/Fi" .. ifile}), {envs = msvc:runenvs()}) From 593ef027feec3417cabd2825db673ee8ce656402 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Aug 2024 19:59:11 +0200 Subject: [PATCH 09/21] fix missing defines in compflags for dependency scanners --- .../modules_support/clang/dependency_scanner.lua | 11 ++++++++++- .../modules_support/gcc/dependency_scanner.lua | 6 ++++++ .../modules_support/msvc/dependency_scanner.lua | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua index e6f3763656e..cc189b07b1e 100644 --- a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua @@ -32,6 +32,14 @@ function generate_dependency_for(target, sourcefile, opt) local changed = false local dependfile = target:dependfile(sourcefile) local flags = compinst:compflags({sourcefile = file, target = target}) or {} + local fileconfig = target:fileconfig(sourcefile) + -- fileconfig.defines are not in compflags here so we manually add it + if fileconfig and fileconfig.defines then + for _, define in ipairs(fileconfig.defines) do + table.insert(flags, "-D" .. define) + end + end + depend.on_changed(function() if opt.progress then progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile) @@ -51,8 +59,9 @@ function generate_dependency_for(target, sourcefile, opt) local dependency_flags = table.join({"--format=p1689", "--", clang_path, "-x", "c++", "-c", sourcefile, "-o", target:objectfile(sourcefile)}, flags) if sourcefile:match("frozen") then + print(target:fileconfig(sourcefile)) print(os.args(table.join(clangscandeps, dependency_flags))) - assert(false) + -- assert(false) end if option.get("verbose") then print(os.args(table.join(clangscandeps, dependency_flags))) diff --git a/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua index 237e2262760..2132f4edf9d 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua @@ -37,6 +37,12 @@ function generate_dependency_for(target, sourcefile, opt) local dependfile = target:dependfile(sourcefile) local flags = compinst:compflags({sourcefile = file, target = target}) or {} local changed = false + -- fileconfig.defines are not in compflags here so we manually add it + if fileconfig and fileconfig.defines then + for _, define in ipairs(fileconfig.defines) do + table.insert(flags, "-D" .. define) + end + end depend.on_changed(function() if opt.progress then diff --git a/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua index cd0928f49b6..ad5b7aaf969 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua @@ -38,6 +38,12 @@ function generate_dependency_for(target, sourcefile, opt) local compinst = target:compiler("cxx") local flags = compinst:compflags({sourcefile = file, target = target}) or {} local changed = false + -- fileconfig.defines are not in compflags here so we manually add it + if fileconfig and fileconfig.defines then + for _, define in ipairs(fileconfig.defines) do + table.insert(flags, "-D" .. define) + end + end depend.on_changed(function () progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile) From dc73c38303b736a8dec9ac4df0ed0a3a7f55d318 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 4 Oct 2024 17:52:17 +0200 Subject: [PATCH 10/21] fix module dependency flags update --- .../c++/modules/modules_support/builder.lua | 30 +++++++++++++++++++ .../modules/modules_support/clang/builder.lua | 13 +++++--- .../modules/modules_support/msvc/builder.lua | 5 +++- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/builder.lua b/xmake/rules/c++/modules/modules_support/builder.lua index f651e2b698f..51e87a8a888 100644 --- a/xmake/rules/c++/modules/modules_support/builder.lua +++ b/xmake/rules/c++/modules/modules_support/builder.lua @@ -21,6 +21,7 @@ -- imports import("core.base.json") import("core.base.option") +import("core.base.hashset") import("async.runjobs") import("private.async.buildjobs") import("core.tool.compiler") @@ -460,3 +461,32 @@ function add_headerunit_to_target_mapper(target, headerunit, bmifile) return deduplicated and true or false end +-- check if dependencies changed +function is_dependencies_changed(target, module) + local cachekey = target:name() .. module.name + + for required, _ in table.orderpairs(module.requires) do + requires = requires or hashset.new() + requires:insert(required) + end + + local oldrequires = compiler_support.memcache():get2(cachekey, "oldrequires") + or compiler_support.localcache():get2(cachekey, "oldrequires") + + local changed = false + if oldrequires and requires then + oldrequires = hashset.from(oldrequires) + if oldrequires:size() ~= requires:size() then + requires_changed = true + else + for required in requires:keys() do + if not oldrequires:has(required) then + requires_changed = true + break + end + end + end + end + + return requires:to_array(), changed +end diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index 8981911bd67..adbee51f0c7 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -122,10 +122,11 @@ function _get_requiresflags(target, module, opt) local name = module.name local cachekey = target:name() .. name + local requires, requires_changed = is_dependencies_changed(target, module) local requiresflags = compiler_support.memcache():get2(cachekey, "requiresflags") - or compiler_support.localcache():get2(cachekey, "requiresflags") + or compiler_support.localcache():get2(cachekey, "requiresflags") - if not requiresflags then + if not requiresflags or requires_changed then requiresflags = {} for required, _ in table.orderpairs(module.requires) do local dep_module = get_from_target_mapper(target, required) @@ -146,8 +147,11 @@ function _get_requiresflags(target, module, opt) table.join2(requiresflags, deps) end end - compiler_support.memcache():set2(cachekey, "requiresflags", table.unique(requiresflags)) - compiler_support.localcache():set2(cachekey, "requiresflags", table.unique(requiresflags)) + requiresflags = table.unique(requiresflags) + compiler_support.memcache():set2(cachekey, "requiresflags", requiresflags) + compiler_support.memcache():set2(cachekey, "oldrequires", requires) + compiler_support.localcache():set2(cachekey, "requiresflags", requiresflags) + compiler_support.localcache():set2(cachekey, "oldrequires", requires) end return requiresflags end @@ -231,6 +235,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) build, dependinfo = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) end + -- if build then if build then -- compile if it's a named module if provide or compiler_support.has_module_extension(opt.cppfile) then diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index 2d17d2a3948..5024a3f6072 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -169,9 +169,10 @@ function _get_requiresflags(target, module, opt) local name = module.name local cachekey = target:name() .. name + local requires, requires_changed = is_dependencies_changed(target, module) local requiresflags = compiler_support.memcache():get2(cachekey, "requiresflags") or compiler_support.localcache():get2(cachekey, "requiresflags") - if not requiresflags then + if not requiresflags or requires_changed then local deps_flags = {} for required, _ in table.orderpairs(module.requires) do local dep_module = get_from_target_mapper(target, required) @@ -212,7 +213,9 @@ function _get_requiresflags(target, module, opt) end end compiler_support.memcache():set2(cachekey, "requiresflags", requiresflags) + compiler_support.memcache():set2(cachekey, "oldrequires", requires) compiler_support.localcache():set2(cachekey, "requiresflags", requiresflags) + compiler_support.localcache():set2(cachekey, "oldrequires", requires) end return requiresflags end From b63a48f1647126589547c9b9e5ea15e821b9094c Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 4 Oct 2024 18:05:23 +0200 Subject: [PATCH 11/21] cleanup --- .../c++/modules/modules_support/clang/dependency_scanner.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua index cc189b07b1e..5a89d54bb86 100644 --- a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua @@ -58,11 +58,6 @@ function generate_dependency_for(target, sourcefile, opt) local clangscandeps = compiler_support.get_clang_scan_deps(target) local dependency_flags = table.join({"--format=p1689", "--", clang_path, "-x", "c++", "-c", sourcefile, "-o", target:objectfile(sourcefile)}, flags) - if sourcefile:match("frozen") then - print(target:fileconfig(sourcefile)) - print(os.args(table.join(clangscandeps, dependency_flags))) - -- assert(false) - end if option.get("verbose") then print(os.args(table.join(clangscandeps, dependency_flags))) end From 19cc438bceb4ca3bde0fb8dd2820194a28975457 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 4 Oct 2024 18:29:13 +0200 Subject: [PATCH 12/21] fix dependency scanner for gcc and clang --- .../c++/modules/modules_support/clang/dependency_scanner.lua | 2 +- .../c++/modules/modules_support/gcc/dependency_scanner.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua index 5a89d54bb86..5b6d50b1c9c 100644 --- a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua @@ -71,7 +71,7 @@ function generate_dependency_for(target, sourcefile, opt) end fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) local keepsystemincludesflag = compiler_support.get_keepsystemincludesflag(target) - local compflags = flags + local compflags = table.clone(flags) -- exclude -fmodule* and -std=c++/gnu++* flags because -- when they are set clang try to find bmi of imported modules but they don't exists in this point of compilation table.remove_if(compflags, function(_, flag) diff --git a/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua index 2132f4edf9d..a2f4f8c7bfb 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua @@ -64,7 +64,7 @@ function generate_dependency_for(target, sourcefile, opt) wprint("GCC doesn't support module scanning ! using fallback scanner") end fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) - local compflags = flags + local compflags = table.clone(flags) -- exclude -fmodule* flags because, when they are set gcc try to find bmi of imported modules but they don't exists a this point of compilation table.remove_if(compflags, function(_, flag) return flag:startswith("-fmodule") end) local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) From 6cf96ccaf32860e128a5447c48a1f1dcd6b216de Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 5 Oct 2024 18:48:41 +0200 Subject: [PATCH 13/21] add missing local variable declaration for moduler build --- xmake/rules/c++/modules/modules_support/builder.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/rules/c++/modules/modules_support/builder.lua b/xmake/rules/c++/modules/modules_support/builder.lua index 51e87a8a888..9133bad604f 100644 --- a/xmake/rules/c++/modules/modules_support/builder.lua +++ b/xmake/rules/c++/modules/modules_support/builder.lua @@ -465,13 +465,13 @@ end function is_dependencies_changed(target, module) local cachekey = target:name() .. module.name + local requires for required, _ in table.orderpairs(module.requires) do requires = requires or hashset.new() requires:insert(required) end local oldrequires = compiler_support.memcache():get2(cachekey, "oldrequires") - or compiler_support.localcache():get2(cachekey, "oldrequires") local changed = false if oldrequires and requires then From 6c57450734d93d16f370ddccf3d41240bc8f64f5 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 5 Oct 2024 18:50:26 +0200 Subject: [PATCH 14/21] don't persist requiresflags into a file --- xmake/rules/c++/modules/modules_support/clang/builder.lua | 2 -- xmake/rules/c++/modules/modules_support/msvc/builder.lua | 1 - 2 files changed, 3 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index adbee51f0c7..fc0798ee7fb 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -124,8 +124,6 @@ function _get_requiresflags(target, module, opt) local requires, requires_changed = is_dependencies_changed(target, module) local requiresflags = compiler_support.memcache():get2(cachekey, "requiresflags") - or compiler_support.localcache():get2(cachekey, "requiresflags") - if not requiresflags or requires_changed then requiresflags = {} for required, _ in table.orderpairs(module.requires) do diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index 5024a3f6072..7106503806f 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -171,7 +171,6 @@ function _get_requiresflags(target, module, opt) local requires, requires_changed = is_dependencies_changed(target, module) local requiresflags = compiler_support.memcache():get2(cachekey, "requiresflags") - or compiler_support.localcache():get2(cachekey, "requiresflags") if not requiresflags or requires_changed then local deps_flags = {} for required, _ in table.orderpairs(module.requires) do From 929d11a6eb75d9b3586afc264a7cc93ca2931eac Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 5 Oct 2024 18:50:46 +0200 Subject: [PATCH 15/21] cleanup --- xmake/rules/c++/modules/modules_support/clang/builder.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index fc0798ee7fb..1fb79d0cfab 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -233,7 +233,6 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) build, dependinfo = should_build(target, opt.cppfile, bmifile, {name = name, objectfile = opt.objectfile, requires = opt.module.requires}) end - -- if build then if build then -- compile if it's a named module if provide or compiler_support.has_module_extension(opt.cppfile) then From 053fcb3bf84a9c60f5aef453e9b20e8671488099 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 5 Oct 2024 18:55:22 +0200 Subject: [PATCH 16/21] fix flags in dependendy scanners --- .../modules_support/clang/dependency_scanner.lua | 12 +++--------- .../modules_support/gcc/dependency_scanner.lua | 16 +++++----------- .../modules_support/msvc/dependency_scanner.lua | 8 +------- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua index 5b6d50b1c9c..fb375fcb7a4 100644 --- a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua @@ -31,14 +31,8 @@ function generate_dependency_for(target, sourcefile, opt) local compinst = target:compiler("cxx") local changed = false local dependfile = target:dependfile(sourcefile) - local flags = compinst:compflags({sourcefile = file, target = target}) or {} + local flags = compinst:compflags({sourcefile = sourcefile, target = target}) or {} local fileconfig = target:fileconfig(sourcefile) - -- fileconfig.defines are not in compflags here so we manually add it - if fileconfig and fileconfig.defines then - for _, define in ipairs(fileconfig.defines) do - table.insert(flags, "-D" .. define) - end - end depend.on_changed(function() if opt.progress then @@ -78,8 +72,8 @@ function generate_dependency_for(target, sourcefile, opt) return flag:startswith("-fmodule") or flag:startswith("-std=c++") or flag:startswith("-std=gnu++") end) local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) - local flags = table.join(compflags or {}, keepsystemincludesflag or {}, {"-E", "-x", "c++", file, "-o", ifile}) - os.vrunv(compinst:program(), flags) + compflags = table.join(compflags or {}, keepsystemincludesflag or {}, {"-E", "-x", "c++", file, "-o", ifile}) + os.vrunv(compinst:program(), compflags) local content = io.readfile(ifile) os.rm(ifile) return content diff --git a/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua index a2f4f8c7bfb..11dab5669e5 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua @@ -35,14 +35,8 @@ function generate_dependency_for(target, sourcefile, opt) local depsfileflag = compiler_support.get_depsfileflag(target) local depstargetflag = compiler_support.get_depstargetflag(target) local dependfile = target:dependfile(sourcefile) - local flags = compinst:compflags({sourcefile = file, target = target}) or {} + local flags = compinst:compflags({sourcefile = sourcefile, target = target}) or {} local changed = false - -- fileconfig.defines are not in compflags here so we manually add it - if fileconfig and fileconfig.defines then - for _, define in ipairs(fileconfig.defines) do - table.insert(flags, "-D" .. define) - end - end depend.on_changed(function() if opt.progress then @@ -55,8 +49,8 @@ function generate_dependency_for(target, sourcefile, opt) if has_depsflags and not target:policy("build.c++.gcc.fallbackscanner") then local ifile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".i")) local dfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".d")) - local flags = table.join(flags or {}, baselineflags, {sourcefile, "-MT", jsonfile, "-MD", "-MF", dfile, depsformatflag, depsfileflag .. jsonfile, depstargetflag .. target:objectfile(sourcefile), "-o", ifile}) - os.vrunv(compinst:program(), flags) + local compflags = table.join(flags or {}, baselineflags, {sourcefile, "-MT", jsonfile, "-MD", "-MF", dfile, depsformatflag, depsfileflag .. jsonfile, depstargetflag .. target:objectfile(sourcefile), "-o", ifile}) + os.vrunv(compinst:program(), compflags) os.rm(ifile) os.rm(dfile) else @@ -68,8 +62,8 @@ function generate_dependency_for(target, sourcefile, opt) -- exclude -fmodule* flags because, when they are set gcc try to find bmi of imported modules but they don't exists a this point of compilation table.remove_if(compflags, function(_, flag) return flag:startswith("-fmodule") end) local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) - local flags = table.join(baselineflags, compflags or {}, {file, "-o", ifile}) - os.vrunv(compinst:program(), flags) + compflags = table.join(baselineflags, compflags or {}, {file, "-o", ifile}) + os.vrunv(compinst:program(), compflags) local content = io.readfile(ifile) os.rm(ifile) return content diff --git a/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua index ad5b7aaf969..491a27cbf86 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua @@ -36,14 +36,8 @@ function generate_dependency_for(target, sourcefile, opt) local common_flags = {"-TP", scandependenciesflag} local dependfile = target:dependfile(sourcefile) local compinst = target:compiler("cxx") - local flags = compinst:compflags({sourcefile = file, target = target}) or {} + local flags = compinst:compflags({sourcefile = sourcefile, target = target}) or {} local changed = false - -- fileconfig.defines are not in compflags here so we manually add it - if fileconfig and fileconfig.defines then - for _, define in ipairs(fileconfig.defines) do - table.insert(flags, "-D" .. define) - end - end depend.on_changed(function () progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile) From fb842c9e4208fcba3052239088a9299759761d9e Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Mon, 7 Oct 2024 16:26:53 +0200 Subject: [PATCH 17/21] cleanup --- xmake/rules/c++/modules/modules_support/clang/builder.lua | 2 -- xmake/rules/c++/modules/modules_support/msvc/builder.lua | 2 -- 2 files changed, 4 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index 1fb79d0cfab..2ad97a94363 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -148,8 +148,6 @@ function _get_requiresflags(target, module, opt) requiresflags = table.unique(requiresflags) compiler_support.memcache():set2(cachekey, "requiresflags", requiresflags) compiler_support.memcache():set2(cachekey, "oldrequires", requires) - compiler_support.localcache():set2(cachekey, "requiresflags", requiresflags) - compiler_support.localcache():set2(cachekey, "oldrequires", requires) end return requiresflags end diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index 7106503806f..de4f97bd415 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -213,8 +213,6 @@ function _get_requiresflags(target, module, opt) end compiler_support.memcache():set2(cachekey, "requiresflags", requiresflags) compiler_support.memcache():set2(cachekey, "oldrequires", requires) - compiler_support.localcache():set2(cachekey, "requiresflags", requiresflags) - compiler_support.localcache():set2(cachekey, "oldrequires", requires) end return requiresflags end From d8b4280e5b43bbeeed8c4ddf67ad1dd08fbc70a5 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Mon, 7 Oct 2024 16:37:37 +0200 Subject: [PATCH 18/21] don't convert hashset to table and some cleanup for module builders --- xmake/rules/c++/modules/modules_support/builder.lua | 13 +++++-------- .../c++/modules/modules_support/clang/builder.lua | 2 +- .../c++/modules/modules_support/msvc/builder.lua | 3 +-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/builder.lua b/xmake/rules/c++/modules/modules_support/builder.lua index 9133bad604f..7e51ad6f89d 100644 --- a/xmake/rules/c++/modules/modules_support/builder.lua +++ b/xmake/rules/c++/modules/modules_support/builder.lua @@ -465,21 +465,18 @@ end function is_dependencies_changed(target, module) local cachekey = target:name() .. module.name - local requires + local requires = hashset.new() for required, _ in table.orderpairs(module.requires) do - requires = requires or hashset.new() requires:insert(required) end local oldrequires = compiler_support.memcache():get2(cachekey, "oldrequires") - local changed = false - if oldrequires and requires then - oldrequires = hashset.from(oldrequires) - if oldrequires:size() ~= requires:size() then + if oldrequires then + if oldrequires ~= requires:size() then requires_changed = true else - for required in requires:keys() do + for _, required in requires:keys() do if not oldrequires:has(required) then requires_changed = true break @@ -488,5 +485,5 @@ function is_dependencies_changed(target, module) end end - return requires:to_array(), changed + return requires, changed end diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index 2ad97a94363..ad30aa158d3 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -126,7 +126,7 @@ function _get_requiresflags(target, module, opt) local requiresflags = compiler_support.memcache():get2(cachekey, "requiresflags") if not requiresflags or requires_changed then requiresflags = {} - for required, _ in table.orderpairs(module.requires) do + for required, _ in requires:orderkeys() do local dep_module = get_from_target_mapper(target, required) assert(dep_module, "module dependency %s required for %s not found", required, name) diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index de4f97bd415..bb7090cb49f 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -173,9 +173,8 @@ function _get_requiresflags(target, module, opt) local requiresflags = compiler_support.memcache():get2(cachekey, "requiresflags") if not requiresflags or requires_changed then local deps_flags = {} - for required, _ in table.orderpairs(module.requires) do + for required, _ in requires:orderkeys() do local dep_module = get_from_target_mapper(target, required) - assert(dep_module, "module dependency %s required for %s not found <%s>", required, name, target:name()) local mapflag From 665fafc8ae0f3fdd6c2205b2fd0b90a9627409b6 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 8 Oct 2024 11:27:31 +0800 Subject: [PATCH 19/21] Update builder.lua --- xmake/rules/c++/modules/modules_support/builder.lua | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/builder.lua b/xmake/rules/c++/modules/modules_support/builder.lua index 7e51ad6f89d..60e1112d8eb 100644 --- a/xmake/rules/c++/modules/modules_support/builder.lua +++ b/xmake/rules/c++/modules/modules_support/builder.lua @@ -464,19 +464,14 @@ end -- check if dependencies changed function is_dependencies_changed(target, module) local cachekey = target:name() .. module.name - - local requires = hashset.new() - for required, _ in table.orderpairs(module.requires) do - requires:insert(required) - end - + local requires = hashset.from(table.keys(module.requires or {})) local oldrequires = compiler_support.memcache():get2(cachekey, "oldrequires") local changed = false if oldrequires then - if oldrequires ~= requires:size() then + if oldrequires ~= requires then requires_changed = true else - for _, required in requires:keys() do + for required in requires:items() do if not oldrequires:has(required) then requires_changed = true break @@ -484,6 +479,5 @@ function is_dependencies_changed(target, module) end end end - return requires, changed end From 921b651c56f25817a4fbac8359497e5bb12375f1 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 8 Oct 2024 11:32:00 +0800 Subject: [PATCH 20/21] Update builder.lua --- xmake/rules/c++/modules/modules_support/msvc/builder.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index bb7090cb49f..5998db62ff6 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -173,7 +173,7 @@ function _get_requiresflags(target, module, opt) local requiresflags = compiler_support.memcache():get2(cachekey, "requiresflags") if not requiresflags or requires_changed then local deps_flags = {} - for required, _ in requires:orderkeys() do + for required in requires:orderitems() do local dep_module = get_from_target_mapper(target, required) assert(dep_module, "module dependency %s required for %s not found <%s>", required, name, target:name()) @@ -204,8 +204,8 @@ function _get_requiresflags(target, module, opt) requiresflags = {} local contains = {} for _, map in ipairs(deps_flags) do - local name, _ = map[2]:split("=")[1], map[2]:split("=")[2] - if not contains[name] then + local name = map[2]:split("=")[1] + if name and not contains[name] then table.insert(requiresflags, map) contains[name] = true end @@ -414,4 +414,3 @@ function make_headerunit_buildcmds(target, batchcmds, headerunit, bmifile, outpu batchcmds:add_depfiles(headerunit.path) return os.mtime(bmifile) end - From 7106bb8cbfb98dd13c0a0481067e19aac60baf76 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 8 Oct 2024 11:33:11 +0800 Subject: [PATCH 21/21] Update builder.lua --- xmake/rules/c++/modules/modules_support/clang/builder.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index ad30aa158d3..6d60f49a0be 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -126,7 +126,7 @@ function _get_requiresflags(target, module, opt) local requiresflags = compiler_support.memcache():get2(cachekey, "requiresflags") if not requiresflags or requires_changed then requiresflags = {} - for required, _ in requires:orderkeys() do + for required in requires:orderitems() do local dep_module = get_from_target_mapper(target, required) assert(dep_module, "module dependency %s required for %s not found", required, name) @@ -358,4 +358,3 @@ function get_requires(target, module) end return _requires end -