diff options
| author | ruki <[email protected]> | 2021-02-18 00:56:17 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-02-18 00:56:17 +0800 |
| commit | 4ba07e5ef5fc128d1ad9ef2227d1674a0a1d00c2 (patch) | |
| tree | b4c9ffbda7a5c75b3116543d86d357445c91313a | |
| parent | 7398de24ff14782768cbd72882aa18ebd36717ea (diff) | |
improve export_all rule
| -rw-r--r-- | xmake/rules/utils/symbols/export_all/export_all.lua | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/xmake/rules/utils/symbols/export_all/export_all.lua b/xmake/rules/utils/symbols/export_all/export_all.lua index 15566fa04..f0dbe3fc2 100644 --- a/xmake/rules/utils/symbols/export_all/export_all.lua +++ b/xmake/rules/utils/symbols/export_all/export_all.lua @@ -34,12 +34,10 @@ function main (target) 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") + -- get all symbols from object files + local allsymbols = {} for _, objectfile in ipairs(target:objectfiles()) do - local objectsymbols = os.iorunv(dumpbin.program, {"/symbols", "/nologo", objectfile}) + local objectsymbols = try { function () return os.iorunv(dumpbin.program, {"/symbols", "/nologo", objectfile}) end } if objectsymbols then for _, line in ipairs(objectsymbols:split('\n', {plain = true})) do -- 008 00000000 SECT3 notype () External | add @@ -47,12 +45,22 @@ function main (target) local symbol = line:match(".*External%s+| (.*)") if symbol then symbol = symbol:trim() - allsymbols_file:print("%s", symbol) + table.insert(allsymbols, symbol) end end end end end - allsymbols_file:close() - target:add("shflags", "/def:" .. allsymbols_filepath, {force = true}) + + -- export all symbols + if #allsymbols > 0 then + 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 _, symbol in ipairs(allsymbols) do + allsymbols_file:print("%s", symbol) + end + allsymbols_file:close() + target:add("shflags", "/def:" .. allsymbols_filepath, {force = true}) + end end |
