diff options
| author | ruki <[email protected]> | 2025-10-10 12:00:39 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-10-10 12:00:39 +0800 |
| commit | 64112b9b62e9cbd29eaddce61ba5436910a83757 (patch) | |
| tree | 40c93927765514ed36b167b13d7c1e3aa55306c8 | |
| parent | 3a2c66848cab8f59b9c96b777ceadde7064cd38d (diff) | |
| parent | 264268baebd5a138734798e0f6e2afd171f9adae (diff) | |
Merge pull request #6915 from xmake-io/export
improve to export def rules for binary
| -rw-r--r-- | xmake/rules/platform/windows/def/xmake.lua | 39 | ||||
| -rw-r--r-- | xmake/rules/utils/symbols/export_list/xmake.lua | 11 |
2 files changed, 29 insertions, 21 deletions
diff --git a/xmake/rules/platform/windows/def/xmake.lua b/xmake/rules/platform/windows/def/xmake.lua index 08279d90a..f7bd66ab2 100644 --- a/xmake/rules/platform/windows/def/xmake.lua +++ b/xmake/rules/platform/windows/def/xmake.lua @@ -22,28 +22,27 @@ rule("platform.windows.def") set_extensions(".def") on_config("windows", "mingw", function (target) - if not target:is_shared() then - return - end - - if target:is_plat("windows") and (not target:has_tool("sh", "link", "clangxx")) then - return - end - - local sourcebatch = target:sourcebatches()["platform.windows.def"] - if sourcebatch then - for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - local flag = path.translate(sourcefile) - if target:is_plat("windows") then - flag = "/def:" .. flag - if target:has_tool("sh", "clangxx") then - flag = "-Wl," .. flag + if target:is_plat("windows") and (target:is_shared() or target:is_binary()) then + local sourcebatch = target:sourcebatches()["platform.windows.def"] + if sourcebatch then + -- https://github.com/xmake-io/xmake/pull/4901 + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local matched = false + local flag = path.translate(sourcefile) + if target:has_tool("ld", "link") then + flag = "/def:" .. flag + matched = true + elseif target:has_tool("ld", "clangxx") then + flag = "-Wl,/def:" .. flag + matched = true + end + if matched then + target:add("shflags", flag, {force = true}) + target:add("ldflags", flag, {force = true}) + target:data_add("linkdepfiles", sourcefile) end + break end - -- https://github.com/xmake-io/xmake/pull/4901 - target:add("shflags", flag, {force = true}) - target:data_add("linkdepfiles", sourcefile) - break; end end end) diff --git a/xmake/rules/utils/symbols/export_list/xmake.lua b/xmake/rules/utils/symbols/export_list/xmake.lua index 00a697e09..bd37af477 100644 --- a/xmake/rules/utils/symbols/export_list/xmake.lua +++ b/xmake/rules/utils/symbols/export_list/xmake.lua @@ -37,7 +37,8 @@ rule("utils.symbols.export_list") set_extensions(".export.txt") on_config(function (target) - assert(target:is_shared(), 'rule("utils.symbols.export_list"): only for shared target(%s)!', target:name()) + assert(target:is_shared() or (target:is_plat("windows") and target:is_binary()), + 'rule("utils.symbols.export_list"): only for binary/shared target(%s)!', target:fullname()) local exportfile local exportkind local exportsymbols = target:extraconf("rules", "utils.symbols.export_list", "symbols") @@ -60,6 +61,7 @@ rule("utils.symbols.export_list") exportkind = "def" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.def") target:add("shflags", "-L/def:" .. exportfile, {force = true}) + target:add("ldflags", "-L/def:" .. exportfile, {force = true}) elseif target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then exportkind = "apple" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.exp") @@ -73,6 +75,12 @@ rule("utils.symbols.export_list") exportkind = "def" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.def") target:add("shflags", "/def:" .. exportfile, {force = true}) + target:add("ldflags", "/def:" .. exportfile, {force = true}) + elseif target:is_plat("windows") and target:has_tool("ld", "clangxx") then + exportkind = "def" + exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.def") + target:add("shflags", "-Wl,/def:" .. exportfile, {force = true}) + target:add("ldflags", "-Wl,/def:" .. exportfile, {force = true}) elseif target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then exportkind = "apple" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.exp") @@ -88,6 +96,7 @@ rule("utils.symbols.export_list") target:add("shflags", "--version-script=" .. exportfile, {force = true}) end if exportfile and exportkind then + target:data_add("linkdepfiles", exportfile) if exportkind == "ver" then io.writefile(exportfile, ([[{ global: |
