Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pkgs/development/tools/build-managers/meson/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ python3Packages.buildPythonApplication rec {
sha256 = "0qn5hyzvam3rimn7g3671s1igj7fbkwdnf5nc8jr4d5swy25mq61";
};

patchPhase = "cat ${./depfixer_patchelf.py} >> mesonbuild/scripts/depfixer.py";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be in postPatch in case we need to add patches in the future.


postFixup = ''
pushd $out/bin
# undo shell wrapper as meson tools are called with python
Expand All @@ -18,10 +20,6 @@ python3Packages.buildPythonApplication rec {
popd
'';

postPatch = ''
sed -i -e 's|e.fix_rpath(install_rpath)||' mesonbuild/scripts/meson_install.py
'';

setupHook = ./setup-hook.sh;

meta = with lib; {
Expand Down
35 changes: 35 additions & 0 deletions pkgs/development/tools/build-managers/meson/depfixer_patchelf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import subprocess

def _patchelf(*args):
p = subprocess.Popen(['patchelf'] + list(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
if p.returncode == 0:
return p.communicate()[0].rstrip()
else:
return None

class PatchElf(Elf):
def print_soname(self):
print(_patchelf('--print-soname', self.bfile) or 'This file does not have a soname.')

def print_rpath(self):
print(_patchelf('--print-rpath', self.bfile) or 'This file does not have a runpath.')

def fix_rpath(self, install_rpath):
if install_rpath:
old_rpath = _patchelf('--print-rpath', self.bfile)
if old_rpath:
new_rpath = old_rpath + b':' + bytes(install_rpath, 'utf-8')
if len(old_rpath) < len(new_rpath):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not this always true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. Thanks!

if self.verbose:
print('Expanding rpath beyond original capacity, setting dontStrip:')
print('https://github.com/NixOS/nixpkgs/pull/31228')
open('.nix-dont-strip', 'a').close()
else:
new_rpath = install_rpath
_patchelf('--set-rpath', new_rpath, self.bfile)

def remove_rpath_entry(self):
_patchelf('--remove-rpath', self.bfile)

Elf = PatchElf
10 changes: 10 additions & 0 deletions pkgs/development/tools/build-managers/meson/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ if [ -z "$dontUseMesonConfigure" -a -z "$configurePhase" ]; then
setOutputFlags=
configurePhase=mesonConfigurePhase
fi

mesonPreFixupPhase() {
for f in $(find . -name .nix-dont-strip); do
echo "Found $f, setting dontStrip"
export dontStrip=1
rm $f
done
}

preFixupPhases+=(mesonPreFixupPhase)