Add a flag to print the nix-gl-host LD_LIBRARY_PATH
In some situations, such as environment setup scripts, we'd like to print the nix-gl-host LD_LIBRARY_PATH instead of running a binary.
This commit is contained in:
parent
95456b5ed1
commit
19ae538413
|
@ -329,7 +329,9 @@ def is_dso_cache_up_to_date(dsos: HostDSOs, cache_file_path: str) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def nvidia_main(cache_dir: str, dso_vendor_paths: List[str]) -> Dict:
|
def nvidia_main(
|
||||||
|
cache_dir: str, dso_vendor_paths: List[str], print_ld_library_path: bool = False
|
||||||
|
) -> Dict:
|
||||||
"""Prepares the environment necessary to run a opengl/cuda program
|
"""Prepares the environment necessary to run a opengl/cuda program
|
||||||
on a Nvidia graphics card. It is by definition really stateful.
|
on a Nvidia graphics card. It is by definition really stateful.
|
||||||
|
|
||||||
|
@ -404,6 +406,8 @@ def nvidia_main(cache_dir: str, dso_vendor_paths: List[str]) -> Dict:
|
||||||
new_env["__EGL_VENDOR_LIBRARY_DIRS"] = egl_config_files
|
new_env["__EGL_VENDOR_LIBRARY_DIRS"] = egl_config_files
|
||||||
ld_library_path = os.environ.get("LD_LIBRARY_PATH", None)
|
ld_library_path = os.environ.get("LD_LIBRARY_PATH", None)
|
||||||
nv_ld_library_path = f"{cuda_dir}:{glx_dir}"
|
nv_ld_library_path = f"{cuda_dir}:{glx_dir}"
|
||||||
|
if print_ld_library_path:
|
||||||
|
print(nv_ld_library_path)
|
||||||
ld_library_path = (
|
ld_library_path = (
|
||||||
nv_ld_library_path
|
nv_ld_library_path
|
||||||
if ld_library_path is None
|
if ld_library_path is None
|
||||||
|
@ -439,10 +443,11 @@ def main(args):
|
||||||
else:
|
else:
|
||||||
log_info("Retrieving DSOs from the load path.")
|
log_info("Retrieving DSOs from the load path.")
|
||||||
host_dsos_paths: List[str] = get_ld_paths()
|
host_dsos_paths: List[str] = get_ld_paths()
|
||||||
new_env = nvidia_main(cache_dir, host_dsos_paths)
|
new_env = nvidia_main(cache_dir, host_dsos_paths, args.print_ld_library_path)
|
||||||
os.environ.update(new_env)
|
|
||||||
log_info(f"{time.time() - start_time} seconds elapsed since script start.")
|
log_info(f"{time.time() - start_time} seconds elapsed since script start.")
|
||||||
exec_binary(args.NIX_BINARY, args.ARGS)
|
if args.NIX_BINARY:
|
||||||
|
os.environ.update(new_env)
|
||||||
|
exec_binary(args.NIX_BINARY, args.ARGS)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -458,17 +463,37 @@ if __name__ == "__main__":
|
||||||
help="Use the driver libraries contained in this directory instead of discovering them from the load path.",
|
help="Use the driver libraries contained in this directory instead of discovering them from the load path.",
|
||||||
default=None,
|
default=None,
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-p",
|
||||||
|
"--print-ld-library-path",
|
||||||
|
action=argparse.BooleanOptionalAction,
|
||||||
|
default=False,
|
||||||
|
help="Print the GL/Cuda LD_LIBRARY_PATH env you should add to your environment.",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"NIX_BINARY",
|
"NIX_BINARY",
|
||||||
type=str,
|
type=str,
|
||||||
|
nargs="?",
|
||||||
help="Nix-built binary you'd like to wrap.",
|
help="Nix-built binary you'd like to wrap.",
|
||||||
|
default=None,
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"ARGS",
|
"ARGS",
|
||||||
type=str,
|
type=str,
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="The args passed to the wrapped binary.",
|
help="The args passed to the wrapped binary.",
|
||||||
|
default=None,
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
if args.print_ld_library_path and args.NIX_BINARY:
|
||||||
|
print(
|
||||||
|
"ERROR: -p and NIX_BINARY are both set. You have to choose between one of these options."
|
||||||
|
)
|
||||||
|
print(" run nixglhost --help for more informations. ")
|
||||||
|
sys.exit(1)
|
||||||
|
elif not args.print_ld_library_path and not args.NIX_BINARY:
|
||||||
|
print("ERROR: Please set the NIX_BINARY you want to run.")
|
||||||
|
print(" run nixglhost --help for more informations. ")
|
||||||
|
sys.exit(1)
|
||||||
ret = main(args)
|
ret = main(args)
|
||||||
sys.exit(ret)
|
sys.exit(ret)
|
||||||
|
|
Loading…
Reference in a new issue