···1043104310441044In certain situations you may want to run the main command (`autoPatchelf`) of the setup hook on a file or a set of directories instead of unconditionally patching all outputs. This can be done by setting the `dontAutoPatchelf` environment variable to a non-empty value.
1045104510461046-By default `autoPatchelf` will fail as soon as any ELF file requires a dependency which cannot be resolved via the given build inputs. In some situations you might prefer to just leave missing dependencies unpatched and continue to patch the rest. This can be achieved by setting the `autoPatchelfIgnoreMissingDeps` environment variable to a non-empty value.
10461046+By default `autoPatchelf` will fail as soon as any ELF file requires a dependency which cannot be resolved via the given build inputs. In some situations you might prefer to just leave missing dependencies unpatched and continue to patch the rest. This can be achieved by setting the `autoPatchelfIgnoreMissingDeps` environment variable to a non-empty value. `autoPatchelfIgnoreMissingDeps` can be set to a list like `autoPatchelfIgnoreMissingDeps = [ "libcuda.so.1" "libcudart.so.1" ];` or to simply `[ "*" ]` to ignore all missing dependencies.
1047104710481048The `autoPatchelf` command also recognizes a `--no-recurse` command line flag, which prevents it from recursing into subdirectories.
10491049
+23-17
pkgs/build-support/setup-hooks/auto-patchelf.py
···11#!/usr/bin/env python3
2233-from collections import defaultdict
44-from contextlib import contextmanager
55-from dataclasses import dataclass
66-from elftools.common.exceptions import ELFError # type: ignore
77-from elftools.elf.dynamic import DynamicSection # type: ignore
88-from elftools.elf.elffile import ELFFile # type: ignore
99-from elftools.elf.enums import ENUM_E_TYPE, ENUM_EI_OSABI # type: ignore
1010-from itertools import chain
1111-from pathlib import Path, PurePath
1212-1313-from typing import Tuple, Optional, Iterator, List, DefaultDict, Set
1414-153import argparse
164import os
175import pprint
186import subprocess
197import sys
88+from collections import defaultdict
99+from contextlib import contextmanager
1010+from dataclasses import dataclass
1111+from itertools import chain
1212+from pathlib import Path, PurePath
1313+from typing import DefaultDict, Iterator, List, Optional, Set, Tuple
20141515+from elftools.common.exceptions import ELFError # type: ignore
1616+from elftools.elf.dynamic import DynamicSection # type: ignore
1717+from elftools.elf.elffile import ELFFile # type: ignore
1818+from elftools.elf.enums import ENUM_E_TYPE, ENUM_EI_OSABI # type: ignore
211922202321@contextmanager
···246244 lib_dirs: List[Path],
247245 runtime_deps: List[Path],
248246 recursive: bool =True,
249249- ignore_missing: bool =False) -> None:
247247+ ignore_missing: List[str] = []) -> None:
250248251249 if not paths_to_patch:
252250 sys.exit("No paths to patch, stopping.")
···264262 missing = [dep for dep in dependencies if not dep.found]
265263266264 # Print a summary of the missing dependencies at the end
265265+ print(f"auto-patchelf: {len(missing)} dependencies could not be satisfied")
266266+ failure = False
267267 for dep in missing:
268268- print(f"auto-patchelf could not satisfy dependency {dep.name} wanted by {dep.file}")
268268+ if dep.name.name in ignore_missing or "*" in ignore_missing:
269269+ print(f"warn: auto-patchelf ignoring missing {dep.name} wanted by {dep.file}")
270270+ else:
271271+ print(f"error: auto-patchelf could not satisfy dependency {dep.name} wanted by {dep.file}")
272272+ failure = True
269273270270- if missing and not ignore_missing:
274274+ if failure:
271275 sys.exit('auto-patchelf failed to find all the required dependencies.\n'
272272- 'Add the missing dependencies to --libs or use --ignore-missing.')
276276+ 'Add the missing dependencies to --libs or use '
277277+ '`--ignore-missing="foo.so.1 bar.so etc.so"`.')
273278274279275280def main() -> None:
···280285 'libraries in the provided paths.')
281286 parser.add_argument(
282287 "--ignore-missing",
283283- action="store_true",
288288+ nargs="*",
289289+ type=str,
284290 help="Do not fail when some dependencies are not found.")
285291 parser.add_argument(
286292 "--no-recurse",
+8-1
pkgs/build-support/setup-hooks/auto-patchelf.sh
···5353 esac
5454 done
55555656+ if [ "${autoPatchelfIgnoreMissingDeps[*]}" == "1" ]; then
5757+ echo "autoPatchelf: WARNING: setting 'autoPatchelfIgnoreMissingDeps" \
5858+ "= true;' is deprecated and will be removed in a future release." \
5959+ "Use 'autoPatchelfIgnoreMissingDeps = [ \"*\" ];' instead." >&2
6060+ autoPatchelfIgnoreMissingDeps=( "*" )
6161+ fi
6262+5663 local runtimeDependenciesArray=($runtimeDependencies)
5764 @pythonInterpreter@ @autoPatchelfScript@ \
5865 ${norecurse:+--no-recurse} \
5959- ${autoPatchelfIgnoreMissingDeps:+--ignore-missing} \
6666+ --ignore-missing "${autoPatchelfIgnoreMissingDeps[@]}" \
6067 --paths "$@" \
6168 --libs "${autoPatchelfLibs[@]}" \
6269 "${extraAutoPatchelfLibs[@]}" \
···5252 xinput
5353 ];
54545555- autoPatchelfIgnoreMissingDeps = true; # Attempts to patchelf unneeded SOs
5555+ autoPatchelfIgnoreMissingDeps = [ "libc.musl-x86_64.so.1" ]; # Attempts to patchelf unneeded SOs
56565757 meta = with lib; {
5858 description = "A tracking application for A Link to the Past Randomizer";