summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Rendina <[email protected]>2025-04-15 11:39:17 +0200
committerChristian Rendina <[email protected]>2025-04-15 11:39:17 +0200
commitd6e95742d7674ccab1e73d204c11619159fa0c4b (patch)
treea6030df93730e566da969ca5e50eeaaef5bec31b
parente865a0206e1c57e0f34c473b4616304f6b44d377 (diff)
parent52950c684c10690a9db791e4919760316cce26e6 (diff)
Merge branch 'dev' of https://github.com/xmake-io/xmake into dev
-rw-r--r--tests/projects/c++/modules/hello_with_pch/test.lua1
-rw-r--r--tests/projects/c++/modules/test_pch.lua31
-rw-r--r--xmake/core/base/option.lua4
-rw-r--r--xmake/core/tool/tool.lua8
-rw-r--r--xmake/modules/core/project/depend.lua4
-rw-r--r--xmake/modules/core/tools/gcc.lua41
-rw-r--r--xmake/modules/package/tools/autoconf.lua2
-rw-r--r--xmake/modules/utils/archive/extract.lua37
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua11
-rw-r--r--xmake/rules/c++/modules/modules_support/builder.lua11
-rw-r--r--xmake/rules/c++/modules/modules_support/clang/builder.lua8
-rw-r--r--xmake/rules/c++/modules/modules_support/compiler_support.lua9
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc/builder.lua14
13 files changed, 81 insertions, 100 deletions
diff --git a/tests/projects/c++/modules/hello_with_pch/test.lua b/tests/projects/c++/modules/hello_with_pch/test.lua
new file mode 100644
index 000000000..7717f8049
--- /dev/null
+++ b/tests/projects/c++/modules/hello_with_pch/test.lua
@@ -0,0 +1 @@
+inherit(".test_base")
diff --git a/tests/projects/c++/modules/test_pch.lua b/tests/projects/c++/modules/test_pch.lua
deleted file mode 100644
index 98286c229..000000000
--- a/tests/projects/c++/modules/test_pch.lua
+++ /dev/null
@@ -1,31 +0,0 @@
-import("lib.detect.find_tool")
-import("core.base.semver")
-import("detect.sdks.find_vstudio")
-import("utils.ci.is_running", {alias = "ci_is_running"})
-
-function _build()
- if ci_is_running() then
- os.run("xmake -rvD")
- else
- os.run("xmake -r")
- end
- local outdata = os.iorun("xmake")
- if outdata then
- if outdata:find("compiling") or outdata:find("linking") or outdata:find("generating") then
- raise("Modules incremental compilation does not work\n%s", outdata)
- end
- end
-end
-
-function main(t)
- -- TODO c++ modules with pch does not work for gcc now.
- if is_host("linux") then
- local clang = find_tool("clang", {version = true})
- if clang then
- os.exec("xmake f --toolchain=clang -c --yes --policies=build.c++.modules.std:n,build.c++.clang.fallbackscanner")
- _build()
- end
- else
- _build()
- end
-end
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index 62551dda3..240e35bc4 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -478,7 +478,7 @@ function option.show_logo(logo, opt)
/_/\_\_|_| |_|\__ \|_|\_\____|
by ruki, xmake.io
- ]]
+]]
-- make rainbow for logo
opt = opt or {}
@@ -505,7 +505,7 @@ function option.show_logo(logo, opt)
local footer = [[
${point_right} ${bright}Manual${clear}: ${underline}https://xmake.io/#/getting_started${clear}
${pray} ${bright}Donate${clear}: ${underline}https://xmake.io/#/sponsor${clear}
- ]]
+]]
-- show footer
io.print(colors.translate(footer))
diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua
index 9022880a4..468b22579 100644
--- a/xmake/core/tool/tool.lua
+++ b/xmake/core/tool/tool.lua
@@ -40,14 +40,12 @@ local import = require("sandbox/modules/import")
function _instance.new(kind, name, program, plat, arch, toolchain_inst)
-- import "core.tools.xxx"
- local toolclass = nil
- if os.isfile(path.join(os.programdir(), "modules", "core", "tools", name .. ".lua")) then
- toolclass = import("core.tools." .. name, {nocache = true}) -- @note we need to create a tool instance with unique toolclass context (_g)
- end
+ -- @note we need to create a tool instance with unique toolclass context (_g)
+ local toolclass = import("core.tools." .. name, {try = true, nocache = true})
-- not found?
if not toolclass then
- return nil, string.format("cannot import \"core.tool.%s\" module!", name)
+ return nil, string.format("cannot import \"core.tools.%s\" module!", name)
end
-- new an instance
diff --git a/xmake/modules/core/project/depend.lua b/xmake/modules/core/project/depend.lua
index 05b93acf1..ca213d975 100644
--- a/xmake/modules/core/project/depend.lua
+++ b/xmake/modules/core/project/depend.lua
@@ -70,6 +70,8 @@ end
-- show diagnosis info?
function _is_show_diagnosis_info()
+ return true
+ --[[
local show = _g.is_show_diagnosis_info
if show == nil then
if project.policy("diagnosis.check_build_deps") then
@@ -79,7 +81,7 @@ function _is_show_diagnosis_info()
end
_g.is_show_diagnosis_info = show
end
- return show
+ return show]]
end
-- save dependent info to file
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 059eb5977..3de17be4a 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -31,6 +31,7 @@ import("core.language.language")
import("utils.progress")
import("private.cache.build_cache")
import("private.service.distcc_build.client", {alias = "distcc_build_client"})
+import("rules.c++.modules.modules_support.compiler_support", {rootdir = os.programdir()})
function init(self)
@@ -864,24 +865,35 @@ function _compile(self, sourcefile, objectfile, compflags, opt)
end
end
--- make the compile arguments list for the precompiled header
-function _compargv_pch(self, pcheaderfile, pcoutputfile, flags, opt)
-
- -- remove "-include xxx.h" and "-include-pch xxx.pch"
- local pchflags = {}
+-- remove "-include xxx.h" and "-include-pch xxx.pch"
+function _remove_flags_for_pch(self, flags, opt)
+ opt = opt or {}
+ local result = {}
local include = false
+ local pchfile = opt.pchfile
for _, flag in ipairs(flags) do
+ local inserted = false
if not flag:startswith("-include") then
if not include then
- table.insert(pchflags, flag)
+ inserted = true
end
include = false
else
include = true
end
+ if pchfile and flag:startswith("-fmodules") then
+ inserted = false
+ end
+ if inserted then
+ table.insert(result, flag)
+ end
end
+ return result
+end
- -- set the language of precompiled header?
+-- make the compile arguments list for the precompiled header
+function _translate_flags_for_pch(self, flags)
+ local pchflags = _remove_flags_for_pch(self, flags, {pchfile = true})
if self:kind() == "cxx" then
table.insert(pchflags, "-x")
table.insert(pchflags, "c++-header")
@@ -895,19 +907,24 @@ function _compargv_pch(self, pcheaderfile, pcoutputfile, flags, opt)
table.insert(pchflags, "-x")
table.insert(pchflags, "objective-c-header")
end
+ return pchflags
+end
- -- make the compile arguments list
- local argv = table.join("-c", pchflags, "-o", pcoutputfile, pcheaderfile)
- return self:program(), argv
+-- remove the force includes for c++modules
+-- @see https://github.com/xmake-io/xmake/issues/4051#issuecomment-2795707800
+function _translate_flags_for_mpp(self, flags)
+ return _remove_flags_for_pch(self, flags)
end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags, opt)
- -- precompiled header?
+ -- is precompiled header or module files? remove the force includes.
local extension = path.extension(sourcefile)
if (extension:startswith(".h") or extension == ".inl") then
- return _compargv_pch(self, sourcefile, objectfile, flags, opt)
+ flags = _translate_flags_for_pch(self, flags)
+ elseif compiler_support.has_module_extension(sourcefile, {extension = extension}) then
+ flags = _translate_flags_for_mpp(self, flags)
end
local argv = table.join("-c", flags, "-o", objectfile, sourcefile)
diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua
index 821ab759f..5a287045f 100644
--- a/xmake/modules/package/tools/autoconf.lua
+++ b/xmake/modules/package/tools/autoconf.lua
@@ -362,7 +362,7 @@ function buildenvs(package, opt)
end
if ldflags or shflags then
-- autoconf does not use SHFLAGS
- envs.LDFLAGS = table.concat(_translate_paths(table.join(ldflags or {}, shflags)), ' ')
+ envs.LDFLAGS = table.concat(table.reverse_unique(_translate_paths(table.join(ldflags or {}, shflags))), ' ')
end
-- cross-compilation? pass the full build environments
diff --git a/xmake/modules/utils/archive/extract.lua b/xmake/modules/utils/archive/extract.lua
index edf75eaf8..65d846413 100644
--- a/xmake/modules/utils/archive/extract.lua
+++ b/xmake/modules/utils/archive/extract.lua
@@ -166,9 +166,7 @@ function _extract_using_7z(archivefile, outputdir, extension, opt)
-- https://github.com/xmake-io/xmake-repo/pull/2673
os.tryrm(path.join(outputdir, "*.paxheader"))
end
-
- _extract_uncompressed_tar(outputdir_old, outputdir, opt)
- return true
+ return _extract_uncompressed_tar(outputdir_old, outputdir, opt)
end
-- extract archivefile using gzip
@@ -210,9 +208,7 @@ function _extract_using_gzip(archivefile, outputdir, extension, opt)
-- extract it
os.vrunv(program, argv, {curdir = outputdir})
-
- _extract_uncompressed_tar(outputdir_old, outputdir, opt)
- return true
+ return _extract_uncompressed_tar(outputdir_old, outputdir, opt)
end
-- extract archivefile using xz
@@ -254,9 +250,7 @@ function _extract_using_xz(archivefile, outputdir, extension, opt)
-- extract it
os.vrunv(program, argv, {curdir = outputdir})
-
- _extract_uncompressed_tar(outputdir_old, outputdir, opt)
- return true
+ return _extract_uncompressed_tar(outputdir_old, outputdir, opt)
end
-- extract archivefile using zstd
@@ -298,9 +292,7 @@ function _extract_using_zstd(archivefile, outputdir, extension, opt)
-- extract it
os.vrunv(program, argv, {curdir = outputdir})
-
- _extract_uncompressed_tar(outputdir_old, outputdir, opt)
- return true
+ return _extract_uncompressed_tar(outputdir_old, outputdir, opt)
end
-- extract archivefile using unzip
@@ -346,9 +338,7 @@ function _extract_using_unzip(archivefile, outputdir, extension, opt)
-- extract it
os.vrunv(program, argv)
-
- _extract_uncompressed_tar(outputdir_old, outputdir, opt)
- return true
+ return _extract_uncompressed_tar(outputdir_old, outputdir, opt)
end
-- extract archivefile using powershell
@@ -379,12 +369,9 @@ function _extract_using_powershell(archivefile, outputdir, extension, opt)
-- extract it
local argv = {"-ExecutionPolicy", "Bypass", "-File", scriptfile, archivefile, outputdir}
os.vrunv(powershell.program, argv)
-
- _extract_uncompressed_tar(outputdir_old, outputdir, opt)
- return true
+ return _extract_uncompressed_tar(outputdir_old, outputdir, opt)
end
-
-- extract archivefile using bzip2
function _extract_using_bzip2(archivefile, outputdir, extension, opt)
@@ -429,9 +416,7 @@ function _extract_using_bzip2(archivefile, outputdir, extension, opt)
-- extract it
os.vrunv(program, argv, {curdir = outputdir})
-
- _extract_uncompressed_tar(outputdir_old, outputdir, opt)
- return true
+ return _extract_uncompressed_tar(outputdir_old, outputdir, opt)
end
-- extract *.tar after decompress
@@ -439,9 +424,15 @@ function _extract_uncompressed_tar(outputdir_old, outputdir, opt)
if outputdir_old then
local tarfile = find_file("**.tar", outputdir)
if tarfile and os.isfile(tarfile) then
- return _extract(tarfile, outputdir_old, ".tar", {_extract_using_7z, _extract_using_tar}, opt)
+ local ok = _extract(tarfile, outputdir_old, ".tar", {_extract_using_7z, _extract_using_tar}, opt)
+ -- remove the temporary tar file
+ -- @see https://github.com/xmake-io/xmake/issues/6311
+ os.rm(tarfile)
+ os.rm(outputdir, {emptydirs = true})
+ return ok
end
end
+ return true
end
-- extract archive file using extractors
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index b69826694..9b0846930 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -30,6 +30,7 @@ import("detect.sdks.find_cuda")
import("vsfile")
import("vsutils")
import("private.utils.toolchain", {alias = "toolchain_utils"})
+import("rules.c++.modules.modules_support.compiler_support", {rootdir = os.programdir()})
function _make_dirs(dir, vcxprojdir)
dir = dir:trim()
@@ -132,12 +133,6 @@ function _split_gpucodes(flag)
return flag:split(",")
end
--- is module file?
-function _is_modulefile(sourcefile)
- local extension = path.extension(sourcefile)
- return extension == ".mpp" or extension == ".mxx" or extension == ".cppm" or extension == ".ixx"
-end
-
-- make compiling command
function _make_compcmd(compargv, sourcefile, objectfile, vcxprojdir)
local argv = {}
@@ -1179,7 +1174,7 @@ function _make_source_file_forall(vcxprojfile, vsinfo, target, sourcefile, sourc
else
-- compile as c++ modules
- if _is_modulefile(sourcefile) then
+ if compiler_support.has_module_extension(sourcefile) then
vcxprojfile:print("<CompileAs>CompileAsCppModule</CompileAs>")
end
@@ -1316,7 +1311,7 @@ function _make_source_file_forspec(vcxprojfile, vsinfo, target, sourcefile, sour
-- for *.c/cpp/cu files
else
-- compile as c++ modules
- if _is_modulefile(sourcefile) then
+ if compiler_support.has_module_extension(sourcefile) then
vcxprojfile:print("<CompileAs>CompileAsCppModule</CompileAs>")
end
diff --git a/xmake/rules/c++/modules/modules_support/builder.lua b/xmake/rules/c++/modules/modules_support/builder.lua
index 7ec120cc9..a02e1e7d3 100644
--- a/xmake/rules/c++/modules/modules_support/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/builder.lua
@@ -48,8 +48,9 @@ function _build_modules(target, sourcebatch, modules, opt)
-- we need to use the full path as dep name if requre item is headerunit
local dep = name
if req.method:startswith("include-") and req.path then
- dep = path.normalize(req.path)
+ dep = req.path
end
+ dep = path.normalize(dep)
local depname = target:fullname() .. "/module/" .. dep
table.insert(deps, depname)
end
@@ -279,7 +280,7 @@ function build_modules_for_batchjobs(target, batchjobs, sourcebatch, modules, op
-- add module jobs
_build_modules(target, sourcebatch, modules, table.join(opt, {
build_module = function(deps, module, name, objectfile, cppfile)
- local job_name = target:fullname() .. "/module/" .. (name or cppfile)
+ local job_name = target:fullname() .. "/module/" .. path.normalize(name or cppfile)
modulesjobs[job_name] = _builder(target).make_module_buildjobs(target, batchjobs, job_name, deps,
{module = module, objectfile = objectfile, cppfile = cppfile})
end
@@ -306,7 +307,7 @@ function build_modules_for_jobgraph(target, jobgraph, sourcebatch, modules, opt)
-- add module jobs
_build_modules(target, sourcebatch, modules, table.join(opt, {
build_module = function(deps, module, name, objectfile, cppfile)
- local jobname = target:fullname() .. "/module/" .. (name or cppfile)
+ local jobname = target:fullname() .. "/module/" .. path.normalize(name or cppfile)
_builder(target).make_module_jobgraph(target, jobgraph, {
module = module, objectfile = objectfile, cppfile = cppfile
})
@@ -355,7 +356,7 @@ function build_headerunits_for_batchjobs(target, batchjobs, sourcebatch, modules
local modulesjobs = {}
_build_headerunits(target, headerunits, table.join(opt, {
build_headerunit = function(headerunit, key, bmifile, outputdir, build)
- local job_name = target:fullname() .. "/module/" .. key
+ local job_name = target:fullname() .. "/module/" .. path.normalize(key)
local job = _builder(target).make_headerunit_buildjobs(target, job_name, batchjobs, headerunit, bmifile, outputdir, table.join(opt, {build = build}))
if job then
modulesjobs[job_name] = job
@@ -392,7 +393,7 @@ function build_headerunits_for_jobgraph(target, jobgraph, sourcebatch, modules,
local modulesjobs = {}
_build_headerunits(target, headerunits, table.join(opt, {
build_headerunit = function(headerunit, key, bmifile, outputdir, build)
- local job_name = target:fullname() .. "/module/" .. key
+ local job_name = target:fullname() .. "/module/" .. path.normalize(key)
_builder(target).make_headerunit_jobgraph(target,
job_name, jobgraph, headerunit, bmifile, outputdir, table.join(opt, {build = build}))
end
diff --git a/xmake/rules/c++/modules/modules_support/clang/builder.lua b/xmake/rules/c++/modules/modules_support/clang/builder.lua
index ec6692c35..420d1f0ee 100644
--- a/xmake/rules/c++/modules/modules_support/clang/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/clang/builder.lua
@@ -409,7 +409,8 @@ function make_headerunit_buildjobs(target, job_name, batchjobs, headerunit, bmif
local depvalues = {compinst:program(), compflags}
if opt.build then
- progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), headerunit.name)
+ progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s",
+ target:fullname(), headerunit.name)
_compile(target, _make_headerunitflags(target, headerunit, bmifile), headerunit.path, bmifile)
end
@@ -457,8 +458,9 @@ function make_headerunit_buildcmds(target, batchcmds, headerunit, bmifile, outpu
add_headerunit_to_target_mapper(target, headerunit, bmifile)
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:fullname(), name)
+ local headerfile = 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:fullname(), headerfile)
_batchcmds_compile(batchcmds, target, _make_headerunitflags(target, headerunit, bmifile), bmifile)
end
batchcmds:add_depfiles(headerunit.path)
diff --git a/xmake/rules/c++/modules/modules_support/compiler_support.lua b/xmake/rules/c++/modules/modules_support/compiler_support.lua
index eed30a320..fea294ad8 100644
--- a/xmake/rules/c++/modules/modules_support/compiler_support.lua
+++ b/xmake/rules/c++/modules/modules_support/compiler_support.lua
@@ -82,13 +82,14 @@ function get_bmi_path(bmifile)
end
-- has module extension? e.g. *.mpp, ...
-function has_module_extension(sourcefile)
+function has_module_extension(sourcefile, opt)
+ opt = opt or {}
local modulexts = _g.modulexts
if modulexts == nil then
modulexts = hashset.of(".mpp", ".mxx", ".cppm", ".ixx")
_g.modulexts = modulexts
end
- local extension = path.extension(sourcefile)
+ local extension = opt.extension or path.extension(sourcefile)
return modulexts:has(extension:lower())
end
@@ -133,7 +134,7 @@ end
function find_quote_header_file(target, sourcefile, file)
local p = path.join(path.directory(path.absolute(sourcefile, project.directory())), file)
- assert(os.isfile(p))
+ assert(os.isfile(p), "\"%s\" not found", p)
return p
end
@@ -149,7 +150,7 @@ function find_angle_header_file(target, file)
end
table.join2(headerpaths, target:get("includedirs"))
local p = find_file(file, headerpaths)
- assert(p, "find <%s> not found!", file)
+ assert(p, "<%s> not found!", file)
return p
end
diff --git a/xmake/rules/c++/modules/modules_support/gcc/builder.lua b/xmake/rules/c++/modules/modules_support/gcc/builder.lua
index 4033eefd5..1f909623f 100644
--- a/xmake/rules/c++/modules/modules_support/gcc/builder.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc/builder.lua
@@ -387,9 +387,10 @@ function make_headerunit_buildjobs(target, job_name, batchjobs, headerunit, bmif
if option.get("diagnosis") then
print("mapper file:\n%s", io.readfile(headerunit_mapper))
end
+ local headerfile = headerunit.unique and headerunit.name or headerunit.path
_compile(target,
_make_headerunitflags(target, headerunit, headerunit_mapper, opt),
- path.translate(path.filename(headerunit.name)), bmifile)
+ path.translate(headerfile), bmifile)
os.tryrm(headerunit_mapper)
end
@@ -421,13 +422,15 @@ function make_headerunit_jobgraph(target, job_name, jobgraph, headerunit, bmifil
if opt.build then
local headerunit_mapper = _generate_headerunit_modulemapper_file({name = path.normalize(headerunit.path), bmifile = bmifile})
- progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s", target:fullname(), headerunit.name)
+ progress.show(jobopt.progress, "${color.build.target}<%s> ${clear}${color.build.object}compiling.headerunit.$(mode) %s",
+ target:fullname(), headerunit.name)
if option.get("diagnosis") then
print("mapper file:\n%s", io.readfile(headerunit_mapper))
end
+ local headerfile = headerunit.unique and headerunit.name or headerunit.path
_compile(target,
_make_headerunitflags(target, headerunit, headerunit_mapper, opt),
- path.translate(path.filename(headerunit.name)), bmifile)
+ path.translate(headerfile), bmifile)
os.tryrm(headerunit_mapper)
end
@@ -450,8 +453,9 @@ function make_headerunit_buildcmds(target, batchcmds, headerunit, bmifile, outpu
add_headerunit_to_target_mapper(target, _headerunit, bmifile)
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:fullname(), name)
+ local headerfile = 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:fullname(), headerfile)
if option.get("diagnosis") then
batchcmds:print("mapper file:\n%s", io.readfile(headerunit_mapper))
end