summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-10-24 22:53:05 +0800
committerruki <[email protected]>2023-10-24 22:53:05 +0800
commit66b43560f7cf25b20ecb78a85dc17fe1f975bb48 (patch)
tree52e461ab60c8c76d6b5a8ae8a379121991573df9
parent645d407a01aa69d35d5340c66f5e109583e4c427 (diff)
pass extras to tools
-rw-r--r--xmake/core/package/package.lua7
-rw-r--r--xmake/core/project/package.lua3
-rw-r--r--xmake/core/tool/builder.lua12
-rw-r--r--xmake/modules/core/tools/cl.lua12
-rw-r--r--xmake/modules/core/tools/clang_cl.lua6
-rw-r--r--xmake/modules/core/tools/dmd.lua4
-rw-r--r--xmake/modules/core/tools/gcc.lua36
-rw-r--r--xmake/modules/core/tools/go.lua5
-rw-r--r--xmake/modules/core/tools/ld.lua2
-rw-r--r--xmake/modules/core/tools/ldc2.lua4
-rw-r--r--xmake/modules/core/tools/link.lua6
-rw-r--r--xmake/modules/core/tools/ml.lua2
-rw-r--r--xmake/modules/core/tools/nim.lua6
-rw-r--r--xmake/modules/core/tools/nvcc.lua7
-rw-r--r--xmake/modules/core/tools/zig_cc.lua2
15 files changed, 76 insertions, 38 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 769551bcb..bbc303929 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -912,8 +912,11 @@ function _instance:manifest_save()
if value ~= nil then
vars = vars or {}
vars[name] = value
- extras = extras or {}
- extras[name] = self:extraconf(name)
+ local extra = self:extraconf(name)
+ if extra then
+ extras = extras or {}
+ extras[name] = extra
+ end
end
for _, component_name in ipairs(table.wrap(self:get("components"))) do
local comp = self:component(component_name)
diff --git a/xmake/core/project/package.lua b/xmake/core/project/package.lua
index cf372022f..63267a04e 100644
--- a/xmake/core/project/package.lua
+++ b/xmake/core/project/package.lua
@@ -206,6 +206,9 @@ function _instance:extraconf(name, item, key)
local value = extraconf
if item then
value = extraconf and extraconf[item] or nil
+ if value == nil and extraconf and type(item) == "table" then
+ value = extraconf[table.concat(item, "_")]
+ end
if value and key then
value = value[key]
end
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index dbd716082..a6cea93c0 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -281,6 +281,14 @@ function builder:_add_flags_from_argument(flags, target, args)
local extras = args.extras
self:_add_flags_from_language(flags, nil, {
target = function (name)
+ -- we need also to get extras from arguments
+ -- @see https://github.com/xmake-io/xmake/issues/4274
+ --
+ -- e.g.
+ -- package/add_linkgroups("xxx", {group = true})
+ -- {linkgroups = , extras = {
+ -- linkgroups = {z = {group = true}}
+ -- }}
return args[name], extras and extras[name]
end,
toolchain = function (name)
@@ -437,7 +445,7 @@ function builder:_add_flags_from_language(flags, target, getters)
local mapper = item.mapper
local extras = item.extras
if item.multival then
- local results = mapper(self:_tool(), item.values, target, self:_targetkind())
+ local results = mapper(self:_tool(), item.values, {target = target, targetkind = self:_targetkind(), extras = extras})
for _, flag in ipairs(table.wrap(results)) do
if flag and flag ~= "" and (not check or self:has_flags(flag)) then
table.insert(flags, flag)
@@ -445,7 +453,7 @@ function builder:_add_flags_from_language(flags, target, getters)
end
else
for _, flagvalue in ipairs(item.values) do
- local flag = mapper(self:_tool(), flagvalue, target, self:_targetkind())
+ local flag = mapper(self:_tool(), flagvalue, {target = target, targetkind = self:_targetkind(), extras = extras})
if flag and flag ~= "" and (not check or self:has_flags(flag)) then
table.insert(flags, flag)
end
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index 607f0f4d9..34927d179 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -88,7 +88,7 @@ function init(self)
end
-- make the symbol flags
-function nf_symbols(self, levels, target)
+function nf_symbols(self, levels, opt)
local flags = nil
local values = hashset.from(levels)
if values:has("debug") then
@@ -103,6 +103,7 @@ function nf_symbols(self, levels, target)
-- generate *.pdb file
local symbolfile = nil
+ local target = opt.target
if target and target.symbolfile and not values:has("embed") then
symbolfile = target:symbolfile()
end
@@ -296,7 +297,8 @@ function nf_includedir(self, dir)
end
-- make the force include flag
-function nf_forceinclude(self, headerfile, target)
+function nf_forceinclude(self, headerfile, opt)
+ local target = opt.target
local sourcekinds = target and target:extraconf("forceincludes", headerfile, "sourcekinds")
if not sourcekinds or table.contains(table.wrap(sourcekinds), self:kind()) then
return {"-FI", headerfile}
@@ -377,8 +379,9 @@ function nf_encoding(self, encoding)
end
-- make the c precompiled header flag
-function nf_pcheader(self, pcheaderfile, target)
+function nf_pcheader(self, pcheaderfile, opt)
if self:kind() == "cc" then
+ local target = opt.target
local objectfiles = target:objectfiles()
if objectfiles then
table.insert(objectfiles, target:pcoutputfile("c") .. ".obj")
@@ -388,8 +391,9 @@ function nf_pcheader(self, pcheaderfile, target)
end
-- make the c++ precompiled header flag
-function nf_pcxxheader(self, pcheaderfile, target)
+function nf_pcxxheader(self, pcheaderfile, opt)
if self:kind() == "cxx" then
+ local target = opt.target
local objectfiles = target:objectfiles()
if objectfiles then
table.insert(objectfiles, target:pcoutputfile("cxx") .. ".obj")
diff --git a/xmake/modules/core/tools/clang_cl.lua b/xmake/modules/core/tools/clang_cl.lua
index ee795e9d7..69459ad3e 100644
--- a/xmake/modules/core/tools/clang_cl.lua
+++ b/xmake/modules/core/tools/clang_cl.lua
@@ -105,7 +105,8 @@ function nf_optimize(self, level)
end
-- make the c precompiled header flag
-function nf_pcheader(self, pcheaderfile, target)
+function nf_pcheader(self, pcheaderfile, opt)
+ local target = opt.target
if self:kind() == "cc" then
local objectfiles = target:objectfiles()
if objectfiles then
@@ -119,7 +120,8 @@ function nf_pcheader(self, pcheaderfile, target)
end
-- make the c++ precompiled header flag
-function nf_pcxxheader(self, pcheaderfile, target)
+function nf_pcxxheader(self, pcheaderfile, opt)
+ local target = opt.target
if self:kind() == "cxx" then
local objectfiles = target:objectfiles()
if objectfiles then
diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua
index e02a1ed0a..8be22bf97 100644
--- a/xmake/modules/core/tools/dmd.lua
+++ b/xmake/modules/core/tools/dmd.lua
@@ -72,7 +72,7 @@ function nf_strip(self, level)
end
-- make the symbol flag
-function nf_symbol(self, level, target)
+function nf_symbol(self, level)
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
@@ -83,7 +83,7 @@ function nf_symbol(self, level, target)
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
- elseif (kind == "dcld" or kind == "dcsh") and target:is_plat("windows") and level == "debug" then
+ elseif (kind == "dcld" or kind == "dcsh") and self:is_plat("windows") and level == "debug" then
return "-g"
end
end
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 7d55c4fdc..ecc4eed98 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -81,7 +81,7 @@ function load(self)
end
-- make the strip flag
-function nf_strip(self, level, target)
+function nf_strip(self, level)
local maps = {
debug = "-Wl,-S"
, all = "-s"
@@ -283,7 +283,8 @@ function nf_sysincludedir(self, dir)
end
-- make the force include flag
-function nf_forceinclude(self, headerfile, target)
+function nf_forceinclude(self, headerfile, opt)
+ local target = opt.target
local sourcekinds = target and target:extraconf("forceincludes", headerfile, "sourcekinds")
if not sourcekinds or table.contains(table.wrap(sourcekinds), self:kind()) then
return {"-include", headerfile}
@@ -307,15 +308,24 @@ function nf_syslink(self, lib)
end
-- make the link group flag
-function nf_linkgroup(self, linkgroup, target)
+function nf_linkgroup(self, linkgroup, opt)
local linkflags = {}
for _, lib in ipairs(linkgroup) do
table.insert(linkflags, nf_link(self, lib))
end
local flags = {}
- if target and not self:is_plat("macosx", "windows", "mingw") then
- local group = target:extraconf("linkgroups", linkgroup, "group")
- local whole = target:extraconf("linkgroups", linkgroup, "whole")
+ local target = opt.target
+ local extras = opt.extras or target:extraconf("linkgroups")
+ if extras then
+ if type(linkgroup) == "table" then
+ extras = extras[table.concat(linkgroup, "_")]
+ else
+ extras = extras[linkgroup]
+ end
+ end
+ if extras and not self:is_plat("macosx", "windows", "mingw") then
+ local group = extras.group
+ local whole = extras.whole
if group and whole then
-- https://github.com/xmake-io/xmake/issues/4308
table.join2(flags, "-Wl,--whole-archive", "-Wl,--start-group", linkflags, "-Wl,--end-group", "-Wl,--no-whole-archive")
@@ -324,7 +334,7 @@ function nf_linkgroup(self, linkgroup, target)
elseif whole then
table.join2(flags, "-Wl,--whole-archive", linkflags, "-Wl,--no-whole-archive")
end
- local static = target:extraconf("linkgroups", linkgroup, "static")
+ local static = extras.static
if static then
table.join2(flags, "-Wl,-Bstatic", linkflags, "-Wl,-Bdynamic")
end
@@ -416,8 +426,9 @@ function nf_encoding(self, encoding)
end
-- make the c precompiled header flag
-function nf_pcheader(self, pcheaderfile, target)
+function nf_pcheader(self, pcheaderfile, opt)
if self:kind() == "cc" then
+ local target = opt.target
local pcoutputfile = target:pcoutputfile("c")
if self:name() == "clang" then
return {"-include", pcheaderfile, "-include-pch", pcoutputfile}
@@ -428,8 +439,9 @@ function nf_pcheader(self, pcheaderfile, target)
end
-- make the c++ precompiled header flag
-function nf_pcxxheader(self, pcheaderfile, target)
+function nf_pcxxheader(self, pcheaderfile, opt)
if self:kind() == "cxx" then
+ local target = opt.target
local pcoutputfile = target:pcoutputfile("cxx")
if self:name() == "clang" then
return {"-include", pcheaderfile, "-include-pch", pcoutputfile}
@@ -440,8 +452,9 @@ function nf_pcxxheader(self, pcheaderfile, target)
end
-- make the objc precompiled header flag
-function nf_pmheader(self, pcheaderfile, target)
+function nf_pmheader(self, pcheaderfile, opt)
if self:kind() == "mm" then
+ local target = opt.target
local pcoutputfile = target:pcoutputfile("m")
if self:name() == "clang" then
return {"-include", pcheaderfile, "-include-pch", pcoutputfile}
@@ -452,8 +465,9 @@ function nf_pmheader(self, pcheaderfile, target)
end
-- make the objc++ precompiled header flag
-function nf_pmxxheader(self, pcheaderfile, target)
+function nf_pmxxheader(self, pcheaderfile, opt)
if self:kind() == "mxx" then
+ local target = opt.target
local pcoutputfile = target:pcoutputfile("mxx")
if self:name() == "clang" then
return {"-include", pcheaderfile, "-include-pch", pcoutputfile}
diff --git a/xmake/modules/core/tools/go.lua b/xmake/modules/core/tools/go.lua
index 51f5709af..e7d660d75 100644
--- a/xmake/modules/core/tools/go.lua
+++ b/xmake/modules/core/tools/go.lua
@@ -42,8 +42,9 @@ function nf_optimize(self, level)
end
-- make the symbol flag
-function nf_symbol(self, level, target, mapkind)
- if mapkind ~= "object" then
+function nf_symbol(self, level, opt)
+ local targetkind = opt.targetkind
+ if targetkind ~= "object" then
return
end
local maps = {
diff --git a/xmake/modules/core/tools/ld.lua b/xmake/modules/core/tools/ld.lua
index e933a847c..29917f70e 100644
--- a/xmake/modules/core/tools/ld.lua
+++ b/xmake/modules/core/tools/ld.lua
@@ -38,7 +38,7 @@ function init(self)
end
-- make the strip flag
-function nf_strip(self, level, target)
+function nf_strip(self, level)
local maps = {
debug = "-S"
, all = "-s"
diff --git a/xmake/modules/core/tools/ldc2.lua b/xmake/modules/core/tools/ldc2.lua
index 5a9f77026..49a1c451e 100644
--- a/xmake/modules/core/tools/ldc2.lua
+++ b/xmake/modules/core/tools/ldc2.lua
@@ -49,7 +49,7 @@ function nf_optimize(self, level)
end
-- make the symbol flag
-function nf_symbol(self, level, target)
+function nf_symbol(self, level)
local kind = self:kind()
if language.sourcekinds()[kind] then
local maps = _g.symbol_maps
@@ -61,7 +61,7 @@ function nf_symbol(self, level, target)
_g.symbol_maps = maps
end
return maps[level .. '_' .. kind] or maps[level]
- elseif (kind == "dcld" or kind == "dcsh") and target:is_plat("windows") and level == "debug" then
+ elseif (kind == "dcld" or kind == "dcsh") and self:is_plat("windows") and level == "debug" then
return "-g"
end
end
diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua
index ee68cf01f..9c53c2e28 100644
--- a/xmake/modules/core/tools/link.lua
+++ b/xmake/modules/core/tools/link.lua
@@ -58,9 +58,10 @@ function get(self, name)
end
-- make the strip flag
-function nf_strip(self, level, target)
+function nf_strip(self, level, opt)
-- link.exe/arm64 does not support /opt:ref, /opt:icf
+ local target = opt.target
if target and target:is_arch("arm64") then
return
end
@@ -80,10 +81,11 @@ function nf_strip(self, level, target)
end
-- make the symbol flag
-function nf_symbol(self, level, target)
+function nf_symbol(self, level, opt)
-- debug? generate *.pdb file
local flags = nil
+ local target = opt.target
if target then
if target:type() == "target" then
if level == "debug" and (target:is_binary() or target:is_shared()) then
diff --git a/xmake/modules/core/tools/ml.lua b/xmake/modules/core/tools/ml.lua
index 042937ed7..5bb1fb884 100644
--- a/xmake/modules/core/tools/ml.lua
+++ b/xmake/modules/core/tools/ml.lua
@@ -55,7 +55,7 @@ function init(self)
end
-- make the symbol flags
-function nf_symbols(self, levels, target)
+function nf_symbols(self, levels)
local flags = nil
local values = hashset.from(levels)
if values:has("debug") then
diff --git a/xmake/modules/core/tools/nim.lua b/xmake/modules/core/tools/nim.lua
index 13d8fb3d6..b765f01f6 100644
--- a/xmake/modules/core/tools/nim.lua
+++ b/xmake/modules/core/tools/nim.lua
@@ -89,7 +89,7 @@ function nf_symbol(self, level)
end
-- make the strip flag
-function nf_strip(self, level, target)
+function nf_strip(self, level)
if self:is_plat("linux", "macosx", "bsd") then
if level == "debug" or level == "all" then
return "--passL:-s"
@@ -103,7 +103,7 @@ function nf_includedir(self, dir)
end
-- make the link flag
-function nf_link(self, lib, target)
+function nf_link(self, lib)
if self:is_plat("windows") then
return "--passL:" .. lib .. ".lib"
else
@@ -112,7 +112,7 @@ function nf_link(self, lib, target)
end
-- make the linkdir flag
-function nf_linkdir(self, dir, target)
+function nf_linkdir(self, dir)
if self:is_plat("windows") then
return {"--passL:-libpath:" .. path.translate(dir)}
else
diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua
index 038e2e75a..7050f86af 100644
--- a/xmake/modules/core/tools/nvcc.lua
+++ b/xmake/modules/core/tools/nvcc.lua
@@ -53,7 +53,7 @@ function init(self)
end
-- make the symbol flag
-function nf_symbol(self, level, target)
+function nf_symbol(self, level, opt)
-- debug? generate *.pdb file
local flags = nil
@@ -62,6 +62,7 @@ function nf_symbol(self, level, target)
if self:is_plat("windows") then
local host_flags = nil
local symbolfile = nil
+ local target = opt.target
if target and target.symbolfile then
symbolfile = target:symbolfile()
end
@@ -259,12 +260,12 @@ function nf_rpathdir(self, dir)
end
-- make the c precompiled header flag
-function nf_pcheader(self, pcheaderfile, target)
+function nf_pcheader(self, pcheaderfile)
return {"-include", pcheaderfile}
end
-- make the c++ precompiled header flag
-function nf_pcxxheader(self, pcheaderfile, target)
+function nf_pcxxheader(self, pcheaderfile)
return {"-include", pcheaderfile}
end
diff --git a/xmake/modules/core/tools/zig_cc.lua b/xmake/modules/core/tools/zig_cc.lua
index 8fefb0f97..205ecddfe 100644
--- a/xmake/modules/core/tools/zig_cc.lua
+++ b/xmake/modules/core/tools/zig_cc.lua
@@ -22,7 +22,7 @@
inherit("gcc")
-- make the strip flag
-function nf_strip(self, level, target)
+function nf_strip(self, level)
local maps = {
debug = "-Wl,-S"
, all = "-s"