summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2024-05-19 23:15:53 +0800
committerruki <[email protected]>2024-05-19 23:15:53 +0800
commitdad8fe9b2acda84bfbead2a05a8b0d4b504d6479 (patch)
tree610cc5fb68689e2ab35fec5d61330ec9d6f159cb /xmake
parent1dee088e701ace1ea4cdfe904a152caddfc55f42 (diff)
add export filter
Diffstat (limited to 'xmake')
-rw-r--r--xmake/rules/utils/symbols/export_all/export_all.lua25
1 files changed, 21 insertions, 4 deletions
diff --git a/xmake/rules/utils/symbols/export_all/export_all.lua b/xmake/rules/utils/symbols/export_all/export_all.lua
index 4842546f3..9376e557e 100644
--- a/xmake/rules/utils/symbols/export_all/export_all.lua
+++ b/xmake/rules/utils/symbols/export_all/export_all.lua
@@ -31,6 +31,7 @@ function _get_allsymbols_by_dumpbin(target, dumpbin, opt)
opt = opt or {}
local allsymbols = hashset.new()
local export_classes = opt.export_classes
+ local export_filter = opt.export_filter
for _, objectfile in ipairs(target:objectfiles()) do
local objectsymbols = try { function () return os.iorunv(dumpbin, {"/symbols", "/nologo", objectfile}) end }
if objectsymbols then
@@ -41,7 +42,11 @@ function _get_allsymbols_by_dumpbin(target, dumpbin, opt)
local symbol = line:match(".*External%s+| (.*)")
if symbol then
symbol = symbol:split('%s')[1]
- if not symbol:startswith("__") then
+ if export_filter then
+ if export_filter(symbol) then
+ allsymbols:insert(symbol)
+ end
+ elseif not symbol:startswith("__") then
-- we need ignore DllMain, https://github.com/xmake-io/xmake/issues/3992
if target:is_arch("x86") and symbol:startswith("_") and not symbol:startswith("_DllMain@") then
symbol = symbol:sub(2)
@@ -69,6 +74,7 @@ function _get_allsymbols_by_objdump(target, objdump, opt)
opt = opt or {}
local allsymbols = hashset.new()
local export_classes = opt.export_classes
+ local export_filter = opt.export_filter
for _, objectfile in ipairs(target:objectfiles()) do
local objectsymbols = try { function () return os.iorunv(objdump, {"--syms", objectfile}) end }
if objectsymbols then
@@ -77,7 +83,11 @@ function _get_allsymbols_by_objdump(target, objdump, opt)
local splitinfo = line:split("%s")
local symbol = splitinfo[#splitinfo]
if symbol then
- if not symbol:startswith("__") then
+ if export_filter then
+ if export_filter(symbol) then
+ allsymbols:insert(symbol)
+ end
+ elseif not symbol:startswith("__") then
-- we need ignore DllMain, https://github.com/xmake-io/xmake/issues/3992
if target:is_arch("x86") and symbol:startswith("_") and not symbol:startswith("_DllMain@") then
symbol = symbol:sub(2)
@@ -120,15 +130,22 @@ function main(target, opt)
-- export c++ class?
local export_classes = target:extraconf("rules", "utils.symbols.export_all", "export_classes")
+ -- the export filter
+ local export_filter = target:extraconf("rules", "utils.symbols.export_all", "export_filter")
+
-- get all symbols
local allsymbols
local msvc = toolchain.load("msvc", {plat = target:plat(), arch = target:arch()})
if msvc:check() then
local dumpbin = assert(find_tool("dumpbin", {envs = msvc:runenvs()}), "dumpbin not found!")
- allsymbols = _get_allsymbols_by_dumpbin(target, dumpbin.program, {export_classes = export_classes})
+ allsymbols = _get_allsymbols_by_dumpbin(target, dumpbin.program, {
+ export_classes = export_classes,
+ export_filter = export_filter})
elseif target:has_tool("cc", "clang", "clang_cl", "clangxx", "gcc", "gxx") then
local objdump = assert(find_tool("llvm-objdump") or find_tool("objdump"), "objdump not found!")
- allsymbols = _get_allsymbols_by_objdump(target, objdump.program, {export_classes = export_classes})
+ allsymbols = _get_allsymbols_by_objdump(target, objdump.program, {
+ export_classes = export_classes,
+ export_filter = export_filter})
end
-- export all symbols