diff options
| author | ruki <[email protected]> | 2025-10-11 07:26:02 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-10-11 07:26:02 +0800 |
| commit | 29bdf3bfa87d6376aaf43693a548fcbd307455b7 (patch) | |
| tree | 3dc593706ddd8a0554a8f98db76bdc256d6b9d91 | |
| parent | a63ee6b38c5c079284b0da2d91cab4bda4b878ef (diff) | |
| parent | 98a47a1e2d0884adb2cdbe52c3a570b0c0e70022 (diff) | |
Merge pull request #6916 from xmake-io/implib
improve implib
| -rw-r--r-- | xmake/core/project/target.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/core/tools/link.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/utils/symbols/export_list/xmake.lua | 22 |
3 files changed, 26 insertions, 6 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 2f69abdd8..3f9e7b813 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1656,13 +1656,13 @@ end -- get the extra build artifact file -- -- supported artifact kinds: --- 1. implib: windows DLL implib(.lib, .dll.a) +-- 1. implib: windows DLL/EXE implib(.lib, .dll.a) -- -- otherwise returns nil -- function _instance:artifactfile(kind) if kind == "implib" then - if self:is_shared() and self:is_plat("windows", "mingw") then + if (self:is_shared() or self:is_binary()) and self:is_plat("windows", "mingw") then return path.join(self:_artifactdir("libdir"), path.basename(self:filename()) .. (self:is_plat("mingw") and ".dll.a" or ".lib")) end end diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index 246c0048b..9acd66706 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -141,10 +141,16 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) argv = winos.cmdargv(argv) end -- @note we cannot put -lib/-dll to @args.txt + local implib = false if targetkind == "static" then table.insert(argv, 1, "-lib") elseif targetkind == "shared" then table.insert(argv, 1, "-dll") + implib = true + elseif targetkind == "binary" then + implib = true + end + if implib then local implibfile = _get_implibfile(self, opt) if implibfile then table.insert(argv, "/implib:" .. implibfile) diff --git a/xmake/rules/utils/symbols/export_list/xmake.lua b/xmake/rules/utils/symbols/export_list/xmake.lua index bd37af477..5069274e2 100644 --- a/xmake/rules/utils/symbols/export_list/xmake.lua +++ b/xmake/rules/utils/symbols/export_list/xmake.lua @@ -96,9 +96,10 @@ rule("utils.symbols.export_list") target:add("shflags", "--version-script=" .. exportfile, {force = true}) end if exportfile and exportkind then - target:data_add("linkdepfiles", exportfile) + local exportfile_tmp = os.tmpfile(exportfile) + os.tryrm(exportfile_tmp) if exportkind == "ver" then - io.writefile(exportfile, ([[{ + io.writefile(exportfile_tmp, ([[{ global: %s @@ -106,7 +107,7 @@ rule("utils.symbols.export_list") *; };]]):format(table.concat(exportsymbols, ";\n ") .. ";")) elseif exportkind == "apple" then - local file = io.open(exportfile, 'w') + local file = io.open(exportfile_tmp, 'w') for _, symbol in ipairs(exportsymbols) do if not symbol:startswith("_") then symbol = "_" .. symbol @@ -115,13 +116,26 @@ rule("utils.symbols.export_list") end file:close() elseif exportkind == "def" then - local file = io.open(exportfile, 'w') + local file = io.open(exportfile_tmp, 'w') file:print("EXPORTS") for _, symbol in ipairs(exportsymbols) do file:print("%s", symbol) end file:close() end + + -- update file if the content is changed + target:data_add("linkdepfiles", exportfile) + if os.isfile(exportfile_tmp) then + if os.isfile(exportfile) then + if io.readfile(exportfile_tmp) ~= io.readfile(exportfile) then + os.cp(exportfile_tmp, exportfile) + end + else + os.cp(exportfile_tmp, exportfile) + end + end + target:data_add("linkdepfiles", exportfile) end end) |
