Skip to content

Commit

Permalink
envision: autopatchelf after build (#359156)
Browse files Browse the repository at this point in the history
  • Loading branch information
layus authored Dec 16, 2024
2 parents a36414b + cb45ad8 commit 145f9be
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 47 deletions.
5 changes: 5 additions & 0 deletions doc/interoperability/openxr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# OpenXR in NixOS

OpenXR is a standard for eXtended Reality (XR) applications and drivers (providers).

OpenXR runtime providers must ensure that the library path of the runtime's shared library can be loaded by Nix applications. If your OpenXR runtime provider runs in an FHSEnv, this means you may have to use `auto-patchelf` to link dependencies to the Nix store.
49 changes: 38 additions & 11 deletions pkgs/by-name/au/auto-patchelf/source/auto-patchelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,17 @@ def auto_patchelf(
ignore_missing: list[str] = [],
append_rpaths: list[Path] = [],
keep_libc: bool = False,
add_existing: bool = True,
extra_args: list[str] = []) -> None:

if not paths_to_patch:
sys.exit("No paths to patch, stopping.")

# Add all shared objects of the current output path to the cache,
# before lib_dirs, so that they are chosen first in find_dependency.
populate_cache(paths_to_patch, recursive)
if add_existing:
populate_cache(paths_to_patch, recursive)

populate_cache(lib_dirs)

dependencies = []
Expand Down Expand Up @@ -360,35 +363,51 @@ def main() -> None:
prog="auto-patchelf",
description='auto-patchelf tries as hard as possible to patch the'
' provided binary files by looking for compatible'
'libraries in the provided paths.')
' libraries in the provided paths.')
parser.add_argument(
"--ignore-missing",
nargs="*",
type=str,
help="Do not fail when some dependencies are not found.")
default=[],
help="Do not fail when some dependencies are not found."
)
parser.add_argument(
"--no-recurse",
dest="recursive",
action="store_false",
help="Disable the recursive traversal of paths to patch.")
help="Disable the recursive traversal of paths to patch."
)
parser.add_argument(
"--paths", nargs="*", type=Path,
"--paths",
nargs="*",
type=Path,
required=True,
help="Paths whose content needs to be patched."
" Single files and directories are accepted."
" Directories are traversed recursively by default.")
" Directories are traversed recursively by default."
)
parser.add_argument(
"--libs", nargs="*", type=Path,
"--libs",
nargs="*",
type=Path,
default=[],
help="Paths where libraries are searched for."
" Single files and directories are accepted."
" Directories are not searched recursively.")
" Directories are not searched recursively."
)
parser.add_argument(
"--runtime-dependencies", nargs="*", type=Path,
"--runtime-dependencies",
nargs="*",
type=Path,
default=[],
help="Paths to prepend to the runtime path of executable binaries."
" Subject to deduplication, which may imply some reordering.")
" Subject to deduplication, which may imply some reordering."
)
parser.add_argument(
"--append-rpaths",
nargs="*",
type=Path,
default=[],
help="Paths to append to all runtime paths unconditionally",
)
parser.add_argument(
Expand All @@ -397,14 +416,21 @@ def main() -> None:
action="store_true",
help="Attempt to search for and relink libc dependencies.",
)
parser.add_argument(
"--ignore-existing",
dest="add_existing",
action="store_false",
help="Do not add the existing rpaths of the patched files to the list of directories to search for dependencies.",
)
parser.add_argument(
"--extra-args",
# Undocumented Python argparse feature: consume all remaining arguments
# as values for this one. This means this argument should always be passed
# last.
nargs="...",
type=str,
help="Extra arguments to pass to patchelf. This argument should always come last."
default=[],
help="Extra arguments to pass to patchelf. This argument should always come last.",
)

print("automatically fixing dependencies for ELF files")
Expand All @@ -419,6 +445,7 @@ def main() -> None:
args.ignore_missing,
append_rpaths=args.append_rpaths,
keep_libc=args.keep_libc,
add_existing=args.add_existing,
extra_args=args.extra_args)


Expand Down
205 changes: 205 additions & 0 deletions pkgs/by-name/en/envision/autopatchelf.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
diff --git a/src/builders/build_basalt.rs b/src/builders/build_basalt.rs
index e67e081..9ae1966 100644
--- a/src/builders/build_basalt.rs
+++ b/src/builders/build_basalt.rs
@@ -6,6 +6,7 @@ use crate::{
util::file_utils::rm_rf,
};
use std::collections::{HashMap, VecDeque};
+use std::env;

pub fn get_build_basalt_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
@@ -101,6 +102,21 @@ pub fn get_build_basalt_jobs(profile: &Profile, clean_build: bool) -> VecDeque<W
.to_string(),
]),
));
+ jobs.push_back(WorkerJob::new_cmd(
+ None,
+ "auto-patchelf".into(),
+ Some(
+ [
+ vec![
+ "--ignore-existing",
+ "--paths".into(),
+ build_dir.into_os_string().into_string().unwrap(),
+ "--libs".into(),
+ ],
+ env::var("libs").unwrap_or_default().split(":").map(|s| s.to_string()).collect(),
+ ].concat()
+ ),
+ ));

jobs
}
diff --git a/src/builders/build_libsurvive.rs b/src/builders/build_libsurvive.rs
index b4b0dc3..69871d4 100644
--- a/src/builders/build_libsurvive.rs
+++ b/src/builders/build_libsurvive.rs
@@ -9,6 +9,7 @@ use std::{
collections::{HashMap, VecDeque},
path::Path,
};
+use std::env;

