summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-02-18 22:34:44 +0800
committerruki <[email protected]>2021-02-18 22:34:44 +0800
commitfc17860c4d3998b781e09d318db9a3dc19b59a18 (patch)
tree4eecd64488260c95022da80e28132deef844672d
parent5cbd380893c53723521651e85c02c8926af7b038 (diff)
improve export all rule again
-rw-r--r--xmake/rules/utils/symbols/export_all/export_all.lua17
-rw-r--r--xmake/rules/utils/symbols/export_all/xmake.lua3
2 files changed, 13 insertions, 7 deletions
diff --git a/xmake/rules/utils/symbols/export_all/export_all.lua b/xmake/rules/utils/symbols/export_all/export_all.lua
index a4c88b0aa..ec6115142 100644
--- a/xmake/rules/utils/symbols/export_all/export_all.lua
+++ b/xmake/rules/utils/symbols/export_all/export_all.lua
@@ -22,6 +22,7 @@
import("lib.detect.find_tool")
import("core.tool.toolchain")
import("core.base.option")
+import("core.base.hashset")
import("core.project.depend")
import("private.utils.progress")
@@ -29,7 +30,7 @@ import("private.utils.progress")
function main (target, opt)
-- @note it only supports windows/dll now
- assert(target:kind() == "shared", 'rule("utils.symbols.export_all"): only for shared target!')
+ assert(target:kind() == "shared", 'rule("utils.symbols.export_all"): only for shared target(%s)!', target:name())
if not target:is_plat("windows") or option.get("dry-run") then
return
end
@@ -47,7 +48,7 @@ function main (target, opt)
local dumpbin = assert(find_tool("dumpbin", {envs = msvc:runenvs()}), "dumpbin not found!")
-- get all symbols from object files
- local allsymbols = {}
+ local allsymbols = hashset.new()
for _, objectfile in ipairs(target:objectfiles()) do
local objectsymbols = try { function () return os.iorunv(dumpbin.program, {"/symbols", "/nologo", objectfile}) end }
if objectsymbols then
@@ -56,8 +57,10 @@ function main (target, opt)
if line:find("External") then
local symbol = line:match(".*External%s+| (.*)")
if symbol then
- symbol = symbol:trim()
- table.insert(allsymbols, symbol)
+ symbol = symbol:split('%s')[1]
+ if not symbol:startswith("__") then
+ allsymbols:insert(symbol)
+ end
end
end
end
@@ -65,13 +68,15 @@ function main (target, opt)
end
-- export all symbols
- if #allsymbols > 0 then
+ if allsymbols:size() > 0 then
local allsymbols_file = io.open(allsymbols_filepath, 'w')
allsymbols_file:print("EXPORTS")
- for _, symbol in ipairs(allsymbols) do
+ for _, symbol in allsymbols:keys() do
allsymbols_file:print("%s", symbol)
end
allsymbols_file:close()
+ else
+ wprint('rule("utils.symbols.export_all"): no symbols are exported for target(%s)!', target:name())
end
end, {dependfile = dependfile, files = target:objectfiles()})
diff --git a/xmake/rules/utils/symbols/export_all/xmake.lua b/xmake/rules/utils/symbols/export_all/xmake.lua
index b8de669c0..9d766356e 100644
--- a/xmake/rules/utils/symbols/export_all/xmake.lua
+++ b/xmake/rules/utils/symbols/export_all/xmake.lua
@@ -28,8 +28,9 @@
rule("utils.symbols.export_all")
before_load(function (target)
-- @note it only supports windows/dll now
- assert(target:kind() == "shared", 'rule("utils.symbols.export_all"): only for shared target!')
+ assert(target:kind() == "shared", 'rule("utils.symbols.export_all"): only for shared target(%s)!', target:name())
if target:is_plat("windows") then
+ assert(target:get("optimize") ~= "smallest", 'rule("utils.symbols.export_all"): does not support set_optimize("smallest") for target(%s)!', target:name())
local allsymbols_filepath = path.join(target:autogendir(), "rules", "symbols", "export_all.def")
target:add("shflags", "/def:" .. allsymbols_filepath, {force = true})
end