From 7d54d050a2ef24aa2a88a625ea43fc4ed5e54fd7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 10 May 2022 16:34:06 +0100 Subject: meson: Add options to set a RPATH/RUNPATH on the bwrap executable This is useful when building a self-contained, relocatable tree containing a build of bubblewrap and all of its non-glibc dependencies (in practice this means libcap and maybe libselinux), as is done in the Steam container runtime. A RPATH/RUNPATH pointing to ${ORIGIN}/../lib allows bwrap to find an adjacent, bundled copy of libcap. Signed-off-by: Simon McVittie --- .github/workflows/check.yml | 1 + meson.build | 2 ++ meson_options.txt | 10 ++++++++++ tests/use-as-subproject/assert-correct-rpath.py | 26 +++++++++++++++++++++++++ tests/use-as-subproject/meson.build | 1 + 5 files changed, 40 insertions(+) create mode 100755 tests/use-as-subproject/assert-correct-rpath.py diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ceb3b82..d55d158 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -127,6 +127,7 @@ jobs: test -x DESTDIR-as-subproject/usr/local/libexec/not-flatpak-bwrap test ! -e DESTDIR-as-subproject/usr/local/bin/bwrap test ! -e DESTDIR-as-subproject/usr/local/libexec/bwrap + tests/use-as-subproject/assert-correct-rpath.py DESTDIR-as-subproject/usr/local/libexec/not-flatpak-bwrap - name: Upload test logs uses: actions/upload-artifact@v1 if: failure() || cancelled() diff --git a/meson.build b/meson.build index 404dd2e..0e1f110 100644 --- a/meson.build +++ b/meson.build @@ -121,8 +121,10 @@ bwrap = executable( 'network.c', 'utils.c', ], + build_rpath : get_option('build_rpath'), install : true, install_dir : bwrapdir, + install_rpath : get_option('install_rpath'), dependencies : [selinux_dep, libcap_dep], ) diff --git a/meson_options.txt b/meson_options.txt index 87bac9c..10a0a20 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -15,6 +15,16 @@ option( type : 'string', description : 'install bwrap in this directory [default: bindir, or libexecdir in subprojects]', ) +option( + 'build_rpath', + type : 'string', + description : 'set a RUNPATH or RPATH on the bwrap executable', +) +option( + 'install_rpath', + type : 'string', + description : 'set a RUNPATH or RPATH on the bwrap executable', +) option( 'man', type : 'feature', diff --git a/tests/use-as-subproject/assert-correct-rpath.py b/tests/use-as-subproject/assert-correct-rpath.py new file mode 100755 index 0000000..10b0947 --- /dev/null +++ b/tests/use-as-subproject/assert-correct-rpath.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: LGPL-2.0-or-later + +import subprocess +import sys + +if __name__ == '__main__': + completed = subprocess.run( + ['objdump', '-T', '-x', sys.argv[1]], + stdout=subprocess.PIPE, + ) + stdout = completed.stdout + assert stdout is not None + seen_rpath = False + + for line in stdout.splitlines(): + words = line.strip().split() + + if words and words[0] in (b'RPATH', b'RUNPATH'): + print(line.decode(errors='backslashreplace')) + assert len(words) == 2, words + assert words[1] == b'${ORIGIN}/../lib', words + seen_rpath = True + + assert seen_rpath diff --git a/tests/use-as-subproject/meson.build b/tests/use-as-subproject/meson.build index 802fd61..bc4781c 100644 --- a/tests/use-as-subproject/meson.build +++ b/tests/use-as-subproject/meson.build @@ -14,6 +14,7 @@ configure_file( subproject( 'bubblewrap', default_options : [ + 'install_rpath=${ORIGIN}/../lib', 'program_prefix=not-flatpak-', ], ) -- cgit v1.2.1