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