summaryrefslogtreecommitdiff
path: root/xmake/rules/utils
diff options
context:
space:
mode:
authorruki <[email protected]>2021-02-18 00:55:41 +0800
committerruki <[email protected]>2021-02-18 00:55:41 +0800
commit7398de24ff14782768cbd72882aa18ebd36717ea (patch)
treec7b5c1126c8d1e8927fef68155c3ddf524e7eb12 /xmake/rules/utils
parent46e0f6a1adda408052ba5b87c244cedaae5f1d00 (diff)
add export_all rule
Diffstat (limited to 'xmake/rules/utils')
-rw-r--r--xmake/rules/utils/symbols/export_all/export_all.lua30
1 files changed, 29 insertions, 1 deletions
diff --git a/xmake/rules/utils/symbols/export_all/export_all.lua b/xmake/rules/utils/symbols/export_all/export_all.lua
index 9d815090c..15566fa04 100644
--- a/xmake/rules/utils/symbols/export_all/export_all.lua
+++ b/xmake/rules/utils/symbols/export_all/export_all.lua
@@ -25,6 +25,34 @@ import("core.tool.toolchain")
-- export all symbols for dynamic library
function main (target)
-- @note it only supports windows/dll now
- assert(target:is_plat("windows") and target:kind() == "shared", 'rule("utils.symbols.export_all"): only support windows/dll now')
+ assert(target:kind() == "shared", 'rule("utils.symbols.export_all"): only for shared target!')
+ if not target:is_plat("windows") then
+ return
+ end
+ -- get dumpbin
+ local msvc = toolchain.load("msvc", {plat = target:plat(), arch = target:arch()})
+ local dumpbin = assert(find_tool("dumpbin", {envs = msvc:runenvs()}), "dumpbin not found!")
+
+ -- export all symbols
+ local allsymbols_filepath = path.join(target:autogendir(), "rules", "symbols", "export_all.def")
+ local allsymbols_file = io.open(allsymbols_filepath, 'w')
+ allsymbols_file:print("EXPORTS")
+ for _, objectfile in ipairs(target:objectfiles()) do
+ local objectsymbols = os.iorunv(dumpbin.program, {"/symbols", "/nologo", objectfile})
+ if objectsymbols then
+ for _, line in ipairs(objectsymbols:split('\n', {plain = true})) do
+ -- 008 00000000 SECT3 notype () External | add
+ if line:find("External") then
+ local symbol = line:match(".*External%s+| (.*)")
+ if symbol then
+ symbol = symbol:trim()
+ allsymbols_file:print("%s", symbol)
+ end
+ end
+ end
+ end
+ end
+ allsymbols_file:close()
+ target:add("shflags", "/def:" .. allsymbols_filepath, {force = true})
end