pub fn get_build_libsurvive_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
@@ -71,6 +72,21 @@ pub fn get_build_libsurvive_jobs(profile: &Profile, clean_build: bool) -> VecDeq
}
jobs.push_back(cmake.get_build_job());
jobs.push_back(cmake.get_install_job());
+ jobs.push_back(WorkerJob::new_cmd(
+ None,
+ "auto-patchelf".into(),
+ Some(
+ [
+ vec![
+ "--ignore-existing",
+ "--paths".into(),
+ build_dir.into_os_string().into_string().unwrap(),
+ "--libs".into(),
+ ],
+ env::var("libs").unwrap_or_default().split(":").map(|s| s.to_string()).collect(),
+ ].concat()
+ ),
+ ));

jobs
}
diff --git a/src/builders/build_monado.rs b/src/builders/build_monado.rs
index f379d6f..5710add 100644
--- a/src/builders/build_monado.rs
+++ b/src/builders/build_monado.rs
@@ -9,6 +9,7 @@ use std::{
collections::{HashMap, VecDeque},
path::Path,
};
+use std::env;

pub fn get_build_monado_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
@@ -83,6 +84,21 @@ pub fn get_build_monado_jobs(profile: &Profile, clean_build: bool) -> VecDeque<W
}
jobs.push_back(cmake.get_build_job());
jobs.push_back(cmake.get_install_job());
+ jobs.push_back(WorkerJob::new_cmd(
+ None,
+ "auto-patchelf".into(),
+ Some(
+ [
+ vec![
+ "--ignore-existing",
+ "--paths".into(),
+ build_dir.into_os_string().into_string().unwrap(),
+ "--libs".into(),
+ ],
+ env::var("libs").unwrap_or_default().split(":").map(|s| s.to_string()).collect(),
+ ].concat()
+ ),
+ ));

jobs
}
diff --git a/src/builders/build_opencomposite.rs b/src/builders/build_opencomposite.rs
index 631b69f..72e8a73 100644
--- a/src/builders/build_opencomposite.rs
+++ b/src/builders/build_opencomposite.rs
@@ -9,6 +9,7 @@ use std::{
collections::{HashMap, VecDeque},
path::Path,
};
+use std::env;

pub fn get_build_opencomposite_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
@@ -48,6 +49,21 @@ pub fn get_build_opencomposite_jobs(profile: &Profile, clean_build: bool) -> Vec
jobs.push_back(cmake.get_prepare_job());
}
jobs.push_back(cmake.get_build_job());
+ jobs.push_back(WorkerJob::new_cmd(
+ None,
+ "auto-patchelf".into(),
+ Some(
+ [
+ vec![
+ "--ignore-existing",
+ "--paths".into(),
+ build_dir.into_os_string().into_string().unwrap(),
+ "--libs".into(),
+ ],
+ env::var("libs").unwrap_or_default().split(":").map(|s| s.to_string()).collect(),
+ ].concat()
+ ),
+ ));

jobs
}
diff --git a/src/builders/build_openhmd.rs b/src/builders/build_openhmd.rs
index 1157eca..534a895 100644
--- a/src/builders/build_openhmd.rs
+++ b/src/builders/build_openhmd.rs
@@ -3,6 +3,7 @@ use crate::{
util::file_utils::rm_rf,
};
use std::{collections::VecDeque, path::Path};
+use std::env;

pub fn get_build_openhmd_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
@@ -80,6 +81,22 @@ pub fn get_build_openhmd_jobs(profile: &Profile, clean_build: bool) -> VecDeque<
"install".into(),
]),
));
+ // autopatchelf job
+ jobs.push_back(WorkerJob::new_cmd(
+ None,
+ "auto-patchelf".into(),
+ Some(
+ [
+ vec![
+ "--ignore-existing",
+ "--paths".into(),
+ build_dir.into_os_string().into_string().unwrap(),
+ "--libs".into(),
+ ],
+ env::var("libs").unwrap_or_default().split(":").map(|s| s.to_string()).collect(),
+ ].concat()
+ ),
+ ));

jobs
}
diff --git a/src/builders/build_wivrn.rs b/src/builders/build_wivrn.rs
index f2a415d..a160186 100644
--- a/src/builders/build_wivrn.rs
+++ b/src/builders/build_wivrn.rs
@@ -9,6 +9,7 @@ use std::{
collections::{HashMap, VecDeque},
path::Path,
};
+use std::env;

pub fn get_build_wivrn_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new();
@@ -60,6 +61,21 @@ pub fn get_build_wivrn_jobs(profile: &Profile, clean_build: bool) -> VecDeque<Wo
}
jobs.push_back(cmake.get_build_job());
jobs.push_back(cmake.get_install_job());
+ jobs.push_back(WorkerJob::new_cmd(
+ None,
+ "auto-patchelf".into(),
+ Some(
+ [
+ vec![
+ "--no-add-existing",
+ "--paths".into(),
+ build_dir.into_os_string().into_string().unwrap(),
+ "--libs".into(),
+ ],
+ env::var("libs").unwrap_or_default().split(":").map(|s| s.to_string()).collect(),
+ ].concat()
+ ),
+ ));

jobs
}
Loading

0 comments on commit 145f9be

Please sign in to comment.