summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-23 09:36:29 +0800
committerGitHub <[email protected]>2022-08-23 09:36:29 +0800
commit006390def621247c8d3857495afaa4e7038a32fa (patch)
treeaa0bb46561ded824fd53999d0d6884fa803ba942
parent5a9631ba93e7a677a8c1e9769b17e392cdbb61af (diff)
parent2019daea91cb6ad5eda1a38fab3b515e261ea698 (diff)
Merge pull request #2707 from xmake-io/framework
improve frameworks
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/modules/core/tools/gcc.lua5
-rw-r--r--xmake/rules/xcode/application/build.lua35
-rw-r--r--xmake/rules/xcode/framework/xmake.lua7
4 files changed, 45 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index da3aef858..5eda9263f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@
* [#2614](https://github.com/xmake-io/xmake/issues/2614): Fix building submodules2 tests for msvc
* [#2620](https://github.com/xmake-io/xmake/issues/2620): Fix build cache for incremental compilation
* [#2177](https://github.com/xmake-io/xmake/issues/2177): Fix python.library segmentation fault for macosx
+* Fix rpath for macos/iphoneos frameworks and application
## v2.6.9
@@ -1387,6 +1388,7 @@
* [#2614](https://github.com/xmake-io/xmake/issues/2614): 为 msvc 修复构建 submodules2 测试工程
* [#2620](https://github.com/xmake-io/xmake/issues/2620): 修复构建缓存导致的增量编译问题
* [#2177](https://github.com/xmake-io/xmake/issues/2177): 修复 python.library 在 macOS 上段错误崩溃
+* 修复 ios/macOS framework 和 application 的 rpath 加载路径
## v2.6.9
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 4122c8ae8..7dfaab07f 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -350,13 +350,14 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
-- add rpath for dylib (macho), e.g. -install_name @rpath/file.dylib
local flags_extra = {}
- if targetkind == "shared" and is_plat("macosx", "iphoneos", "watchos") then
+ local plat = self:plat()
+ if targetkind == "shared" and (plat == "macosx" or plat == "iphoneos" or plat == "watchos") then
table.insert(flags_extra, "-install_name")
table.insert(flags_extra, "@rpath/" .. path.filename(targetfile))
end
-- add `-Wl,--out-implib,outputdir/libxxx.a` for xxx.dll on mingw/gcc
- if targetkind == "shared" and is_plat("mingw") then
+ if targetkind == "shared" and plat == "mingw" then
table.insert(flags_extra, "-Wl,--out-implib," .. path.join(path.directory(targetfile), path.basename(targetfile) .. ".dll.a"))
end
diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua
index a4862ae86..b39c3546e 100644
--- a/xmake/rules/xcode/application/build.lua
+++ b/xmake/rules/xcode/application/build.lua
@@ -25,6 +25,25 @@ import("core.project.depend")
import("private.tools.codesign")
import("utils.progress")
+-- copy frameworks with symlink
+--
+-- TODO we should improve os.cp to support for copying directory with symlink
+-- os.vcp(frameworkdir, frameworksdir, {symlink = true})
+function _copy_frameworks(frameworkdir, frameworksdir)
+ os.mkdir(frameworksdir)
+ local frameworkdir_dst = path.join(frameworksdir, path.filename(frameworkdir))
+ os.tryrm(frameworkdir_dst)
+ for _, filepath in ipairs(os.filedirs(path.join(frameworkdir, "*"))) do
+ if path.filename(filepath) == "Versions" then
+ _copy_frameworks(filepath, frameworkdir_dst)
+ else
+ local dstpath = path.join(frameworkdir_dst, path.filename(filepath))
+ os.tryrm(dstpath)
+ os.cp(filepath, dstpath, {symlink = true})
+ end
+ end
+end
+
-- main entry
function main (target, opt)
@@ -32,6 +51,7 @@ function main (target, opt)
local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
local contentsdir = path.absolute(target:data("xcode.bundle.contentsdir"))
local resourcesdir = path.absolute(target:data("xcode.bundle.resourcesdir"))
+ local frameworksdir = path.join(contentsdir, "Frameworks")
-- do build if changed
depend.on_changed(function ()
@@ -46,10 +66,21 @@ function main (target, opt)
end
os.vcp(target:targetfile(), path.join(binarydir, path.filename(target:targetfile())))
- -- copy dependent dynamic libraries, TODO copy frameworks
+ -- change rpath
+ -- @see https://github.com/xmake-io/xmake/issues/2679#issuecomment-1221839215
+ local targetfile = path.join(binarydir, path.filename(target:targetfile()))
+ os.vrunv("install_name_tool", {"-delete_rpath", "@loader_path", targetfile})
+ os.vrunv("install_name_tool", {"-add_rpath", "@executable_path/../Frameworks", targetfile})
+
+ -- copy dependent dynamic libraries and frameworks
for _, dep in ipairs(target:orderdeps()) do
if dep:kind() == "shared" then
- os.vcp(dep:targetfile(), binarydir)
+ local frameworkdir = dep:data("xcode.bundle.rootdir")
+ if dep:rule("xcode.framework") and frameworkdir then
+ _copy_frameworks(frameworkdir, frameworksdir, {symlink = true})
+ else
+ os.vcp(dep:targetfile(), binarydir)
+ end
end
end
diff --git a/xmake/rules/xcode/framework/xmake.lua b/xmake/rules/xcode/framework/xmake.lua
index de7d7c93c..520ccf1b8 100644
--- a/xmake/rules/xcode/framework/xmake.lua
+++ b/xmake/rules/xcode/framework/xmake.lua
@@ -105,6 +105,13 @@ rule("xcode.framework")
end
os.vcp(target:targetfile(), contentsdir)
+ -- change rpath
+ -- @see https://github.com/xmake-io/xmake/issues/2679#issuecomment-1221839215
+ local filename = path.filename(target:targetfile())
+ local targetfile = path.join(contentsdir, filename)
+ local rpath = path.relative(contentsdir, path.directory(bundledir))
+ os.vrunv("install_name_tool", {"-id", path.join("@rpath", rpath, filename), targetfile})
+
-- move header files
os.tryrm(headersdir)
os.mv(path.join(contentsdir, "Headers.tmp", target:basename()), headersdir)