From a393c0a2d41c22514769ec270818a599c2b9008f Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 3 Feb 2024 19:45:17 +0100 Subject: fix recompilation of .cpp files --- .../rules/c++/modules/modules_support/builder.lua | 37 ++++------- .../c++/modules/modules_support/clang/builder.lua | 74 ++++++++++++++-------- .../c++/modules/modules_support/gcc/builder.lua | 24 ++++++- .../c++/modules/modules_support/msvc/builder.lua | 52 ++++++++++----- 4 files changed, 120 insertions(+), 67 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/builder.lua b/xmake/rules/c++/modules/modules_support/builder.lua index 741009af5..a4bbc9c7f 100644 --- a/xmake/rules/c++/modules/modules_support/builder.lua +++ b/xmake/rules/c++/modules/modules_support/builder.lua @@ -47,24 +47,17 @@ function _build_modules(target, sourcebatch, modules, opt) local fileconfig = target:fileconfig(cppfile) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) - local build = _should_build(target, cppfile, bmifile, {objectfile = objectfile, requires = module.requires}) - -- add objectfile if module is not from external dep if not (fileconfig and fileconfig.external) then target:add("objectfiles", objectfile) end - -- needed to detect rebuild of dependencies - if provide and build then - _mark_build(target, name) - end - local deps = {} for _, dep in ipairs(table.keys(module.requires or {})) do table.insert(deps, opt.batchjobs and target:name() .. dep or dep) end - opt.build_module(deps, build, module, name, provide, objectfile, cppfile, fileconfig) + opt.build_module(deps, module, name, provide, objectfile, cppfile, fileconfig) ::CONTINUE:: end @@ -112,23 +105,21 @@ function _should_build(target, sourcefile, bmifile, opt) end end - -- or rebuild it if the file changed for headerunit and namedmodules + -- or rebuild it if the file changed local objectfile = opt.objectfile - if compiler_support.has_module_extension(sourcefile) or (opt and opt.headerunit) then - local dryrun = option.get("dry-run") - local compinst = compiler.load("cxx", {target = target}) - local compflags = compinst:compflags({sourcefile = sourcefile, target = target}) + local dryrun = option.get("dry-run") + local compinst = compiler.load("cxx", {target = target}) + local compflags = compinst:compflags({sourcefile = sourcefile, target = target}) - local dependfile = target:dependfile(bmifile or objectfile) - local dependinfo = target:is_rebuilt() and {} or (depend.load(dependfile) or {}) + local dependfile = target:dependfile(bmifile or objectfile) + local dependinfo = target:is_rebuilt() and {} or (depend.load(dependfile) or {}) - -- need build this object? - local depvalues = {compinst:program(), compflags} - local lastmtime = os.isfile(bmifile or objectfile) and os.mtime(dependfile) or 0 + -- need build this object? + local depvalues = {compinst:program(), compflags} + local lastmtime = os.isfile(bmifile or objectfile) and os.mtime(dependfile) or 0 - if dryrun or depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues}) then - return true - end + if dryrun or depend.is_changed(dependinfo, {lastmtime = lastmtime, values = depvalues}) then + return true end return false @@ -207,10 +198,10 @@ function build_modules_for_batchjobs(target, batchjobs, sourcebatch, modules, op local modulesjobs = {} _build_modules(target, sourcebatch, modules, table.join(opt, { - build_module = function(deps, build, module, name, provide, objectfile, cppfile, fileconfig) + build_module = function(deps, module, name, provide, objectfile, cppfile, fileconfig) local job_name = name and target:name() .. name or cppfile - modulesjobs[job_name] = _builder(target).make_module_buildjobs(target, batchjobs, job_name, deps, {build = build, module = module, objectfile = objectfile, cppfile = cppfile}) + modulesjobs[job_name] = _builder(target).make_module_buildjobs(target, batchjobs, job_name, deps, _should_build, _mark_build, {module = module, objectfile = objectfile, cppfile = cppfile}) if provide and fileconfig and fileconfig.public then batchjobs:addjob(name .. "_metafile", function(index, total) diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index 86b3d1a37..8b1cdf827 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -190,7 +190,7 @@ function get_module_required_defines(target, sourcefile) end -- build module file for batchjobs -function make_module_buildjobs(target, batchjobs, job_name, deps, opt) +function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, mark_build, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) @@ -210,31 +210,42 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) _append_requires_flags(target, opt.module, name, opt.cppfile, bmifile, opt) end + local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) + + -- needed to detect rebuild of dependencies + if provide and build then + mark_build(target, name) + end + local dependfile = target:dependfile(bmifile or opt.objectfile) local dependinfo = depend.load(dependfile) or {} dependinfo.files = {} local depvalues = {compinst:program(), compflags} - -- compile if it's a named module - if opt.build and (provide or compiler_support.has_module_extension(opt.cppfile)) then - progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) + if build then + -- compile if it's a named module + if provide or compiler_support.has_module_extension(opt.cppfile) then + progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) - if not dryrun then - local objectdir = path.directory(opt.objectfile) - if not os.isdir(objectdir) then - os.mkdir(objectdir) + if not dryrun then + local objectdir = path.directory(opt.objectfile) + if not os.isdir(objectdir) then + os.mkdir(objectdir) + end end - end - local fileconfig = target:fileconfig(opt.cppfile) - local external = fileconfig and fileconfig.external + local fileconfig = target:fileconfig(opt.cppfile) + local external = fileconfig and fileconfig.external - local precompile, first_step, second_step = _make_modulebuildflags(target, provide, bmifile, {sourcefile = opt.cppfile, external = external, name = name}) + local precompile, first_step, second_step = _make_modulebuildflags(target, provide, bmifile, {sourcefile = opt.cppfile, external = external, name = name}) - _compile(target, first_step, opt.cppfile, precompile and bmifile or opt.objectfile) + _compile(target, first_step, opt.cppfile, precompile and bmifile or opt.objectfile) - if second_step then - _compile(target, second_step, opt.cppfile, opt.objectfile, {bmifile = bmifile}) + if second_step then + _compile(target, second_step, opt.cppfile, opt.objectfile, {bmifile = bmifile}) + end + else + os.tryrm(opt.objectfile) -- force rebuild for .cpp files end end @@ -245,7 +256,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) end -- build module file for batchcmds -function make_module_buildcmds(target, batchcmds, opt) +function make_module_buildcmds(target, batchcmds, should_build, mark_build, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) @@ -255,19 +266,30 @@ function make_module_buildcmds(target, batchcmds, opt) _append_requires_flags(target, opt.module, name, opt.cppfile, bmifile, opt) end - -- compile if it's a named module - if opt.build and (provide or compiler_support.has_module_extension(opt.cppfile)) then - batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) - batchcmds:mkdir(path.directory(opt.objectfile)) + local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) - local fileconfig = target:fileconfig(opt.cppfile) - local external = fileconfig and fileconfig.external + -- needed to detect rebuild of dependencies + if provide and build then + mark_build(target, name) + end + + if build then + -- compile if it's a named module + if provide or compiler_support.has_module_extension(opt.cppfile) then + batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) + batchcmds:mkdir(path.directory(opt.objectfile)) + + local fileconfig = target:fileconfig(opt.cppfile) + local external = fileconfig and fileconfig.external - local precompile, first_step, second_step = _make_modulebuildflags(target, provide, bmifile, {batchcmds = true, sourcefile = opt.cppfile, external = external, name = name}) - _batchcmds_compile(batchcmds, target, first_step, opt.cppfile, precompile and bmifile or opt.objectfile) + local precompile, first_step, second_step = _make_modulebuildflags(target, provide, bmifile, {batchcmds = true, sourcefile = opt.cppfile, external = external, name = name}) + _batchcmds_compile(batchcmds, target, first_step, opt.cppfile, precompile and bmifile or opt.objectfile) - if second_step then - _batchcmds_compile(batchcmds, target, second_step, opt.cppfile, opt.objectfile, {bmifile = bmifile}) + if second_step then + _batchcmds_compile(batchcmds, target, second_step, opt.cppfile, opt.objectfile, {bmifile = bmifile}) + end + else + batchcmds:rm(opt.objectfile) -- force rebuild for .cpp files end end batchcmds:add_depfiles(opt.cppfile) diff --git a/xmake/rules/c++/modules/modules_support/gcc/builder.lua b/xmake/rules/c++/modules/modules_support/gcc/builder.lua index 2f763744a..c90fe743e 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/builder.lua @@ -207,7 +207,7 @@ function get_module_required_defines(target, sourcefile) end -- build module file for batchjobs -function make_module_buildjobs(target, batchjobs, job_name, deps, opt) +function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, mark_build, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) @@ -229,6 +229,13 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) target:fileconfig_add(opt.cppfile, {force = {cxxflags = {module_mapperflag .. module_mapper}}}) end + local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) + + -- needed to detect rebuild of dependencies + if provide and build then + mark_build(target, name) + end + local dependfile = target:dependfile(bmifile or opt.objectfile) local dependinfo = depend.load(dependfile) or {} dependinfo.files = {} @@ -245,6 +252,8 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local flags = _make_modulebuildflags(target, opt) _compile(target, flags, opt.cppfile, opt.objectfile) os.tryrm(module_mapper) + else + os.tryrm(opt.objectfile) -- force rebuild for .cpp files end end table.insert(dependinfo.files, opt.cppfile) @@ -254,7 +263,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) end -- build module file for batchcmds -function make_module_buildcmds(target, batchcmds, opt) +function make_module_buildcmds(target, batchcmds, should_build, mark_build, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local module_mapperflag = compiler_support.get_modulemapperflag(target) @@ -266,7 +275,14 @@ function make_module_buildcmds(target, batchcmds, opt) target:fileconfig_add(opt.cppfile, {force = {cxxflags = {module_mapperflag .. module_mapper}}}) end - if opt.build then + local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) + + -- needed to detect rebuild of dependencies + if provide and build then + mark_build(target, name) + end + + if build then -- compile if it's a named module if provide or compiler_support.has_module_extension(opt.cppfile) then batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) @@ -275,6 +291,8 @@ function make_module_buildcmds(target, batchcmds, opt) end batchcmds:mkdir(path.directory(opt.objectfile)) _batchcmds_compile(batchcmds, target, _make_modulebuildflags(target, {batchcmds = true, sourcefile = opt.cppfile}), opt.cppfile, opt.objectfile) + else + batchcmds:rm(opt.objectfile) -- force rebuild for .cpp files end end batchcmds:add_depfiles(opt.cppfile) diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index 019235837..925f0fa35 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -207,7 +207,7 @@ function get_module_required_defines(target, sourcefile) end -- build module file for batchjobs -function make_module_buildjobs(target, batchjobs, job_name, deps, opt) +function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, mark_build, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) @@ -227,27 +227,39 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) _append_requires_flags(target, opt.module, name, opt.cppfile, bmifile, opt) end + local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) + + -- needed to detect rebuild of dependencies + if provide and build then + mark_build(target, name) + end + + local dependfile = target:dependfile(bmifile or opt.objectfile) local dependinfo = depend.load(dependfile) or {} dependinfo.files = {} local depvalues = {compinst:program(), compflags} - -- compile if it's a named module - if opt.build and (provide or compiler_support.has_module_extension(opt.cppfile)) then - progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) + if build then + -- compile if it's a named module + if provide or compiler_support.has_module_extension(opt.cppfile) then + progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) - if not dryrun then - local objectdir = path.directory(opt.objectfile) - if not os.isdir(objectdir) then - os.mkdir(objectdir) + if not dryrun then + local objectdir = path.directory(opt.objectfile) + if not os.isdir(objectdir) then + os.mkdir(objectdir) + end end - end - local fileconfig = target:fileconfig(opt.cppfile) - local external = fileconfig and fileconfig.external - local flags = _make_modulebuildflags(target, provide, bmifile, {external = external}) + local fileconfig = target:fileconfig(opt.cppfile) + local external = fileconfig and fileconfig.external + local flags = _make_modulebuildflags(target, provide, bmifile, {external = external}) - _compile(target, flags, opt.cppfile, opt.objectfile) + _compile(target, flags, opt.cppfile, opt.objectfile) + else + os.tryrm(opt.objectfile) -- force rebuild for .cpp files + end end table.insert(dependinfo.files, opt.cppfile) @@ -257,7 +269,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) end -- build module file for batchcmds -function make_module_buildcmds(target, batchcmds, opt) +function make_module_buildcmds(target, batchcmds, should_build, mark_build, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) @@ -267,7 +279,15 @@ function make_module_buildcmds(target, batchcmds, opt) _append_requires_flags(target, opt.module, name, opt.cppfile, bmifile, opt) end - if opt.build then + local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) + + -- needed to detect rebuild of dependencies + if provide and build then + mark_build(target, name) + end + + if build then + -- compile if it's a named module if provide or compiler_support.has_module_extension(opt.cppfile) then batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) batchcmds:mkdir(path.directory(opt.objectfile)) @@ -276,6 +296,8 @@ function make_module_buildcmds(target, batchcmds, opt) local external = fileconfig and fileconfig.external local flags = _make_modulebuildflags(target, provide, bmifile, opt.cppfile, opt.objectfile, {batchcmds = true, external = external}) _batchcmds_compile(batchcmds, target, flags, opt.cppfile, objectfile) + else + batchcmds:rm(opt.objectfile) -- force rebuild for .cpp files end end batchcmds:add_depfiles(opt.cppfile) -- cgit v1.3.1 From fa0d8835aeae4905ce607d84cb15dd23bcaa19ce Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 3 Feb 2024 22:21:26 +0100 Subject: fix recompilation for gcc --- .../c++/modules/modules_support/gcc/builder.lua | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/gcc/builder.lua b/xmake/rules/c++/modules/modules_support/gcc/builder.lua index c90fe743e..ae3ed2d95 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/builder.lua @@ -222,13 +222,6 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, local compinst = compiler.load("cxx", {target = target}) local compflags = compinst:compflags({sourcefile = opt.cppfile, target = target}) - -- generate and append module mapper file - local module_mapper - if provide or opt.module.requires then - module_mapper = _generate_modulemapper_file(target, opt.module) - target:fileconfig_add(opt.cppfile, {force = {cxxflags = {module_mapperflag .. module_mapper}}}) - end - local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) -- needed to detect rebuild of dependencies @@ -236,6 +229,13 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, mark_build(target, name) end + -- generate and append module mapper file + local module_mapper + if provide or opt.module.requires then + module_mapper = _generate_modulemapper_file(target, opt.module) + target:fileconfig_add(opt.cppfile, {force = {cxxflags = {module_mapperflag .. module_mapper}}}) + end + local dependfile = target:dependfile(bmifile or opt.objectfile) local dependinfo = depend.load(dependfile) or {} dependinfo.files = {} @@ -266,15 +266,9 @@ end function make_module_buildcmds(target, batchcmds, should_build, mark_build, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) + local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) local module_mapperflag = compiler_support.get_modulemapperflag(target) - -- generate and append module mapper file - local module_mapper - if provide or opt.module.requires then - module_mapper = _generate_modulemapper_file(target, opt.module) - target:fileconfig_add(opt.cppfile, {force = {cxxflags = {module_mapperflag .. module_mapper}}}) - end - local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) -- needed to detect rebuild of dependencies @@ -282,6 +276,13 @@ function make_module_buildcmds(target, batchcmds, should_build, mark_build, opt) mark_build(target, name) end + -- generate and append module mapper file + local module_mapper + if provide or opt.module.requires then + module_mapper = _generate_modulemapper_file(target, opt.module) + target:fileconfig_add(opt.cppfile, {force = {cxxflags = {module_mapperflag .. module_mapper}}}) + end + if build then -- compile if it's a named module if provide or compiler_support.has_module_extension(opt.cppfile) then -- cgit v1.3.1 From ce79b0d86208463a6a6fded2131baf72247526d1 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 3 Feb 2024 22:32:33 +0100 Subject: fix batchcmds --- xmake/rules/c++/modules/modules_support/builder.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/builder.lua b/xmake/rules/c++/modules/modules_support/builder.lua index a4bbc9c7f..93ecebe08 100644 --- a/xmake/rules/c++/modules/modules_support/builder.lua +++ b/xmake/rules/c++/modules/modules_support/builder.lua @@ -228,8 +228,8 @@ function build_modules_for_batchcmds(target, batchcmds, sourcebatch, modules, op -- build modules _build_modules(target, sourcebatch, modules, table.join(opt, { - build_module = function(_, build, module, name, provide, objectfile, cppfile, fileconfig) - depmtime = math.max(depmtime, _builder(target).make_module_buildcmds(target, batchcmds, {build = build, module = module, cppfile = cppfile, objectfile = objectfile, progress = opt.progress})) + build_module = function(_, module, name, provide, objectfile, cppfile, fileconfig) + depmtime = math.max(depmtime, _builder(target).make_module_buildcmds(target, batchcmds, _should_build, _mark_build, {module = module, cppfile = cppfile, objectfile = objectfile, progress = opt.progress})) if provide and fileconfig and fileconfig.public then local metafilepath = compiler_support.get_metafile(target, cppfile) -- cgit v1.3.1 From ca775e5acba55f26f4d33aae784e4d6b809e2339 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 3 Feb 2024 23:59:46 +0100 Subject: fix unnecessary recompilation of modules --- .../c++/modules/modules_support/clang/builder.lua | 34 ++++++++++++++------- .../c++/modules/modules_support/msvc/builder.lua | 35 +++++++++++++++------- 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index 8b1cdf827..9643fe84e 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -205,16 +205,23 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, local compinst = compiler.load("cxx", {target = target}) local compflags = compinst:compflags({sourcefile = opt.cppfile, target = target}) + if provide or compiler_support.has_module_extension(opt.cppfile) then + build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) + + -- needed to detect rebuild of dependencies + if provide and build then + mark_build(target, name) + end + end + -- append requires flags if opt.module.requires then _append_requires_flags(target, opt.module, name, opt.cppfile, bmifile, opt) end - local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) - - -- needed to detect rebuild of dependencies - if provide and build then - mark_build(target, name) + -- for cpp file we need to check after appendings the flags + if build == nil then + build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) end local dependfile = target:dependfile(bmifile or opt.objectfile) @@ -261,16 +268,23 @@ function make_module_buildcmds(target, batchcmds, should_build, mark_build, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) + if provide or compiler_support.has_module_extension(opt.cppfile) then + build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) + + -- needed to detect rebuild of dependencies + if provide and build then + mark_build(target, name) + end + end + -- append requires flags if opt.module.requires then _append_requires_flags(target, opt.module, name, opt.cppfile, bmifile, opt) end - local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) - - -- needed to detect rebuild of dependencies - if provide and build then - mark_build(target, name) + -- for cpp file we need to check after appendings the flags + if build == nil then + build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) end if build then diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index 925f0fa35..3a4b14b68 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -222,19 +222,25 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, local compinst = compiler.load("cxx", {target = target}) local compflags = compinst:compflags({sourcefile = opt.cppfile, target = target}) + if provide or compiler_support.has_module_extension(opt.cppfile) then + build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) + + -- needed to detect rebuild of dependencies + if provide and build then + mark_build(target, name) + end + end + -- append requires flags if opt.module.requires then _append_requires_flags(target, opt.module, name, opt.cppfile, bmifile, opt) end - local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) - - -- needed to detect rebuild of dependencies - if provide and build then - mark_build(target, name) + -- for cpp file we need to check after appendings the flags + if build == nil then + build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) end - local dependfile = target:dependfile(bmifile or opt.objectfile) local dependinfo = depend.load(dependfile) or {} dependinfo.files = {} @@ -274,16 +280,23 @@ function make_module_buildcmds(target, batchcmds, should_build, mark_build, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) + if provide or compiler_support.has_module_extension(opt.cppfile) then + build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) + + -- needed to detect rebuild of dependencies + if provide and build then + mark_build(target, name) + end + end + -- append requires flags if opt.module.requires then _append_requires_flags(target, opt.module, name, opt.cppfile, bmifile, opt) end - local build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) - - -- needed to detect rebuild of dependencies - if provide and build then - mark_build(target, name) + -- for cpp file we need to check after appendings the flags + if build == nil then + build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) end if build then -- cgit v1.3.1 From e5f820e4f187e2a87db4b88c76cc2ac3da2b24d7 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Feb 2024 16:44:22 +0100 Subject: make should_build and mark_build public --- xmake/rules/c++/modules/modules_support/builder.lua | 12 ++++++------ xmake/rules/c++/modules/modules_support/clang/builder.lua | 4 ++-- xmake/rules/c++/modules/modules_support/gcc/builder.lua | 4 ++-- xmake/rules/c++/modules/modules_support/msvc/builder.lua | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/builder.lua b/xmake/rules/c++/modules/modules_support/builder.lua index 93ecebe08..4ceb67b0b 100644 --- a/xmake/rules/c++/modules/modules_support/builder.lua +++ b/xmake/rules/c++/modules/modules_support/builder.lua @@ -78,10 +78,10 @@ function _build_headerunits(target, headerunits, opt) end local bmifile = path.join(outputdir, path.filename(headerunit.name) .. compiler_support.get_bmi_extension(target)) local key = path.normalize(headerunit.path) - local build = _should_build(target, headerunit.path, bmifile, {key = key, headerunit = true}) + local build = should_build(target, headerunit.path, bmifile, {key = key, headerunit = true}) if build then - _mark_build(target, key) + mark_build(target, key) end opt.build_headerunit(headerunit, key, bmifile, outputdir, build) @@ -89,7 +89,7 @@ function _build_headerunits(target, headerunits, opt) end -- should we build this module or headerunit ? -function _should_build(target, sourcefile, bmifile, opt) +function should_build(target, sourcefile, bmifile, opt) -- force rebuild a module if any of its module dependency is rebuilt local requires = opt.requires @@ -181,7 +181,7 @@ function _builder(target) return builder end -function _mark_build(target, name) +function mark_build(target, name) compiler_support.memcache():set2("should_build_in" .. target:name(), name, true) end @@ -201,7 +201,7 @@ function build_modules_for_batchjobs(target, batchjobs, sourcebatch, modules, op build_module = function(deps, module, name, provide, objectfile, cppfile, fileconfig) local job_name = name and target:name() .. name or cppfile - modulesjobs[job_name] = _builder(target).make_module_buildjobs(target, batchjobs, job_name, deps, _should_build, _mark_build, {module = module, objectfile = objectfile, cppfile = cppfile}) + modulesjobs[job_name] = _builder(target).make_module_buildjobs(target, batchjobs, job_name, deps, {module = module, objectfile = objectfile, cppfile = cppfile}) if provide and fileconfig and fileconfig.public then batchjobs:addjob(name .. "_metafile", function(index, total) @@ -229,7 +229,7 @@ function build_modules_for_batchcmds(target, batchcmds, sourcebatch, modules, op -- build modules _build_modules(target, sourcebatch, modules, table.join(opt, { build_module = function(_, module, name, provide, objectfile, cppfile, fileconfig) - depmtime = math.max(depmtime, _builder(target).make_module_buildcmds(target, batchcmds, _should_build, _mark_build, {module = module, cppfile = cppfile, objectfile = objectfile, progress = opt.progress})) + depmtime = math.max(depmtime, _builder(target).make_module_buildcmds(target, batchcmds, {module = module, cppfile = cppfile, objectfile = objectfile, progress = opt.progress})) if provide and fileconfig and fileconfig.public then local metafilepath = compiler_support.get_metafile(target, cppfile) diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index 9643fe84e..0d470ada4 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -190,7 +190,7 @@ function get_module_required_defines(target, sourcefile) end -- build module file for batchjobs -function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, mark_build, opt) +function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) @@ -263,7 +263,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, end -- build module file for batchcmds -function make_module_buildcmds(target, batchcmds, should_build, mark_build, opt) +function make_module_buildcmds(target, batchcmds, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) diff --git a/xmake/rules/c++/modules/modules_support/gcc/builder.lua b/xmake/rules/c++/modules/modules_support/gcc/builder.lua index ae3ed2d95..db0ea3958 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/builder.lua @@ -207,7 +207,7 @@ function get_module_required_defines(target, sourcefile) end -- build module file for batchjobs -function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, mark_build, opt) +function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) @@ -263,7 +263,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, end -- build module file for batchcmds -function make_module_buildcmds(target, batchcmds, should_build, mark_build, opt) +function make_module_buildcmds(target, batchcmds, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index 3a4b14b68..4aa353214 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -207,7 +207,7 @@ function get_module_required_defines(target, sourcefile) end -- build module file for batchjobs -function make_module_buildjobs(target, batchjobs, job_name, deps, should_build, mark_build, opt) +function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) -- cgit v1.3.1 From 2728a2c821de5fb2e9567fea74ca38a81e5cfea0 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Feb 2024 16:47:25 +0100 Subject: fix gcc module compilation --- xmake/rules/c++/modules/modules_support/gcc/builder.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/rules/c++/modules/modules_support/gcc/builder.lua b/xmake/rules/c++/modules/modules_support/gcc/builder.lua index db0ea3958..7e96c3fcc 100644 --- a/xmake/rules/c++/modules/modules_support/gcc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/gcc/builder.lua @@ -241,7 +241,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) dependinfo.files = {} local depvalues = {compinst:program(), compflags} - if opt.build then + if build then -- compile if it's a named module if provide or compiler_support.has_module_extension(opt.cppfile) then progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.module.$(mode) %s", target:name(), name or opt.cppfile) -- cgit v1.3.1 From ffe0768bd867f90d482eeb7c12739e3a8fc00679 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Feb 2024 20:45:36 +0100 Subject: fix missing build variable declaration --- xmake/rules/c++/modules/modules_support/clang/builder.lua | 2 ++ xmake/rules/c++/modules/modules_support/msvc/builder.lua | 2 ++ 2 files changed, 4 insertions(+) diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua index 0d470ada4..15a53c00b 100644 --- a/xmake/rules/c++/modules/modules_support/clang/builder.lua +++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua @@ -205,6 +205,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local compinst = compiler.load("cxx", {target = target}) local compflags = compinst:compflags({sourcefile = opt.cppfile, target = target}) + local build if provide or compiler_support.has_module_extension(opt.cppfile) then build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) @@ -268,6 +269,7 @@ function make_module_buildcmds(target, batchcmds, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) + local build if provide or compiler_support.has_module_extension(opt.cppfile) then build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua index 4aa353214..10a0ad409 100644 --- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua +++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua @@ -222,6 +222,7 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt) local compinst = compiler.load("cxx", {target = target}) local compflags = compinst:compflags({sourcefile = opt.cppfile, target = target}) + local build if provide or compiler_support.has_module_extension(opt.cppfile) then build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) @@ -280,6 +281,7 @@ function make_module_buildcmds(target, batchcmds, should_build, mark_build, opt) local name, provide, _ = compiler_support.get_provided_module(opt.module) local bmifile = provide and compiler_support.get_bmi_path(provide.bmi) + local build if provide or compiler_support.has_module_extension(opt.cppfile) then build = should_build(target, opt.cppfile, bmifile, {objectfile = opt.objectfile, requires = opt.module.requires}) -- cgit v1.3.1