From c2db03a323516e016a05895d9a6c79a3fd71a4ab Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 4 Feb 2025 00:01:01 +0530 Subject: [PATCH] soup: Ensure that libsoup RPATHs are added with Homebrew too With the old method of adding build RPATHs, only the libsoup as a subproject was supported. However, it's possible to use Homebrew for libsoup too by adding libsoup as a dependency to the target (even though we don't link to it). Apple ld will not add a LC_LOAD_DYLIB entry for a library unless there are symbols that need it because meson passes `-dead_strip_dylibs`, so we can do this without issue. As a bonus, this ensures the correct build RPATHs in all cases. Additionally, we still need to explicitly add an LC_RPATH for the installed case. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4027 Part-of: --- .../ext/adaptivedemux2/meson.build | 3 ++- subprojects/gst-plugins-good/ext/meson.build | 21 ++++++++++++------- .../gst-plugins-good/ext/soup/meson.build | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/meson.build b/subprojects/gst-plugins-good/ext/adaptivedemux2/meson.build index 6543179818..864f17ac09 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/meson.build +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/meson.build @@ -157,6 +157,7 @@ if host_system == 'windows' else if default_library in ['static', 'both'] # Static plugin links to libsoup directly at build time + assert(soup_linked_target) adaptivedemux2_static = static_library('gstadaptivedemux2', c_args: [adaptive_args, soup_linked_target_args], dependencies: [adaptive_deps, soup_linked_target_deps], @@ -165,7 +166,7 @@ else if default_library in ['shared', 'both'] adaptivedemux2_shared = shared_library('gstadaptivedemux2', c_args: adaptive_args, - dependencies: adaptive_deps, + dependencies: [adaptive_deps, soup_dlopen_target_deps], kwargs: adaptive_kwargs + soup_dlopen_target_kwargs) endif endif diff --git a/subprojects/gst-plugins-good/ext/meson.build b/subprojects/gst-plugins-good/ext/meson.build index 3979fbc48b..95044a264c 100644 --- a/subprojects/gst-plugins-good/ext/meson.build +++ b/subprojects/gst-plugins-good/ext/meson.build @@ -18,6 +18,7 @@ soup_ver_opt = get_option('soup-version') default_library = get_option('default_library') soup_linked_target = host_system == 'windows' or default_library != 'shared' soup_lookup_dep = get_option('soup-lookup-dep') or soup_linked_target +soup_dlopen_target_deps = [] soup_dlopen_target_kwargs = {} if get_option('soup').allowed() or get_option('adaptivedemux2').allowed() @@ -43,16 +44,22 @@ if get_option('soup').allowed() or get_option('adaptivedemux2').allowed() endif endif - # Hack to set the right RPATH for making dlopen() work inside the devenv on - # macOS when using libsoup as a subproject. + # Hack to set the LC_RPATH for making dlopen() work, since meson will only + # add that for deps that are in the list of dependencies. We also need to add + # install_rpath to cover the installation case. Every other dep is loaded via + # absolute LC_LOAD_DYLIB entries. if host_system == 'darwin' foreach dep : [libsoup3_dep, libsoup2_dep] - if dep.found() and dep.type_name() == 'internal' - soup_dlopen_target_kwargs += { - 'build_rpath': '@loader_path/../../../libsoup-' + dep.version() / 'libsoup', - } - break + if not dep.found() + continue endif + soup_dlopen_target_deps += [dep] + if dep.type_name() == 'internal' + soup_dlopen_target_kwargs += {'install_rpath': '@loader_path/..'} + else + soup_dlopen_target_kwargs += {'install_rpath': dep.get_variable('libdir')} + endif + break endforeach endif endif diff --git a/subprojects/gst-plugins-good/ext/soup/meson.build b/subprojects/gst-plugins-good/ext/soup/meson.build index a61ee9c30f..43a1e815f1 100644 --- a/subprojects/gst-plugins-good/ext/soup/meson.build +++ b/subprojects/gst-plugins-good/ext/soup/meson.build @@ -71,7 +71,7 @@ else if default_library in ['shared', 'both'] gstsouphttpsrc_shared = shared_library('gstsoup', c_args : soup_library_c_args, - dependencies : soup_library_deps, + dependencies : soup_library_deps + soup_dlopen_target_deps, kwargs: soup_library_kwargs + soup_dlopen_target_kwargs, ) endif