wip
This commit is contained in:
parent
c1680e0c7c
commit
999e620c54
|
@ -419,8 +419,8 @@ def cache_library_path(library_path: LibraryPath, cache_dir_root: str) -> str:
|
||||||
the graphics card drivers. Its full name is hashed: it's an
|
the graphics card drivers. Its full name is hashed: it's an
|
||||||
attempt to keep the final LD_LIBRARY_PATH reasonably sized.
|
attempt to keep the final LD_LIBRARY_PATH reasonably sized.
|
||||||
|
|
||||||
Returns the full path of the cache directory created by this
|
Returns the name of the cache directory created by this
|
||||||
function."""
|
function to CACHE_DIR_ROOT."""
|
||||||
# Hash Computation
|
# Hash Computation
|
||||||
h = hashlib.sha256()
|
h = hashlib.sha256()
|
||||||
h.update(library_path.path.encode("utf8"))
|
h.update(library_path.path.encode("utf8"))
|
||||||
|
@ -443,7 +443,7 @@ def cache_library_path(library_path: LibraryPath, cache_dir_root: str) -> str:
|
||||||
copy_and_patch_libs(dsos=dsos, dest_dir=d, rpath=lib_dir)
|
copy_and_patch_libs(dsos=dsos, dest_dir=d, rpath=lib_dir)
|
||||||
else:
|
else:
|
||||||
log_info(f"Did not find any DSO to put in {d}, skipping copy and patching.")
|
log_info(f"Did not find any DSO to put in {d}, skipping copy and patching.")
|
||||||
return cache_path_root
|
return path_hash
|
||||||
|
|
||||||
|
|
||||||
def generate_cache_ld_library_path(cache_paths: List[str]) -> str:
|
def generate_cache_ld_library_path(cache_paths: List[str]) -> str:
|
||||||
|
@ -463,6 +463,31 @@ def generate_cache_ld_library_path(cache_paths: List[str]) -> str:
|
||||||
return ":".join(ld_library_paths)
|
return ":".join(ld_library_paths)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_cache_metadata(
|
||||||
|
cache_dir: str, cache_content: CacheDirContent, cache_paths: List[str]
|
||||||
|
) -> str:
|
||||||
|
"""Generates the various cache metadata for a given CACHE_CONTENT
|
||||||
|
and CACHE_PATHS in CACHE_DIR.
|
||||||
|
The metadata being:
|
||||||
|
|
||||||
|
- CACHE_DIR/cache.json: json file containing all the paths info.
|
||||||
|
- CACHE_DIR/ld_library_path: file containing the LD_LIBRARY_PATH
|
||||||
|
to inject for the CACHE_PATHS.
|
||||||
|
- CACHE_DIR/egl-confs: directory containing the various EGL
|
||||||
|
confs."""
|
||||||
|
cache_file_path = os.path.join(cache_dir, "cache.json")
|
||||||
|
cached_ld_library_path = os.path.join(cache_dir, "ld_library_path")
|
||||||
|
egl_conf_dir = os.path.join(cache_dir, "egl-confs")
|
||||||
|
with open(cache_file_path, "w", encoding="utf8") as f:
|
||||||
|
f.write(cache_content.to_json())
|
||||||
|
nix_gl_ld_library_path = generate_cache_ld_library_path(cache_paths)
|
||||||
|
log_info(f"Caching LD_LIBRARY_PATH: {nix_gl_ld_library_path}")
|
||||||
|
with open(cached_ld_library_path, "w", encoding="utf8") as f:
|
||||||
|
f.write(nix_gl_ld_library_path)
|
||||||
|
generate_nvidia_egl_config_files(egl_conf_dir)
|
||||||
|
return cache_dir
|
||||||
|
|
||||||
|
|
||||||
def nvidia_main(
|
def nvidia_main(
|
||||||
cache_dir: str, dso_vendor_paths: List[str], print_ld_library_path: bool = False
|
cache_dir: str, dso_vendor_paths: List[str], print_ld_library_path: bool = False
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
|
@ -499,6 +524,7 @@ def nvidia_main(
|
||||||
egl_conf_dir = os.path.join(cache_dir, "egl-confs")
|
egl_conf_dir = os.path.join(cache_dir, "egl-confs")
|
||||||
nix_gl_ld_library_path: Optional[str] = None
|
nix_gl_ld_library_path: Optional[str] = None
|
||||||
# Cache/Patch DSOs
|
# Cache/Patch DSOs
|
||||||
|
# TODO: extract
|
||||||
for path in paths:
|
for path in paths:
|
||||||
res = scan_dsos_from_dir(path)
|
res = scan_dsos_from_dir(path)
|
||||||
if res:
|
if res:
|
||||||
|
@ -512,14 +538,8 @@ def nvidia_main(
|
||||||
for p in cache_content.paths:
|
for p in cache_content.paths:
|
||||||
log_info(f"Caching {p}")
|
log_info(f"Caching {p}")
|
||||||
cache_paths.append(cache_library_path(p, cache_dir))
|
cache_paths.append(cache_library_path(p, cache_dir))
|
||||||
log_info(f"Caching ")
|
cache_absolute_paths = [os.path.join(cache_dir, p) for p in cache_paths]
|
||||||
with open(cache_file_path, "w", encoding="utf8") as f:
|
generate_cache_metadata(cache_dir, cache_content, cache_absolute_paths)
|
||||||
f.write(cache_content.to_json())
|
|
||||||
nix_gl_ld_library_path = generate_cache_ld_library_path(cache_paths)
|
|
||||||
log_info(f"Caching LD_LIBRARY_PATH: {nix_gl_ld_library_path}")
|
|
||||||
with open(cached_ld_library_path, "w", encoding="utf8") as f:
|
|
||||||
f.write(nix_gl_ld_library_path)
|
|
||||||
generate_nvidia_egl_config_files(egl_conf_dir)
|
|
||||||
else:
|
else:
|
||||||
log_info("The cache is up to date, re-using it.")
|
log_info("The cache is up to date, re-using it.")
|
||||||
with open(cached_ld_library_path, "r", encoding="utf8") as f:
|
with open(cached_ld_library_path, "r", encoding="utf8") as f:
|
||||||
|
@ -527,7 +547,6 @@ def nvidia_main(
|
||||||
|
|
||||||
assert nix_gl_ld_library_path, "The nix-host-gl LD_LIBRARY_PATH is not set"
|
assert nix_gl_ld_library_path, "The nix-host-gl LD_LIBRARY_PATH is not set"
|
||||||
log_info(f"Injecting LD_LIBRARY_PATH: {nix_gl_ld_library_path}")
|
log_info(f"Injecting LD_LIBRARY_PATH: {nix_gl_ld_library_path}")
|
||||||
os.makedirs(egl_conf_dir, exist_ok=True)
|
|
||||||
new_env = {}
|
new_env = {}
|
||||||
log_info(f"__GLX_VENDOR_LIBRARY_NAME = nvidia")
|
log_info(f"__GLX_VENDOR_LIBRARY_NAME = nvidia")
|
||||||
new_env["__GLX_VENDOR_LIBRARY_NAME"] = "nvidia"
|
new_env["__GLX_VENDOR_LIBRARY_NAME"] = "nvidia"
|
||||||
|
|
Loading…
Reference in a new issue