From 47936494ac22708db891504db685c54be42e9ec7 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Wed, 19 Jun 2024 14:39:10 -0700 Subject: [PATCH] MacPlatform: use install_name_tool to add /usr/local/lib and /opt/hombrew/lib to rpath of lime.ndll Previously, we added these rpaths to lime.ndll when it was built in commits c70ec9f and 333d093, but it's actually necessary only for Neko, so now I made it happen specfically after calling `nekotools boot` to create the Neko executable. I've tested cpp and hl, and I've confirmed that the executables still launch successfully when these rpaths are omitted. It's better for their security to use fewer rpaths. As noted commit c70ec9f, adding these rpaths is necessary due to a change in Xcode 15 where /usr/local/lib used to be available on the rpath automatically, but now it isn't, which affects the executable's ability to find the libneko dylib. --- project/Build.xml | 7 ------- tools/platforms/MacPlatform.hx | 12 ++++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/project/Build.xml b/project/Build.xml index a23c4033a..0310460d9 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -442,13 +442,6 @@
- - - - diff --git a/tools/platforms/MacPlatform.hx b/tools/platforms/MacPlatform.hx index f2161d936..9889af858 100644 --- a/tools/platforms/MacPlatform.hx +++ b/tools/platforms/MacPlatform.hx @@ -2,6 +2,7 @@ package; import lime.tools.HashlinkHelper; import hxp.Haxelib; +import hxp.HostArchitecture; import hxp.HXML; import hxp.Log; import hxp.Path; @@ -188,6 +189,17 @@ class MacPlatform extends PlatformTarget NekoHelper.createExecutable(project.templatePaths, "mac" + dirSuffix.toLowerCase(), targetDirectory + "/obj/ApplicationMain.n", executablePath); NekoHelper.copyLibraries(project.templatePaths, "mac" + dirSuffix.toLowerCase(), executableDirectory); + + // starting in xcode 15, rpath doesn't automatically include + // /usr/local/lib, but we need it for libneko dylib + System.runCommand("", "install_name_tool", ["-add_rpath", "/usr/local/lib", Path.join([executableDirectory, "lime.ndll"])]); + if (System.hostArchitecture == HostArchitecture.ARM64) + { + // on Apple Silicon, the user may have installed Neko with + // Homebrew, which has a different path. however, if the + // Homebrew path doesn't exist, that's okay. + System.runCommand("", "install_name_tool", ["-add_rpath", "/opt/homebrew/lib", Path.join([executableDirectory, "lime.ndll"])]); + } } else if (targetType == "hl") {