summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-04 22:44:24 +0800
committerruki <[email protected]>2022-08-04 22:44:24 +0800
commit78a52f5c6238dd163e90c2b8bb6f1fc82b0a86a7 (patch)
tree9691556825df5eb8ead972207db5ef3141c90b34
parent4e95000424f80810f2a7af5444a1a07c712057ff (diff)
fix module flags for msvc/clang
-rw-r--r--xmake/rules/c++/modules/modules_support/clang.lua79
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc.lua6
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc.lua15
3 files changed, 37 insertions, 63 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua
index b2425db71..6fc0e340a 100644
--- a/xmake/rules/c++/modules/modules_support/clang.lua
+++ b/xmake/rules/c++/modules/modules_support/clang.lua
@@ -29,7 +29,6 @@ import("common")
-- load module support for the current target
function load(target)
- local compinst = compiler.load("cxx", {target = target})
local cachedir = common.modules_cachedir(target)
local stlcachedir = common.stlmodules_cachedir(target)
@@ -55,15 +54,14 @@ function load(target)
end
end
+-- provide toolchain include dir for stl headerunit when p1689 is not supported
function toolchain_include_directories(target)
local includedirs = _g.includedirs
if includedirs == nil then
includedirs = {}
-
- local gcc, toolname = target:tool("cc")
- assert(toolname, "clang")
-
- local _, result = try {function () return os.iorunv(gcc, {"-E", "-Wp,-v", "-xc", os.nuldev()}) end}
+ local clang, toolname = target:tool("cc")
+ assert(toolname == "clang")
+ local _, result = try {function () return os.iorunv(clang, {"-E", "-Wp,-v", "-xc", os.nuldev()}) end}
if result then
for _, line in ipairs(result:split("\n", {plain = true})) do
line = line:trim()
@@ -75,14 +73,14 @@ function toolchain_include_directories(target)
end
end
end
- _g.includedirs = includedirs or {}
+ _g.includedirs = includedirs
end
return includedirs
end
+-- generate dependency files
function generate_dependencies(target, sourcebatch, opt)
local cachedir = common.modules_cachedir(target)
-
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
local dependfile = target:dependfile(sourcefile)
depend.on_changed(function()
@@ -93,13 +91,11 @@ function generate_dependencies(target, sourcebatch, opt)
os.mkdir(outdir)
end
- local jsonfile = path.translate(path.join(outdir, path.filename(sourcefile) .. ".json"))
-
-- no support of p1689 atm
+ local jsonfile = path.translate(path.join(outdir, path.filename(sourcefile) .. ".json"))
common.fallback_generate_dependencies(target, jsonfile, sourcefile)
local dependinfo = io.readfile(jsonfile)
-
return { moduleinfo = dependinfo }
end, {dependfile = dependfile, files = {sourcefile}})
end
@@ -110,7 +106,6 @@ function generate_headerunits(target, batchcmds, sourcebatch, opt)
local compinst = target:compiler("cxx")
local cachedir = common.modules_cachedir(target)
local stlcachedir = common.stlmodules_cachedir(target)
-
assert(has_headerunitsupport(target), "compiler(clang): does not support c++ header units!")
-- get headerunits flags
@@ -125,7 +120,6 @@ function generate_headerunits(target, batchcmds, sourcebatch, opt)
for _, headerunit in ipairs(sourcebatch) do
if not headerunit.stl then
local file = path.relative(headerunit.path, target:scriptdir())
-
local objectfile = target:objectfile(file)
local outdir
@@ -134,23 +128,21 @@ function generate_headerunits(target, batchcmds, sourcebatch, opt)
else
outdir = path.join(cachedir, path.directory(headerunit.path))
end
-
if not os.isdir(outdir) then
os.mkdir(outdir)
end
- local bmifilename = path.basename(objectfile) .. bmi_extension()
-
+ local bmifilename = path.basename(objectfile) .. get_bmi_extension()
local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename)
if not os.isdir(path.directory(objectfile)) then
os.mkdir(path.directory(objectfile))
end
- local args = { modulecachepathflag .. cachedir, emitmoduleflag, "-c", "-o", bmifile }
+ local args = { modulecachepathflag .. cachedir, emitmoduleflag, "-c", "-o", bmifile}
if headerunit.type == ":quote" then
- table.join2(args, { "-I", path.directory(headerunit.path), "-x", "c++-user-header", headerunit.path })
+ table.join2(args, {"-I", path.directory(headerunit.path), "-x", "c++-user-header", headerunit.path})
elseif headerunit.type == ":angle" then
- table.join2(args, { "-x", "c++-system-header", headerunit.name })
+ table.join2(args, {"-x", "c++-system-header", headerunit.name})
end
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
@@ -162,14 +154,11 @@ function generate_headerunits(target, batchcmds, sourcebatch, opt)
table.append(public_flags, modulefileflag .. bmifile)
else
- local bmifile = path.join(stlcachedir, headerunit.name .. bmi_extension())
-
+ local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension())
if not os.isfile(bmifile) then
- local args = { modulecachepathflag .. stlcachedir, "-c", "-o", bmifile, "-x", "c++-system-header", headerunit.path }
-
+ local args = {modulecachepathflag .. stlcachedir, "-c", "-o", bmifile, "-x", "c++-system-header", headerunit.path}
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args))
-
end
batchcmds:set_depmtime(os.mtime(bmifile))
@@ -199,17 +188,16 @@ function build_modules(target, batchcmds, objectfiles, modules, opt)
flags = table.unique(flags)
target:add("cxxflags", flags, {force = true, expand = false})
- local common_args = { modulecachepathflag .. cachedir }
+ local common_args = {modulecachepathflag .. cachedir}
for _, objectfile in ipairs(objectfiles) do
local m = modules[objectfile]
-
if m then
if not os.isdir(path.directory(objectfile)) then
os.mkdir(path.directory(objectfile))
end
local args = { emitmoduleinterfaceflag }
- local flag = {}
+ local bmiflags = {}
local bmifiles = {}
for name, provide in pairs(m.provides) do
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name)
@@ -222,7 +210,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt)
batchcmds:set_depmtime(os.mtime(bmifile))
batchcmds:set_depcache(target:dependfile(bmifile))
- table.join2(flag, { modulefileflag .. bmifile })
+ table.join2(bmiflags, {modulefileflag .. bmifile})
end
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args))
@@ -231,9 +219,9 @@ function build_modules(target, batchcmds, objectfiles, modules, opt)
batchcmds:set_depmtime(os.mtime(objectfile))
batchcmds:set_depcache(target:dependfile(objectfile))
- target:add("cxxflags", flag, {public = true, force = true})
+ target:add("cxxflags", bmiflags, {public = true, force = true})
target:add("objectfiles", objectfile)
- for _, f in ipairs(flag) do
+ for _, f in ipairs(bmiflags) do
target:data_add("cxx.modules.flags", f)
end
end
@@ -251,18 +239,15 @@ function get_modulesflag(target)
if compinst:has_flags("-fmodules", "cxxflags", {flagskey = "clang_modules"}) then
modulesflag = "-fmodules"
end
-
if not modulesflag then
if compinst:has_flags("-fmodules-ts", "cxxflags", {flagskey = "clang_modules_ts"}) then
modulesflag = "-fmodules-ts"
end
end
-
assert(modulesflag, "compiler(clang): does not support c++ module!")
-
_g.modulesflag = modulesflag or false
end
- return modulesflag
+ return modulesflag or nil
end
function get_implicitmodulesflag(target)
@@ -273,10 +258,9 @@ function get_implicitmodulesflag(target)
implicitmodulesflag = "-fimplicit-modules"
end
assert(implicitmodulesflag, "compiler(clang): does not support c++ module!")
-
_g.implicitmodulesflag = implicitmodulesflag or false
end
- return implicitmodulesflag
+ return implicitmodulesflag or nil
end
function get_implicitmodulemapsflag(target)
@@ -287,10 +271,9 @@ function get_implicitmodulemapsflag(target)
implicitmodulemapsflag = "-fimplicit-module-maps"
end
assert(implicitmodulemapsflag, "compiler(clang): does not support c++ module!")
-
_g.implicitmodulemapsflag = implicitmodulemapsflag or false
end
- return implicitmodulemapsflag
+ return implicitmodulemapsflag or nil
end
function get_prebuiltmodulepathflag(target)
@@ -301,10 +284,9 @@ function get_prebuiltmodulepathflag(target)
prebuiltmodulepathflag = "-fprebuilt-module-path="
end
assert(prebuiltmodulepathflag, "compiler(clang): does not support c++ module!")
-
_g.prebuiltmodulepathflag = prebuiltmodulepathflag or false
end
- return prebuiltmodulepathflag
+ return prebuiltmodulepathflag or nil
end
function get_modulecachepathflag(target)
@@ -315,10 +297,9 @@ function get_modulecachepathflag(target)
modulecachepathflag = "-fmodules-cache-path="
end
assert(modulecachepathflag, "compiler(clang): does not support c++ module!")
-
_g.modulecachepathflag = modulecachepathflag or false
end
- return modulecachepathflag
+ return modulecachepathflag or nil
end
function get_emitmoduleflag(target)
@@ -329,24 +310,22 @@ function get_emitmoduleflag(target)
emitmoduleflag = " -emit-module"
end
assert(emitmoduleflag, "compiler(clang): does not support c++ module!")
-
_g.emitmoduleflag = emitmoduleflag or false
end
- return emitmoduleflag
+ return emitmoduleflag or nil
end
function get_modulefileflag(target)
local modulefileflag = _g.modulefileflag
if modulefileflag == nil then
local compinst = target:compiler("cxx")
- if compinst:has_flags("-fmodule-file=" .. os.tmpfile() .. bmi_extension(), "cxxflags", {flagskey = "clang_module_file"}) then
+ if compinst:has_flags("-fmodule-file=" .. os.tmpfile() .. get_bmi_extension(), "cxxflags", {flagskey = "clang_module_file"}) then
modulefileflag = "-fmodule-file="
end
assert(modulefileflag, "compiler(clang): does not support c++ module!")
-
_g.modulefileflag = modulefileflag or false
end
- return modulefileflag
+ return modulefileflag or nil
end
function get_emitmoduleinterfaceflag(target)
@@ -357,10 +336,9 @@ function get_emitmoduleinterfaceflag(target)
emitmoduleinterfaceflag = "-emit-module-interface"
end
assert(emitmoduleinterfaceflag, "compiler(clang): does not support c++ module!")
-
_g.emitmoduleinterfaceflag = emitmoduleinterfaceflag or false
end
- return emitmoduleinterfaceflag
+ return emitmoduleinterfaceflag or nil
end
function has_headerunitsupport(target)
@@ -371,8 +349,7 @@ function has_headerunitsupport(target)
compinst:has_flags("-x c++-system-header", "cxxflags", {flagskey = "clang_system_header_unit_support"}) then
support_headerunits = true
end
-
_g.support_headerunits = support_headerunits or false
end
- return support_headerunits
+ return support_headerunits or nil
end
diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua
index e10bb0433..74e2a708e 100644
--- a/xmake/rules/c++/modules/modules_support/gcc.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc.lua
@@ -54,8 +54,6 @@ end
-- load module support for the current target
function load(target)
- local compinst = compiler.load("cxx", {target = target})
-
local modulesflag = get_modulesflag(target)
local modulemapperflag = get_modulemapperflag(target)
@@ -161,7 +159,7 @@ function generate_headerunits(target, batchcmds, sourcebatch, opt)
os.mkdir(outdir)
end
- local bmifilename = path.basename(objectfile) .. bmi_extension()
+ local bmifilename = path.basename(objectfile) .. get_bmi_extension()
local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename)
if not os.isdir(path.directory(objectfile)) then
@@ -186,7 +184,7 @@ function generate_headerunits(target, batchcmds, sourcebatch, opt)
batchcmds:set_depcache(target:dependfile(bmifile))
end
else
- local bmifile = path.join(stlcachedir, headerunit.name .. bmi_extension())
+ local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension())
if add_module_to_mapper(mapper_file, headerunit.path, path.absolute(bmifile, project.directory())) then
if not os.isfile(bmifile) then
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua
index fdaa27017..37428de7f 100644
--- a/xmake/rules/c++/modules/modules_support/msvc.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc.lua
@@ -28,7 +28,6 @@ import("common")
-- load module support for the current target
function load(target)
- local compinst = target:compiler("cxx")
local cachedir = common.modules_cachedir(target)
local stlcachedir = common.stlmodules_cachedir(target)
@@ -146,7 +145,7 @@ function generate_headerunits(target, batchcmds, sourcebatch, opt)
os.mkdir(outputdir)
end
- local bmifilename = path.basename(objectfile) .. bmi_extension()
+ local bmifilename = path.basename(objectfile) .. get_bmi_extension()
local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename)
if not os.isdir(path.directory(objectfile)) then
os.mkdir(path.directory(objectfile))
@@ -166,7 +165,7 @@ function generate_headerunits(target, batchcmds, sourcebatch, opt)
table.join2(public_flags, flag)
target:add("objectfiles", objectfile)
else
- local bmifile = path.join(stlcachedir, headerunit.name .. bmi_extension())
+ local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension())
local args = {exportheaderflag, headernameflag .. ":angle", headerunit.name, ifcoutputflag, stlcachedir}
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args), {envs = vcvars})
@@ -174,7 +173,7 @@ function generate_headerunits(target, batchcmds, sourcebatch, opt)
batchcmds:set_depmtime(os.mtime(bmifile))
batchcmds:set_depcache(target:dependfile(bmifile))
- local flag = {headerunitflag .. ":angle", headerunit.name .. "=" .. headerunit.name .. bmi_extension()}
+ local flag = {headerunitflag .. ":angle", headerunit.name .. "=" .. headerunit.name .. get_bmi_extension()}
table.join2(private_flags, flag)
end
end
@@ -209,7 +208,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt)
end
local args = {"/c", "/Fo" .. objectfile}
- local flag = {}
+ local bmiflags = {}
for name, provide in pairs(m.provides) do
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name)
@@ -220,7 +219,7 @@ function build_modules(target, batchcmds, objectfiles, modules, opt)
batchcmds:set_depmtime(os.mtime(bmifile))
batchcmds:set_depcache(target:dependfile(bmifile))
- flag = {referenceflag, name .. "=" .. path.filename(bmifile)}
+ table.join2(bmiflags, {referenceflag, name .. "=" .. path.filename(bmifile)})
end
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args, bmi_args), {envs = vcvars})
@@ -228,8 +227,8 @@ function build_modules(target, batchcmds, objectfiles, modules, opt)
batchcmds:set_depmtime(os.mtime(objectfile))
batchcmds:set_depcache(target:dependfile(objectfile))
- target:add("cxxflags", flag, {force = true, expand = false})
- for _, f in ipairs(flag) do
+ target:add("cxxflags", bmiflags, {force = true, expand = false})
+ for _, f in ipairs(bmiflags) do
target:data_add("cxx.modules.flags", f)
end
target:add("objectfiles", objectfile)