From f3c7db7d0f45cb935030bd5901133d7e6b9a023b Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Tue, 1 Aug 2023 16:46:28 +0200 Subject: [PATCH] Set the MacOS rpath in the build script (#30054) Use the build script to set the rpath in MacOS instead of mach. This is another step toward allowing building servo without mach. --- ports/libsimpleservo/api/build.rs | 6 ++++++ ports/winit/build.rs | 6 ++++++ python/servo/build_commands.py | 14 -------------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/ports/libsimpleservo/api/build.rs b/ports/libsimpleservo/api/build.rs index ca7a17a19d8..1c37e28af09 100644 --- a/ports/libsimpleservo/api/build.rs +++ b/ports/libsimpleservo/api/build.rs @@ -25,6 +25,12 @@ fn main() { println!("cargo:rustc-env=VERGEN_GIT_SHA=nogit"); } + // On MacOS, all dylib dependencies are shipped along with the binary + // in the "/lib" directory. Setting the rpath here, allows the dynamic + // linker to locate them. See `man dyld` for more info. + #[cfg(target_os = "macos")] + println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/lib/"); + // Generate GL bindings // For now, we only support EGL, and only on Windows and Android. if target.contains("android") || target.contains("windows") { diff --git a/ports/winit/build.rs b/ports/winit/build.rs index de66d874b81..e7b34dc2506 100644 --- a/ports/winit/build.rs +++ b/ports/winit/build.rs @@ -36,4 +36,10 @@ fn main() { ); println!("cargo:rustc-env=VERGEN_GIT_SHA=nogit"); } + + // On MacOS, all dylib dependencies are shipped along with the binary + // in the "/lib" directory. Setting the rpath here, allows the dynamic + // linker to locate them. See `man dyld` for more info. + #[cfg(target_os = "macos")] + println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/lib/"); } diff --git a/python/servo/build_commands.py b/python/servo/build_commands.py index c518ba76026..4497e16e849 100644 --- a/python/servo/build_commands.py +++ b/python/servo/build_commands.py @@ -238,12 +238,6 @@ class MachCommands(CommandBase): if not package_gstreamer_dylibs(self.cross_compile_target, servo_path): return 1 - # On Mac we use the relocatable dylibs from offical gstreamer - # .pkg distribution. We need to add an LC_RPATH to the servo binary - # to allow the dynamic linker to be able to locate these dylibs - # See `man dyld` for more info - add_rpath_to_binary(servo_path, "@executable_path/lib/") - # On the Mac, set a lovely icon. This makes it easier to pick out the Servo binary in tools # like Instruments.app. try: @@ -404,14 +398,6 @@ def change_link_name(binary, old, new): install_name_tool(binary, '-change', old, f"@executable_path/{new}") -def add_rpath_to_binary(binary, relative_path): - install_name_tool(binary, "-add_rpath", relative_path) - - -def change_rpath_in_binary(binary, old, new): - install_name_tool(binary, "-rpath", old, new) - - def is_system_library(lib): return lib.startswith("/System/Library") or lib.startswith("/usr/lib")