summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-01-28 00:37:26 +0800
committerruki <[email protected]>2022-01-28 00:37:26 +0800
commit3230c26a0602865f0c59624955b89443cbbfc6bc (patch)
tree3bd22b37b1cdb267dfda70a18c44d26793edffc9
parent1d36f008c9a75a0a2ac20100f4b173a0d6977e24 (diff)
improve merge staticlib for android/win
-rw-r--r--xmake/modules/utils/archive/merge_staticlib.lua10
1 files changed, 9 insertions, 1 deletions
diff --git a/xmake/modules/utils/archive/merge_staticlib.lua b/xmake/modules/utils/archive/merge_staticlib.lua
index dc0130219..fb9c65c06 100644
--- a/xmake/modules/utils/archive/merge_staticlib.lua
+++ b/xmake/modules/utils/archive/merge_staticlib.lua
@@ -28,9 +28,15 @@ function _merge_for_ar(target, program, outputfile, libraryfiles, opt)
if target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then
os.vrunv("libtool", table.join("-static", "-o", outputfile, libraryfiles))
else
+ -- we can't generate directly to outputfile,
+ -- because on windows/ndk, llvm-ar.exe may fail to write with no permission, even though it's a writable temp file.
+ --
+ -- @see https://github.com/xmake-io/xmake/issues/1973
+ local archivefile = target:autogenfile((hash.uuid(outputfile):gsub("%-", ""))) .. ".a"
+ os.mkdir(path.directory(archivefile))
local tmpfile = os.tmpfile()
local mrifile = io.open(tmpfile, "w")
- mrifile:print("create %s", outputfile)
+ mrifile:print("create %s", archivefile)
for _, libraryfile in ipairs(libraryfiles) do
mrifile:print("addlib %s", libraryfile)
end
@@ -38,7 +44,9 @@ function _merge_for_ar(target, program, outputfile, libraryfiles, opt)
mrifile:print("end")
mrifile:close()
os.vrunv(program, {"-M"}, {stdin = tmpfile})
+ os.cp(archivefile, outputfile)
os.rm(tmpfile)
+ os.rm(archivefile)
end
end