From 9aee5239d96e4682bc473bc819049549cb9ce006 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 22 Aug 2022 23:18:17 +0800 Subject: improve frameworks --- xmake/rules/xcode/application/build.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'xmake/rules/xcode/application/build.lua') diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua index a4862ae86..3be9c0371 100644 --- a/xmake/rules/xcode/application/build.lua +++ b/xmake/rules/xcode/application/build.lua @@ -32,6 +32,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 +47,16 @@ function main (target, opt) end os.vcp(target:targetfile(), path.join(binarydir, path.filename(target:targetfile()))) - -- copy dependent dynamic libraries, TODO copy frameworks + -- 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 + os.mkdir(frameworksdir) + os.vcp(frameworkdir, frameworksdir, {symlink = true}) + else + os.vcp(dep:targetfile(), binarydir) + end end end -- cgit v1.3.1 From 22097d49e8a8ff60a8535005c3c3e5b713b2bd42 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Aug 2022 00:45:23 +0800 Subject: improve to copy framework --- xmake/rules/xcode/application/build.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'xmake/rules/xcode/application/build.lua') diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua index 3be9c0371..fcc428b91 100644 --- a/xmake/rules/xcode/application/build.lua +++ b/xmake/rules/xcode/application/build.lua @@ -25,6 +25,21 @@ 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) + for _, filepath in ipairs(os.filedirs(path.join(frameworkdir, "*"))) do + if path.filename(filepath) == "Versions" then + _copy_frameworks(filepath, path.join(frameworksdir, "Versions")) + else + os.cp(filepath, path.join(frameworksdir, path.filename(filepath)), {symlink = true}) + end + end +end + -- main entry function main (target, opt) @@ -52,8 +67,7 @@ function main (target, opt) if dep:kind() == "shared" then local frameworkdir = dep:data("xcode.bundle.rootdir") if dep:rule("xcode.framework") and frameworkdir then - os.mkdir(frameworksdir) - os.vcp(frameworkdir, frameworksdir, {symlink = true}) + _copy_frameworks(frameworkdir, frameworksdir, {symlink = true}) else os.vcp(dep:targetfile(), binarydir) end -- cgit v1.3.1 From 3e51aca6b415fdec57c23b1ad430e29a7c1864a5 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Aug 2022 00:59:56 +0800 Subject: fix link --- xmake/core/base/os.lua | 3 --- xmake/rules/xcode/application/build.lua | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'xmake/rules/xcode/application/build.lua') diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 02e3b7838..fdbc3edbf 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -82,9 +82,6 @@ function os._cp(src, dst, rootdir, opt) -- link file if reserve symlink if opt and opt.symlink and os.islink(src) then local reallink = os.readlink(src) - if os.isfile(dst) then - os.rm(dst) - end if not os.link(reallink, dst) then return false, string.format("cannot link %s(%s) to %s, %s", src, reallink, dst, os.strerror()) end diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua index fcc428b91..bb4ca080b 100644 --- a/xmake/rules/xcode/application/build.lua +++ b/xmake/rules/xcode/application/build.lua @@ -35,7 +35,9 @@ function _copy_frameworks(frameworkdir, frameworksdir) if path.filename(filepath) == "Versions" then _copy_frameworks(filepath, path.join(frameworksdir, "Versions")) else - os.cp(filepath, path.join(frameworksdir, path.filename(filepath)), {symlink = true}) + local dstpath = path.join(frameworksdir, path.filename(filepath)) + os.tryrm(dstpath) + os.cp(filepath, dstpath, {symlink = true}) end end end -- cgit v1.3.1 From cc0dfe3d9eca8e11bb6c555c36edf3117d80559a Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 Aug 2022 22:33:47 +0800 Subject: fix load framework --- xmake/rules/xcode/application/build.lua | 12 ++++++++++-- xmake/rules/xcode/framework/xmake.lua | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'xmake/rules/xcode/application/build.lua') diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua index bb4ca080b..b39c3546e 100644 --- a/xmake/rules/xcode/application/build.lua +++ b/xmake/rules/xcode/application/build.lua @@ -31,11 +31,13 @@ import("utils.progress") -- 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, path.join(frameworksdir, "Versions")) + _copy_frameworks(filepath, frameworkdir_dst) else - local dstpath = path.join(frameworksdir, path.filename(filepath)) + local dstpath = path.join(frameworkdir_dst, path.filename(filepath)) os.tryrm(dstpath) os.cp(filepath, dstpath, {symlink = true}) end @@ -64,6 +66,12 @@ function main (target, opt) end os.vcp(target:targetfile(), path.join(binarydir, path.filename(target:targetfile()))) + -- 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 diff --git a/xmake/rules/xcode/framework/xmake.lua b/xmake/rules/xcode/framework/xmake.lua index 1dde3eec6..520ccf1b8 100644 --- a/xmake/rules/xcode/framework/xmake.lua +++ b/xmake/rules/xcode/framework/xmake.lua @@ -106,6 +106,7 @@ rule("xcode.framework") 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)) -- cgit v1.3.1