Merge pull request #226038 from SomeoneSerge/cuda_nvrtc-origin

cudaPackages: append $ORIGIN to Runpaths

authored by Guillaume Maudoux and committed by GitHub 46a39c48 40227f0b

+24 -6
+15 -5
pkgs/build-support/setup-hooks/auto-patchelf.py
··· 167 found: bool = False # Whether it was found somewhere 168 169 170 - def auto_patchelf_file(path: Path, runtime_deps: list[Path]) -> list[Dependency]: 171 try: 172 with open_elf(path) as elf: 173 ··· 235 dependencies.append(Dependency(path, dep, False)) 236 print(f" {dep} -> not found!") 237 238 # Dedup the rpath 239 rpath_str = ":".join(dict.fromkeys(map(Path.as_posix, rpath))) 240 ··· 251 paths_to_patch: List[Path], 252 lib_dirs: List[Path], 253 runtime_deps: List[Path], 254 - recursive: bool =True, 255 - ignore_missing: List[str] = []) -> None: 256 257 if not paths_to_patch: 258 sys.exit("No paths to patch, stopping.") ··· 265 dependencies = [] 266 for path in chain.from_iterable(glob(p, '*', recursive) for p in paths_to_patch): 267 if not path.is_symlink() and path.is_file(): 268 - dependencies += auto_patchelf_file(path, runtime_deps) 269 270 missing = [dep for dep in dependencies if not dep.found] 271 ··· 312 parser.add_argument( 313 "--runtime-dependencies", nargs="*", type=Path, 314 help="Paths to prepend to the runtime path of executable binaries.") 315 316 print("automatically fixing dependencies for ELF files") 317 args = parser.parse_args() ··· 322 args.libs, 323 args.runtime_dependencies, 324 args.recursive, 325 - args.ignore_missing) 326 327 328 interpreter_path: Path = None # type: ignore
··· 167 found: bool = False # Whether it was found somewhere 168 169 170 + def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = []) -> list[Dependency]: 171 try: 172 with open_elf(path) as elf: 173 ··· 235 dependencies.append(Dependency(path, dep, False)) 236 print(f" {dep} -> not found!") 237 238 + rpath.extend(append_rpaths) 239 + 240 # Dedup the rpath 241 rpath_str = ":".join(dict.fromkeys(map(Path.as_posix, rpath))) 242 ··· 253 paths_to_patch: List[Path], 254 lib_dirs: List[Path], 255 runtime_deps: List[Path], 256 + recursive: bool = True, 257 + ignore_missing: List[str] = [], 258 + append_rpaths: List[Path] = []) -> None: 259 260 if not paths_to_patch: 261 sys.exit("No paths to patch, stopping.") ··· 268 dependencies = [] 269 for path in chain.from_iterable(glob(p, '*', recursive) for p in paths_to_patch): 270 if not path.is_symlink() and path.is_file(): 271 + dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths) 272 273 missing = [dep for dep in dependencies if not dep.found] 274 ··· 315 parser.add_argument( 316 "--runtime-dependencies", nargs="*", type=Path, 317 help="Paths to prepend to the runtime path of executable binaries.") 318 + parser.add_argument( 319 + "--append-rpaths", 320 + nargs="*", 321 + type=Path, 322 + help="Paths to append to all runtime paths unconditionally", 323 + ) 324 325 print("automatically fixing dependencies for ELF files") 326 args = parser.parse_args() ··· 331 args.libs, 332 args.runtime_dependencies, 333 args.recursive, 334 + args.ignore_missing, 335 + append_rpaths=args.append_rpaths) 336 337 338 interpreter_path: Path = None # type: ignore
+3 -1
pkgs/build-support/setup-hooks/auto-patchelf.sh
··· 61 ignoreMissingDepsArray=( "*" ) 62 fi 63 64 local runtimeDependenciesArray=($runtimeDependencies) 65 @pythonInterpreter@ @autoPatchelfScript@ \ 66 ${norecurse:+--no-recurse} \ ··· 68 --paths "$@" \ 69 --libs "${autoPatchelfLibs[@]}" \ 70 "${extraAutoPatchelfLibs[@]}" \ 71 - --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" 72 } 73 74 # XXX: This should ultimately use fixupOutputHooks but we currently don't have
··· 61 ignoreMissingDepsArray=( "*" ) 62 fi 63 64 + local appendRunpathsArray=($appendRunpaths) 65 local runtimeDependenciesArray=($runtimeDependencies) 66 @pythonInterpreter@ @autoPatchelfScript@ \ 67 ${norecurse:+--no-recurse} \ ··· 69 --paths "$@" \ 70 --libs "${autoPatchelfLibs[@]}" \ 71 "${extraAutoPatchelfLibs[@]}" \ 72 + --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \ 73 + --append-rpaths "${appendRunpathsArray[@]}" 74 } 75 76 # XXX: This should ultimately use fixupOutputHooks but we currently don't have
+6
pkgs/development/compilers/cudatoolkit/redist/build-cuda-redist-package.nix
··· 38 stdenv.cc.cc.lib 39 ]; 40 41 dontBuild = true; 42 43 # TODO: choose whether to install static/dynamic libs
··· 38 stdenv.cc.cc.lib 39 ]; 40 41 + # Picked up by autoPatchelf 42 + # Needed e.g. for libnvrtc to locate (dlopen) libnvrtc-builtins 43 + appendRunpaths = [ 44 + "$ORIGIN" 45 + ]; 46 + 47 dontBuild = true; 48 49 # TODO: choose whether to install static/dynamic libs