summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2024-02-01 16:48:11 +0100
committerArthur LAURENT <[email protected]>2024-02-01 16:51:17 +0100
commitb1005e8b51783d6ae0d997345dc365b7b6e3cbdf (patch)
tree3f8bc7e303ddecd74006e57d07b5ad903f8d8b34
parentc7a25377afc0c2f41c4e8946d767f0c0dff02d13 (diff)
use compinst:compile when possible
-rw-r--r--xmake/rules/c++/modules/modules_support/clang/builder.lua50
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc/builder.lua35
2 files changed, 36 insertions, 49 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua
index 0bc467730..64243fd3f 100644
--- a/xmake/rules/c++/modules/modules_support/clang/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua
@@ -37,16 +37,18 @@ function _make_modulebuildflags(target, provide, bmifile, opt)
local module_outputflag = compiler_support.get_moduleoutputflag(target)
local flags
+ local precompile = false
if module_outputflag and provide and not opt.external then -- one step compilation of named module, clang >= 16
- flags = {{"-x", "c++-module", module_outputflag .. bmifile, "-o", target:objectfile(opt.sourcefile), "-c", opt.sourcefile}}
+ flags = {{"-x", "c++-module", module_outputflag .. bmifile}}
elseif provide then -- two step compilation of named module
- flags = {{"-x", "c++-module", "--precompile", "-o", bmifile, "-c", opt.sourcefile}}
+ precompile = true
+ flags = {{"-x", "c++-module", "--precompile"}}
if not opt.external then
- table.insert(flags, {"-o", target:objectfile(opt.sourcefile), "-c", opt.sourcefile})
+ table.insert(flags, {})
end
else -- internal module, no bmi needed
- flags = {{"-x", "c++", "-o", target:objectfile(opt.sourcefile), "-c", opt.sourcefile}}
+ flags = {{"-x", "c++"}}
end
if opt.name == "std" or opt.name == "std.compat" then
@@ -56,7 +58,7 @@ function _make_modulebuildflags(target, provide, bmifile, opt)
end
end
- return table.unpack(flags)
+ return precompile, table.unpack(flags)
end
-- get flags for building a headerunit
@@ -69,41 +71,39 @@ function _make_headerunitflags(target, headerunit, bmifile)
local headertype = (headerunit.type == ":angle") and "system" or "user"
- local flags = table.join(local_directory, {"-xc++-header", "-Wno-everything", module_headerflag .. headertype, "-o", bmifile, "-c", headerunit.path})
+ local flags = table.join(local_directory, {"-xc++-header", "-Wno-everything", module_headerflag .. headertype})
return flags
end
-- do compile
-function _compile(target, flags, cppfile)
+function _compile(target, flags, sourcefile, outputfile, opt)
+ opt = opt or {}
local dryrun = option.get("dry-run")
local compinst = target:compiler("cxx")
- local compflags = compinst:compflags({sourcefile = cppfile, target = target})
- local msvc = target:toolchain("msvc")
+ local compflags = compinst:compflags({sourcefile = sourcefile, target = target})
local flags = table.join(compflags or {}, flags)
-- trace
if option.get("verbose") then
- print(os.args(table.join(compinst:program(), flags)))
+ print(compinst:compcmd(opt.bmifile or sourcefile, outputfile, {target = target, compflags = flags, rawargs = true}))
end
if not dryrun then
-- do compile
- if msvc then
- os.vrunv(compinst:program(), flags, {envs = msvc:runenvs()})
- else
- os.vrunv(compinst:program(), flags)
- end
+ assert(compinst:compile(opt.bmifile or sourcefile, outputfile, {target = target, compflags = flags}))
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 = 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"})
+ local flags = table.join("-c", compflags or {}, flags, {"-o", outputfile, opt.bmifile or sourcefile})
+ batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx"})
end
-- get module requires flags
@@ -241,12 +241,12 @@ function make_module_build_job(target, batchjobs, job_name, deps, opt)
local fileconfig = target:fileconfig(opt.cppfile)
local external = fileconfig and fileconfig.external
- local 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)
+ _compile(target, first_step, opt.cppfile, precompile and bmifile or opt.objectfile)
if second_step then
- _compile(target, second_step, opt.cppfile)
+ _compile(target, second_step, opt.cppfile, opt.objectfile, {bmifile = bmifile})
end
end
@@ -275,11 +275,11 @@ function make_module_build_cmds(target, batchcmds, opt)
local fileconfig = target:fileconfig(opt.cppfile)
local external = fileconfig and fileconfig.external
- local 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)
+ 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)
+ _batchcmds_compile(batchcmds, target, second_step, opt.cppfile, opt.objectfile, {bmifile = bmifile})
end
end
batchcmds:add_depfiles(opt.cppfile)
@@ -310,7 +310,7 @@ function make_headerunit_build_job(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), headerunit.path)
+ _compile(target, _make_headerunitflags(target, headerunit, bmifile), headerunit.path, bmifile)
end
table.insert(dependinfo.files, headerunit.path)
@@ -330,7 +330,7 @@ function make_headerunit_build_cmds(target, batchcmds, headerunit, bmifile, outp
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_compile(batchcmds, target, _make_headerunitflags(target, headerunit, bmifile), bmifile)
end
batchcmds:add_depfiles(headerunit.path)
return os.mtime(bmifile)
diff --git a/xmake/rules/c++/modules/modules_support/gcc/builder.lua b/xmake/rules/c++/modules/modules_support/gcc/builder.lua
index 1ad9b5f09..f0599c7f2 100644
--- a/xmake/rules/c++/modules/modules_support/gcc/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc/builder.lua
@@ -32,17 +32,11 @@ import(".builder", {inherit = true})
-- get flags for building a module
function _make_modulebuildflags(target, opt)
-
- local flags = {"-x", "c++", "-c"}
- if opt.batchcmds then
- table.join2(flags, "-o", target:objectfile(opt.sourcefile), opt.sourcefile)
- end
-
- return flags
+ return {"-x", "c++", "-c"}
end
-- get flags for building a headerunit
-function _make_headerunitflags(target, headerunit, headerunit_mapper, opt)
+function _make_headerunitflags(target, headerunit, headerunit_mapper)
-- get flags
local module_headerflag = compiler_support.get_moduleheaderflag(target)
@@ -55,14 +49,9 @@ function _make_headerunitflags(target, headerunit, headerunit_mapper, opt)
local headertype = (headerunit.type == ":angle") and "system" or "user"
local flags = table.join(local_directory, {module_mapperflag .. headerunit_mapper,
- module_headerflag .. headertype,
- module_onlyflag,
- "-xc++-header",
- "-c"})
- if opt.batchcmds then
- table.join2(flags, {"-o", opt.bmifile, path.filename(headerunit.path)})
- end
-
+ module_headerflag .. headertype,
+ module_onlyflag,
+ "-xc++-header"})
return flags
end
@@ -76,24 +65,22 @@ function _compile(target, flags, sourcefile, outputfile)
-- trace
if option.get("verbose") then
- print(compinst:compcmd(sourcefile, outputfile, {compflags = flags, rawargs = true}))
+ print(compinst:compcmd(sourcefile, outputfile, {target = target, compflags = flags, rawargs = true}))
end
-
if not dryrun then
-- do compile
- compinst:compile(sourcefile, outputfile, {compflags = flags})
+ assert(compinst:compile(sourcefile, outputfile, {target = target, compflags = flags}))
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)
local compinst = target:compiler("cxx")
local compflags = compinst:compflags({sourcefile = sourcefile, target = target})
- local flags = table.join(compflags or {}, flags)
-
+ local flags = table.join("-c", compflags or {}, flags, {"-o", outputfile, sourcefile})
batchcmds:compilev(flags, {compiler = compinst, sourcekind = "cxx"})
end
@@ -307,7 +294,7 @@ function make_module_build_cmds(target, batchcmds, opt)
end
batchcmds:mkdir(path.directory(opt.objectfile))
- _batchcmds_compile(batchcmds, target, _make_modulebuildflags(target, {batchcmds = true, sourcefile = opt.cppfile}), opt.cppfile)
+ _batchcmds_compile(batchcmds, target, _make_modulebuildflags(target, {batchcmds = true, sourcefile = opt.cppfile}), opt.cppfile, opt.objectfile)
end
end
@@ -373,7 +360,7 @@ function make_headerunit_build_cmds(target, batchcmds, headerunit, bmifile, outp
if option.get("diagnosis") then
batchcmds:print("mapper file:\n%s", io.readfile(headerunit_mapper))
end
- _batchcmds_compile(batchcmds, target, _make_headerunitflags(target, headerunit, headerunit_mapper, {batchcmds = true, bmifile = bmifile}))
+ _batchcmds_compile(batchcmds, target, _make_headerunitflags(target, headerunit, headerunit_mapper), bmifile)
end
batchcmds:rm(headerunit_mapper)