summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules
diff options
context:
space:
mode:
authorArthur Laurent <[email protected]>2024-02-02 18:30:05 +0100
committerGitHub <[email protected]>2024-02-02 18:30:05 +0100
commit05deea2df8d17cfae17694b7e5cc78213c068ea4 (patch)
tree8b86aab514f3b36826068efcf7de3571dcd4bd71 /xmake/rules/c++/modules
parentaedc8fa8b17560952782e8409fb41937fa781486 (diff)
parent48be7cd276d22c5cc16058fe328741c7ebd471d1 (diff)
Merge branch 'modules' into optimise-dag
Diffstat (limited to 'xmake/rules/c++/modules')
-rw-r--r--xmake/rules/c++/modules/modules_support/clang/builder.lua2
-rw-r--r--xmake/rules/c++/modules/modules_support/clang/compiler_support.lua31
-rw-r--r--xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua95
-rw-r--r--xmake/rules/c++/modules/modules_support/dependency_scanner.lua20
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua65
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc/builder.lua47
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua55
-rw-r--r--xmake/rules/c++/modules/xmake.lua8
8 files changed, 181 insertions, 142 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua
index 5f4fe249b..86b3d1a37 100644
--- a/xmake/rules/c++/modules/modules_support/clang/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua
@@ -98,7 +98,7 @@ function _batchcmds_compile(batchcmds, target, flags, sourcefile, outputfile, op
opt = opt or {}
local compinst = target:compiler("cxx")
local compflags = compinst:compflags({sourcefile = sourcefile, target = target})
- local flags = table.join("-c", compflags or {}, flags, {"-o", outputfile, opt.bmifile or sourcefile})
+ flags = table.join("-c", compflags or {}, flags, {"-o", outputfile, opt.bmifile or sourcefile})
batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx"})
end
diff --git a/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua b/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua
index 64bd70dd1..ebbfb99ff 100644
--- a/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua
+++ b/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua
@@ -20,7 +20,10 @@
-- imports
import("core.base.semver")
+import("core.base.option")
+import("core.base.json")
import("lib.detect.find_tool")
+import("lib.detect.find_file")
import(".compiler_support", {inherit = true})
-- get includedirs for stl headers
@@ -142,8 +145,8 @@ function get_clang_path(target)
local clang_path = _g.clang_path
if not clang_path then
local program, toolname = target:tool("cxx")
- if program and (toolname == "clang" or toolname == "clangxx") then
- local clang = find_tool("clang", {program = program})
+ if program and toolname:startswith("clang") then
+ local clang = find_tool(toolname, {program = program})
if clang then
clang_path = clang.program
end
@@ -159,8 +162,8 @@ function get_clang_version(target)
local clang_version = _g.clang_version
if not clang_version then
local program, toolname = target:tool("cxx")
- if program and (toolname == "clang" or toolname == "clangxx") then
- local clang = find_tool("clang", {program = program, version = true})
+ if program and toolname:startswith("clang") then
+ local clang = find_tool(toolname, {program = program, version = true})
if clang then
clang_version = clang.version
end
@@ -176,7 +179,7 @@ function get_clang_scan_deps(target)
local clang_scan_deps = _g.clang_scan_deps
if not clang_scan_deps then
local program, toolname = target:tool("cxx")
- if program and (toolname == "clang" or toolname == "clangxx") then
+ if program and toolname:startswith("clang") then
local dir = path.directory(program)
local basename = path.basename(program)
local extension = path.extension(program)
@@ -195,13 +198,26 @@ function get_clang_scan_deps(target)
return clang_scan_deps or nil
end
--- not supported atm
function get_stdmodules(target)
if target:policy("build.c++.modules.std") then
local cpplib = _get_cpplibrary_name(target)
if cpplib then
if cpplib == "c++" then
- -- TODO support libc++ std module file when https://github.com/xmake-io/xmake/pull/4630
+ -- libc++ module is found by parsing libc++.modules.json
+ -- which can be found in <llvm_path>/lib subdirectory (i.e on debian it should be <llvm_path>/lib/x86_64-unknown-linux-gnu/)
+ -- in the futur llvm may provide a way to directory get the path of libc++.modules.json
+ -- @see https://github.com/llvm/llvm-project/pull/76451 (has been revert, so we need to wait)
+ local clang_path = path.directory(get_clang_path(target))
+ local clang_lib_path = path.join(clang_path, "..", "lib")
+ local modules_json_path = find_file("libc++.modules.json", clang_lib_path)
+ if modules_json_path then
+ local modules_json = json.decode(io.readfile(modules_json_path))
+ local std_module_directory = path.directory(modules_json.modules[1]["source-path"])
+ if not path.is_absolute(std_module_directory) then
+ std_module_directory = path.join(path.directory(modules_json_path), std_module_directory)
+ end
+ return {path.join(std_module_directory, "std.cppm"), path.join(std_module_directory, "std.compat.cppm")}
+ end
elseif cpplib == "stdc++" then
-- libstdc++ doesn't have a std module file atm
elseif cpplib == "msstl" then
@@ -222,7 +238,6 @@ function get_stdmodules(target)
end
end
end
- return {}
end
function get_bmi_extension()
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 17d886b0b..9e3982bb0 100644
--- a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua
+++ b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua
@@ -27,59 +27,58 @@ import("utils.progress")
import("compiler_support")
import(".dependency_scanner", {inherit = true})
--- generate dependency files
-function generate_dependencies(target, sourcebatch, opt)
+function generate_dependency_for(target, sourcefile, opt)
local compinst = target:compiler("cxx")
local changed = false
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- local dependfile = target:dependfile(sourcefile)
- depend.on_changed(function()
- if opt.progress then
- progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile)
- end
+ local dependfile = target:dependfile(sourcefile)
+ depend.on_changed(function()
+ if opt.progress then
+ progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile)
+ end
- local outputdir = compiler_support.get_outputdir(target, sourcefile)
- local jsonfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".json"))
- if compiler_support.has_clangscandepssupport(target) and not target:policy("build.c++.clang.fallbackscanner") then
- -- We need absolute path of clang to use clang-scan-deps
- -- See https://clang.llvm.org/docs/StandardCPlusPlusModules.html#possible-issues-failed-to-find-system-headers
- local clang_path = compinst:program()
- if not path.is_absolute(clang_path) then
- 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
- print(os.args(table.join(clangscandeps, flags)))
- end
- local outdata, errdata = os.iorunv(clangscandeps, flags)
- assert(errdata, errdata)
+ local outputdir = compiler_support.get_outputdir(target, sourcefile)
+ local jsonfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".json"))
+ if compiler_support.has_clangscandepssupport(target) and not target:policy("build.c++.clang.fallbackscanner") then
+ -- We need absolute path of clang to use clang-scan-deps
+ -- See https://clang.llvm.org/docs/StandardCPlusPlusModules.html#possible-issues-failed-to-find-system-headers
+ local clang_path = compinst:program()
+ if not path.is_absolute(clang_path) then
+ 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
+ print(os.args(table.join(clangscandeps, flags)))
+ end
+ local outdata, errdata = os.iorunv(clangscandeps, flags)
+ assert(errdata, errdata)
- io.writefile(jsonfile, outdata)
- else
- 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 a this point of compilation
- table.remove_if(compflags, function(_, flag)
- 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)
- local content = io.readfile(ifile)
- os.rm(ifile)
- return content
+ io.writefile(jsonfile, outdata)
+ else
+ 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 a this point of compilation
+ table.remove_if(compflags, function(_, flag)
+ return flag:startswith("-fmodule") or flag:startswith("-std=c++") or flag:startswith("-std=gnu++")
end)
- end
- changed = true
+ 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)
+ local content = io.readfile(ifile)
+ os.rm(ifile)
+ return content
+ end)
+ end
+ changed = true
+
+ local rawdependinfo = io.readfile(jsonfile)
+ return {moduleinfo = rawdependinfo}
+ end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt()})
- local rawdependinfo = io.readfile(jsonfile)
- return {moduleinfo = rawdependinfo}
- end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt()})
- end
return changed
end
+
diff --git a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua
index f7d05a609..7d5526c95 100644
--- a/xmake/rules/c++/modules/modules_support/dependency_scanner.lua
+++ b/xmake/rules/c++/modules/modules_support/dependency_scanner.lua
@@ -22,6 +22,8 @@
import("core.base.json")
import("core.base.hashset")
import("core.base.graph")
+import("core.base.option")
+import("async.runjobs")
import("compiler_support")
import("stl_headers")
@@ -204,6 +206,22 @@ function _get_package_modules(target, package, opt)
return package_modules
end
+-- generate dependency files
+function _generate_dependencies(target, sourcebatch, opt)
+ local changed = false
+ if opt.batchjobs then
+ local jobs = option.get("jobs") or os.default_njob()
+ runjobs(target:name() .. "_module_dependency_scanner", function(index)
+ local sourcefile = sourcebatch.sourcefiles[index]
+ changed = _dependency_scanner(target).generate_dependency_for(target, sourcefile, opt) or changed
+ end, {comax = jobs, total = #sourcebatch.sourcefiles})
+ else
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ changed = _dependency_scanner(target).generate_dependency_for(target, sourcefile, opt) or changed
+ end
+ end
+ return changed
+end
-- get module dependencies
function get_module_dependencies(target, sourcebatch, opt)
local cachekey = target:name() .. "/" .. sourcebatch.rulename
@@ -211,7 +229,7 @@ function get_module_dependencies(target, sourcebatch, opt)
if modules == nil or opt.regenerate then
modules = compiler_support.localcache():get2("modules", cachekey)
opt.progress = opt.progress or 0
- local changed = _dependency_scanner(target).generate_dependencies(target, sourcebatch, opt)
+ local changed = _generate_dependencies(target, sourcebatch, opt)
if changed or modules == nil then
local moduleinfos = compiler_support.load_moduleinfos(target, sourcebatch)
modules = _parse_dependencies_data(target, moduleinfos)
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 982eae960..8cdb0a0a3 100644
--- a/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc/dependency_scanner.lua
@@ -28,49 +28,48 @@ import("builder")
import(".dependency_scanner", {inherit = true})
-- generate dependency files
-function generate_dependencies(target, sourcebatch, opt)
+function generate_dependency_for(target, sourcefile, opt)
local compinst = target:compiler("cxx")
local baselineflags = {"-E", "-x", "c++"}
local depsformatflag = compiler_support.get_depsflag(target, "p1689r5")
local depsfileflag = compiler_support.get_depsfileflag(target)
local depstargetflag = compiler_support.get_depstargetflag(target)
+ local dependfile = target:dependfile(sourcefile)
local changed = false
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- local dependfile = target:dependfile(sourcefile)
- depend.on_changed(function()
- if opt.progress then
- progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile)
- end
- local outputdir = compiler_support.get_outputdir(target, sourcefile)
- local jsonfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".json"))
- if depsformatflag and depsfileflag and depstargetflag 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})
+ depend.on_changed(function()
+ if opt.progress then
+ progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile)
+ end
+
+ local outputdir = compiler_support.get_outputdir(target, sourcefile)
+ local jsonfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".json"))
+ if depsformatflag and depsfileflag and depstargetflag 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})
+ os.vrunv(compinst:program(), flags)
+ os.rm(ifile)
+ os.rm(dfile)
+ else
+ fallback_generate_dependencies(target, jsonfile, sourcefile, function(file)
+ local compflags = compinst:compflags({sourcefile = file, target = target})
+ -- 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)
+ local content = io.readfile(ifile)
os.rm(ifile)
- os.rm(dfile)
- else
- fallback_generate_dependencies(target, jsonfile, sourcefile, function(file)
- local compflags = compinst:compflags({sourcefile = file, target = target})
- -- 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)
- local content = io.readfile(ifile)
- os.rm(ifile)
- return content
- end)
- end
- changed = true
+ return content
+ end)
+ end
+ changed = true
- local dependinfo = io.readfile(jsonfile)
- return { moduleinfo = dependinfo }
- end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt()})
- end
+ local dependinfo = io.readfile(jsonfile)
+ return { moduleinfo = dependinfo }
+ end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt()})
return changed
end
diff --git a/xmake/rules/c++/modules/modules_support/msvc/builder.lua b/xmake/rules/c++/modules/modules_support/msvc/builder.lua
index 7e147657e..019235837 100644
--- a/xmake/rules/c++/modules/modules_support/msvc/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc/builder.lua
@@ -32,67 +32,78 @@ import("compiler_support")
import(".builder", {inherit = true})
-- get flags for building a module
-function _make_modulebuildflags(target, provide, bmifile, sourcefile, objectfile, opt)
+function _make_modulebuildflags(target, provide, bmifile, opt)
local ifcoutputflag = compiler_support.get_ifcoutputflag(target)
local ifconlyflag = compiler_support.get_ifconlyflag(target)
local interfaceflag = compiler_support.get_interfaceflag(target)
local internalpartitionflag = compiler_support.get_internalpartitionflag(target)
- local objectfile_or_ifconlyflag = (opt.external and ifconlyflag) and ifconlyflag or "-Fo" .. objectfile
+ local ifconly = (opt.external and ifconlyflag)
local flags
if provide then -- named module
- flags = {"-TP", ifcoutputflag, bmifile, provide.interface and interfaceflag or internalpartitionflag, objectfile_or_ifconlyflag, "-c", sourcefile}
+ flags = table.join({"-TP", ifcoutputflag, bmifile, provide.interface and interfaceflag or internalpartitionflag}, ifconly or {})
else
- flags = {"-TP", objectfile_or_ifconlyflag, "-c", sourcefile}
+ flags = {"-TP"}
end
return flags
end
-- get flags for building a headerunit
-function _make_headerunitflags(target, headerunit, bmifile, opt)
+function _make_headerunitflags(target, headerunit, bmifile)
-- get flags
local exportheaderflag = compiler_support.get_exportheaderflag(target)
local headernameflag = compiler_support.get_headernameflag(target)
local ifcoutputflag = compiler_support.get_ifcoutputflag(target)
+ local ifconlyflag = compiler_support.get_ifconlyflag(target)
assert(headernameflag and exportheaderflag, "compiler(msvc): does not support c++ header units!")
local local_directory = (headerunit.type == ":quote") and {"-I" .. path.directory(headerunit.path)} or {}
local flags = table.join(local_directory, {"-TP",
exportheaderflag,
headernameflag .. headerunit.type,
+ headerunit.type == ":angle" and headerunit.name or headerunit.path,
ifcoutputflag,
- bmifile,
- headerunit.type == ":angle" and headerunit.name or headerunit.path})
+ bmifile}, ifconlyflag or {})
return flags
end
-- do compile
-function _compile(target, flags, sourcefile)
+function _compile(target, flags, sourcefile, outputfile, headerunit)
local dryrun = option.get("dry-run")
local compinst = target:compiler("cxx")
local compflags = compinst:compflags({sourcefile = sourcefile, target = target})
- local msvc = target:toolchain("msvc")
local flags = table.join(compflags or {}, flags)
-- trace
if option.get("verbose") then
- print(os.args(table.join(compinst:program(), flags)))
+ if headerunit then
+ print(os.args(compinst:program(), flags))
+ else
+ print(compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, rawargs = true}))
+ end
end
-- do compile
if not dryrun then
- os.vrunv(compinst:program(), flags, {envs = msvc:runenvs()})
+ if headerunit then
+ local msvc = target:toolchain("msvc")
+ os.vrunv(compinst:program(), flags, {envs = msvc:runenvs()})
+ else
+ assert(compinst:compile(sourcefile, outputfile, {target = target, compflags = flags}))
+ end
end
end
-- do compile for batchcmds
-- @note we need to use batchcmds:compilev to translate paths in compflags for generator, e.g. -Ixx
-function _batchcmds_compile(batchcmds, target, flags, sourcefile)
+function _batchcmds_compile(batchcmds, target, flags, sourcefile, outputfile)
+ opt = opt or {}
local compinst = target:compiler("cxx")
local compflags = compinst:compflags({sourcefile = sourcefile, target = target})
- batchcmds:compilev(table.join(compflags or {}, flags), {compiler = compinst, sourcekind = "cxx"})
+ flags = table.join("-c", compflags or {}, flags, {"/Fo", outputfile, sourcefile})
+ batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx"})
end
-- get module requires flags
@@ -234,9 +245,9 @@ function make_module_buildjobs(target, batchjobs, job_name, deps, opt)
local fileconfig = target:fileconfig(opt.cppfile)
local external = fileconfig and fileconfig.external
- local flags = _make_modulebuildflags(target, provide, bmifile, opt.cppfile, opt.objectfile, {external = external})
+ local flags = _make_modulebuildflags(target, provide, bmifile, {external = external})
- _compile(target, flags, opt.cppfile)
+ _compile(target, flags, opt.cppfile, opt.objectfile)
end
table.insert(dependinfo.files, opt.cppfile)
@@ -264,7 +275,7 @@ function make_module_buildcmds(target, batchcmds, opt)
local fileconfig = target:fileconfig(opt.cppfile)
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)
+ _batchcmds_compile(batchcmds, target, flags, opt.cppfile, objectfile)
end
end
batchcmds:add_depfiles(opt.cppfile)
@@ -295,7 +306,7 @@ function make_headerunit_buildjobs(target, job_name, batchjobs, headerunit, bmif
if opt.build then
progress.show((index * 100) / total, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:name(), headerunit.name)
- _compile(target, _make_headerunitflags(target, headerunit, bmifile, {}), name)
+ _compile(target, _make_headerunitflags(target, headerunit, bmifile), name, target:objectfile(headerunit.path), true)
end
table.insert(dependinfo.files, headerunit.path)
@@ -313,7 +324,7 @@ function make_headerunit_buildcmds(target, batchcmds, headerunit, bmifile, outpu
if opt.build then
local name = headerunit.unique and headerunit.name or headerunit.path
batchcmds:show_progress(opt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:name(), name)
- _batchcmds_compile(batchcmds, target, _make_headerunitflags(target, headerunit, bmifile, {batchcmds = true, bmifile = bmifile}))
+ _batchcmds_compile(batchcmds, target, _make_headerunitflags(target, headerunit, bmifile), target:objectfile(headerunit.path))
end
batchcmds:add_depfiles(headerunit.path)
return os.mtime(bmifile)
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 ed5027e22..90906fb0e 100644
--- a/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc/dependency_scanner.lua
@@ -29,44 +29,41 @@ import("builder")
import(".dependency_scanner", {inherit = true})
-- generate dependency files
-function generate_dependencies(target, sourcebatch, opt)
+function generate_dependency_for(target, sourcefile, opt)
local msvc = target:toolchain("msvc")
local scandependenciesflag = compiler_support.get_scandependenciesflag(target)
local ifcoutputflag = compiler_support.get_ifcoutputflag(target)
local common_flags = {"-TP", scandependenciesflag}
+ local dependfile = target:dependfile(sourcefile)
local changed = false
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- local dependfile = target:dependfile(sourcefile)
- depend.on_changed(function ()
- progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile)
- local outputdir = compiler_support.get_outputdir(target, sourcefile)
+ depend.on_changed(function ()
+ progress.show(opt.progress, "${color.build.target}<%s> generating.module.deps %s", target:name(), sourcefile)
+ local outputdir = compiler_support.get_outputdir(target, sourcefile)
- 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 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 compinst = target:compiler("cxx")
+ local compflags = table.join(compinst:compflags({sourcefile = sourcefile, target = target}) or {}, common_flags, 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 msvc = target:toolchain("msvc")
- local compflags = table.join(compinst:compflags({sourcefile = sourcefile, target = target}) or {}, common_flags, 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,
- {"/P", "-TP", file, "/Fi" .. ifile}), {envs = msvc:runenvs()})
- local content = io.readfile(ifile)
- os.rm(ifile)
- return content
- end)
- end
- changed = true
+ 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,
+ {"/P", "-TP", file, "/Fi" .. ifile}), {envs = msvc:runenvs()})
+ local content = io.readfile(ifile)
+ os.rm(ifile)
+ return content
+ end)
+ end
+ changed = true
- local dependinfo = io.readfile(jsonfile)
- return { moduleinfo = dependinfo }
- end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt()})
- end
+ local dependinfo = io.readfile(jsonfile)
+ return { moduleinfo = dependinfo }
+ end, {dependfile = dependfile, files = {sourcefile}, changed = target:is_rebuilt()})
return changed
end
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 13f248880..ecb79f65b 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -88,11 +88,11 @@ rule("c++.build.modules.builder")
end
end
+ opt.batchjobs = true
+
compiler_support.patch_sourcebatch(target, sourcebatch, opt)
local modules = dependency_scanner.get_module_dependencies(target, sourcebatch, opt)
- opt.batchjobs = true
-
-- build modules
builder.build_modules_for_batchjobs(target, batchjobs, sourcebatch, modules, opt)
@@ -135,11 +135,11 @@ rule("c++.build.modules.builder")
end
end
+ opt.batchjobs = false
+
compiler_support.patch_sourcebatch(target, sourcebatch, opt)
local modules = dependency_scanner.get_module_dependencies(target, sourcebatch, opt)
- opt.batchjobs = false
-
-- build headerunits
builder.build_headerunits_for_batchcmds(target, batchcmds, sourcebatch, modules, opt)