From cd2be29f2bfc8e5bc85767b9ab182d3712e11532 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 22 Jan 2023 21:53:53 +0100 Subject: improve module compilation on gcc --- xmake/rules/c++/modules/modules_support/gcc.lua | 64 +++++++++---------------- 1 file changed, 23 insertions(+), 41 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/gcc.lua') diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 07b4d130b..722706603 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -74,7 +74,7 @@ function load(target) end target:add("cxxflags", {modulesflag, modulemapperflag .. path.translate(_get_module_mapper(target))}, {force = true, expand = false}) -- fix cxxabi issue, @see https://github.com/xmake-io/xmake/issues/2716#issuecomment-1225057760 - target:add("cxxflags", "-D_GLIBCXX_USE_CXX11_ABI=0") + -- target:add("cxxflags", "-D_GLIBCXX_USE_CXX11_ABI=0") end -- get includedirs for stl headers @@ -170,7 +170,6 @@ end -- generate dependency files function generate_dependencies(target, sourcebatch, opt) - local cachedir = common.modules_cachedir(target) local compinst = target:compiler("cxx") local common_args = {"-E", "-x", "c++"} local depformatflag = get_depflag(target, "p1689r5") or get_depflag(target, "trtbd") @@ -184,11 +183,7 @@ function generate_dependencies(target, sourcebatch, opt) progress.show(opt.progress, "${color.build.object}generating.module.deps %s", sourcefile) end - local outputdir = path.translate(path.join(cachedir, path.directory(path.relative(sourcefile, projectdir)))) - if not os.isdir(outputdir) then - os.mkdir(outputdir) - end - + local outputdir = common.get_outputdir(target, sourcefile) local jsonfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".json")) if depformatflag and depfileflag and depoutputflag and not target:policy("build.c++.gcc.fallbackscanner") then local ifile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".i")) @@ -206,9 +201,14 @@ function generate_dependencies(target, sourcebatch, opt) local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = file, target = target}) local flags = {} + local next_flag = false for _, flag in ipairs(compflags) do - if flag:startswith("-std") or (flag:startswith("-f") and not flag:startswith("-fmodules")) or flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") then + if flag == "-m64" or flag == "-g" or flag:startswith("-m") or flag:startswith("-std") or (flag:startswith("-f") and not flag:startswith("-fmodule")) or flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") or next_flag then table.insert(flags, flag) + next_flag = false + if flag:startswith("-isystem") then + next_flag = true + end end end local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) @@ -292,28 +292,21 @@ end function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits, opt) local compinst = target:compiler("cxx") local mapper_file = _get_module_mapper(target) - local cachedir = common.modules_cachedir(target) -- build headerunits local projectdir = os.projectdir() for _, headerunit in ipairs(headerunits) do - local file = path.relative(headerunit.path, projectdir) - local objectfile = target:objectfile(file) - local outputdir local headerunit_path - if headerunit.type == ":quote" then - outputdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir))) - else - outputdir = path.join(cachedir, path.directory(headerunit.path)) - end - local bmifilename = path.basename(objectfile) .. get_bmi_extension() - local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) if headerunit.type == ":quote" then headerunit_path = path.join(".", path.relative(headerunit.path, projectdir)) elseif headerunit.type == ":angle" then -- if path is relative then its a subtarget path headerunit_path = path.is_absolute(headerunit.path) and headerunit.path or path.join(".", headerunit.path) end + local objectfile = target:objectfile(headerunit_path) + local outputdir = common.get_outputdir(target, headerunit.path) + local bmifilename = path.basename(objectfile) .. get_bmi_extension() + local bmifile = path.join(outputdir, bmifilename) batchjobs:addjob(headerunit.name, function (index, total) depend.on_changed(function() progress.show((index * 100) / total, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) @@ -321,9 +314,6 @@ function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits, if not os.isdir(objectdir) then os.mkdir(objectdir) end - if not os.isdir(outputdir) then - os.mkdir(outputdir) - end -- generate headerunit local args = { "-c" } @@ -343,28 +333,13 @@ end -- generate target user header units for batchcmds function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits, opt) local mapper_file = _get_module_mapper(target) - local cachedir = common.modules_cachedir(target) -- build headerunits local projectdir = os.projectdir() local depmtime = 0 for _, headerunit in ipairs(headerunits) do - local file = path.relative(headerunit.path, projectdir) - local objectfile = target:objectfile(file) - local outputdir - if headerunit.type == ":quote" then - outputdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir))) - else - outputdir = path.join(cachedir, path.directory(headerunit.path)) - end - batchcmds:mkdir(outputdir) - - local bmifilename = path.basename(objectfile) .. get_bmi_extension() - local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) - batchcmds:mkdir(path.directory(objectfile)) - - local flags = {"-c"} local headerunit_path + local flags = {"-c"} if headerunit.type == ":quote" then table.join2(flags, {"-I", path(path.relative(headerunit.path, projectdir)):directory(), "-x", "c++-user-header", headerunit.name}) headerunit_path = path.join(".", path.relative(headerunit.path, projectdir)) @@ -373,6 +348,14 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits, -- if path is relative then its a subtarget path headerunit_path = path.is_absolute(headerunit.path) and headerunit.path or path.join(".", headerunit.path) end + local objectfile = target:objectfile(headerunit_path) + local outputdir = common.get_outputdir(target, headerunit.path) + batchcmds:mkdir(outputdir) + + local bmifilename = path.basename(objectfile) .. get_bmi_extension() + local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) + batchcmds:mkdir(path.directory(objectfile)) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) _batchcmds_compile(batchcmds, target, flags) @@ -417,8 +400,8 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op local fileconfig = target:fileconfig(cppfile) if fileconfig and fileconfig.install then batchjobs:addjob(name .. "_metafile", function(index, total) - local cachedir = common.modules_cachedir(target) - local metafilepath = path.join(cachedir, path.filename(cppfile) .. ".meta-info") + local outputdir = common.get_outputdir(target, cppfile) + local metafilepath = path.join(outputdir, path.filename(cppfile) .. ".meta-info") depend.on_changed(function() progress.show(opt.progress, "${color.build.object}generating.module.metadata %s", name) local metadata = common.generate_meta_module_info(target, name, cppfile, module.requires) @@ -477,7 +460,6 @@ end -- build module files for batchcmds function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, opt) - local modulemapperflag = get_modulemapperflag(target) local mapper_file = _get_module_mapper(target) -- build modules -- cgit v1.3.1 From e5709e2df72b30201941670a5b9d23f8ea1fc251 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 22 Jan 2023 22:02:20 +0100 Subject: revert wrong change --- xmake/rules/c++/modules/modules_support/gcc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xmake/rules/c++/modules/modules_support/gcc.lua') diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 722706603..ee3f547bd 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -74,7 +74,7 @@ function load(target) end target:add("cxxflags", {modulesflag, modulemapperflag .. path.translate(_get_module_mapper(target))}, {force = true, expand = false}) -- fix cxxabi issue, @see https://github.com/xmake-io/xmake/issues/2716#issuecomment-1225057760 - -- target:add("cxxflags", "-D_GLIBCXX_USE_CXX11_ABI=0") + target:add("cxxflags", "-D_GLIBCXX_USE_CXX11_ABI=0") end -- get includedirs for stl headers -- cgit v1.3.1 From acedc8854cdf5e59915bfcf6fc1e979b91ff4d6b Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Mon, 23 Jan 2023 11:58:45 +0100 Subject: format --- xmake/rules/c++/modules/modules_support/clang.lua | 6 ++++-- xmake/rules/c++/modules/modules_support/gcc.lua | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/gcc.lua') diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index e84848cc3..b341df0d4 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -274,8 +274,10 @@ function generate_dependencies(target, sourcebatch, opt) local compflags = compinst:compflags({sourcefile = file, target = target}) local flags = {} local next_flag = false - for _, flag in pairs(compflags) do - if flag == "-m64" or flag == "-g" or flag:startswith("-stdlib") or flag:startswith("-m") or (flag:startswith("-f") and not flag:startswith("-fmodule") and not flag:startswith("-fno-implicit-module-maps")) or flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") or next_flag then + for _, flag in ipairs(compflags) do + if flag == "-m64" or flag == "-g" or flag:startswith("-stdlib") or flag:startswith("-m") or + (flag:startswith("-f") and not flag:startswith("-fmodule") and not flag:startswith("-fno-implicit-module-maps")) or + flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") or next_flag then table.insert(flags, flag) next_flag = false if flag:startswith("-isystem") then diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index ee3f547bd..3ab790daf 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -203,7 +203,9 @@ function generate_dependencies(target, sourcebatch, opt) local flags = {} local next_flag = false for _, flag in ipairs(compflags) do - if flag == "-m64" or flag == "-g" or flag:startswith("-m") or flag:startswith("-std") or (flag:startswith("-f") and not flag:startswith("-fmodule")) or flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") or next_flag then + if flag == "-m64" or flag == "-g" or flag:startswith("-m") or flag:startswith("-std") or + (flag:startswith("-f") and not flag:startswith("-fmodule")) or flag:startswith("-D") or + flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") or next_flag then table.insert(flags, flag) next_flag = false if flag:startswith("-isystem") then -- cgit v1.3.1 From 270b45e610c37472c3cb7a9c23cd3cf52e3f1232 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Mon, 23 Jan 2023 15:38:48 +0100 Subject: simplify fallback dependency parser --- xmake/rules/c++/modules/modules_support/clang.lua | 18 +++++------------- xmake/rules/c++/modules/modules_support/gcc.lua | 23 ++++++++--------------- 2 files changed, 13 insertions(+), 28 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/gcc.lua') diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index c88a844a8..aeb8ebd53 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -272,22 +272,14 @@ function generate_dependencies(target, sourcebatch, opt) common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = file, target = target}) - local flags = {} - local next_flag = false - for _, flag in ipairs(compflags) do - if flag == "-m64" or flag == "-g" or flag:startswith("-stdlib") or flag:startswith("-m") or - (flag:startswith("-f") and not flag:startswith("-fmodule") and not flag:startswith("-fno-implicit-module-maps")) or - flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") or next_flag or - flag:startswith("-iframework") then - table.insert(flags, flag) - next_flag = false - if flag:startswith("-isystem") then - next_flag = true - end + for i, flag in ipairs(compflags) do + -- 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 + if flag:startswith("-fmodule") or flag:startswith("-std=c++") or flag:startswith("-std=gnu++") then + table.remove(compflags, i) end end local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) - os.vrunv(compinst:program(), table.join(flags, {"-E", "-x", "c++", file, "-o", ifile})) + os.vrunv(compinst:program(), table.join(compflags, {"-E", "-x", "c++", file, "-o", ifile})) local content = io.readfile(ifile) os.rm(ifile) return content diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 3ab790daf..2864e41a4 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -200,21 +200,14 @@ function generate_dependencies(target, sourcebatch, opt) common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = file, target = target}) - local flags = {} - local next_flag = false - for _, flag in ipairs(compflags) do - if flag == "-m64" or flag == "-g" or flag:startswith("-m") or flag:startswith("-std") or - (flag:startswith("-f") and not flag:startswith("-fmodule")) or flag:startswith("-D") or - flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") or next_flag then - table.insert(flags, flag) - next_flag = false - if flag:startswith("-isystem") then - next_flag = true - end + for i, flag in ipairs(compflags) do + -- 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 + if flag:startswith("-fmodule") then + table.remove(compflags, i) end end local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) - os.vrunv(compinst:program(), table.join(common_args, flags, {file, "-o", ifile})) + os.vrunv(compinst:program(), table.join(common_args, compflags, {file, "-o", ifile})) local content = io.readfile(ifile) os.rm(ifile) return content @@ -340,8 +333,8 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits, local projectdir = os.projectdir() local depmtime = 0 for _, headerunit in ipairs(headerunits) do - local headerunit_path local flags = {"-c"} + local headerunit_path if headerunit.type == ":quote" then table.join2(flags, {"-I", path(path.relative(headerunit.path, projectdir)):directory(), "-x", "c++-user-header", headerunit.name}) headerunit_path = path.join(".", path.relative(headerunit.path, projectdir)) @@ -358,7 +351,6 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits, local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename) batchcmds:mkdir(path.directory(objectfile)) - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name) _batchcmds_compile(batchcmds, target, flags) batchcmds:add_depfiles(headerunit.path) @@ -405,7 +397,7 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op local outputdir = common.get_outputdir(target, cppfile) local metafilepath = path.join(outputdir, path.filename(cppfile) .. ".meta-info") depend.on_changed(function() - progress.show(opt.progress, "${color.build.object}generating.module.metadata %s", name) + progress.show((index * 100) / total, "${color.build.object}generating.module.metadata %s", name) local metadata = common.generate_meta_module_info(target, name, cppfile, module.requires) json.savefile(metafilepath, metadata) @@ -462,6 +454,7 @@ end -- build module files for batchcmds function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, opt) + local modulemapperflag = get_modulemapperflag(target) local mapper_file = _get_module_mapper(target) -- build modules -- cgit v1.3.1 From 924403375684235e1f34f3b6b2210cc5cda1feb5 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Tue, 24 Jan 2023 12:11:37 +0100 Subject: fix unsafe table remove --- xmake/rules/c++/modules/modules_support/clang.lua | 8 ++------ xmake/rules/c++/modules/modules_support/gcc.lua | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'xmake/rules/c++/modules/modules_support/gcc.lua') diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 17ce22659..320061e1a 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -271,12 +271,8 @@ function generate_dependencies(target, sourcebatch, opt) common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = file, target = target}) - for i, flag in ipairs(compflags) do - -- 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 - if flag:startswith("-fmodule") or flag:startswith("-std=c++") or flag:startswith("-std=gnu++") then - table.remove(compflags, i) - end - end + -- 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 + compflags = 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")) os.vrunv(compinst:program(), table.join(compflags, {"-E", "-x", "c++", file, "-o", ifile})) local content = io.readfile(ifile) diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 2864e41a4..eb83ed96d 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -200,12 +200,8 @@ function generate_dependencies(target, sourcebatch, opt) common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) local compinst = target:compiler("cxx") local compflags = compinst:compflags({sourcefile = file, target = target}) - for i, flag in ipairs(compflags) do - -- 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 - if flag:startswith("-fmodule") then - table.remove(compflags, i) - end - end + -- 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 + compflags = table.remove_if(compflags, function(_, flag) return flag:startswith("-fmodule") end) local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) os.vrunv(compinst:program(), table.join(common_args, compflags, {file, "-o", ifile})) local content = io.readfile(ifile) -- cgit v1.3.1