Skip to content

Commit

Permalink
envision: autopatchelf after build
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandapip1 committed Dec 15, 2024
1 parent 62b6336 commit cb45ad8
Show file tree
Hide file tree
Showing 2 changed files with 278 additions and 36 deletions.
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
}
109 changes: 73 additions & 36 deletions pkgs/by-name/en/envision/package.nix
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
{
lib,
pkgs,
buildFHSEnv,
envision-unwrapped,
}:

buildFHSEnv {
pname = "envision";
inherit (envision-unwrapped) version;

extraOutputsToInstall = [ "dev" ];

strictDeps = true;

# TODO: I'm pretty suspicious of this list of additonal required dependencies. Are they all really needed?
targetPkgs =
pkgs:
[ pkgs.envision-unwrapped ]
++ (with pkgs; [
stdenv.cc.libc
gcc
])
++ (
# OpenHMD dependencies
pkgs.openhmd.buildInputs ++ pkgs.openhmd.nativeBuildInputs
)
++ (
# OpenComposite dependencies
pkgs.opencomposite.buildInputs ++ pkgs.opencomposite.nativeBuildInputs
)
++ (
# Monado dependencies
let
runtimeBuildDeps =
pkgs':
with pkgs';
(
(
pkgs.monado.buildInputs
++ pkgs.monado.nativeBuildInputs
++ (with pkgs; [
# OpenHMD dependencies
openhmd.buildInputs ++ openhmd.nativeBuildInputs
)
++ (
# OpenComposite dependencies
opencomposite.buildInputs ++ opencomposite.nativeBuildInputs ++ [ boost ]
)
++ (
# Monado dependencies
monado.buildInputs
++ monado.nativeBuildInputs
++ [
# Additional dependencies required by Monado when built using Envision
libgbm
shaderc
mesa # TODO: Does this really need "mesa-common-dev"?
xorg.libX11
xorg.libxcb
xorg.libXrandr
xorg.libXrender
xorg.xorgproto

# Additional dependencies required for Monado WMR support
bc
fmt
Expand All @@ -52,7 +42,17 @@ buildFHSEnv {
lz4.dev
tbb
libxkbcommon
])

# Not required for build, but autopatchelf requires them
glibc
SDL2
bluez
librealsense
onnxruntime
libusb1
libjpeg
libGL
]
)
)
++ (
Expand All @@ -64,13 +64,47 @@ buildFHSEnv {
++ pkgs.wivrn.nativeBuildInputs
++ (with pkgs; [
glib
avahi
cmake
cli11
ffmpeg
git
gst_all_1.gstreamer
gst_all_1.gst-plugins-base
libmd
ninja
])
++ (with pkgs; [
android-tools # For adb installing WiVRn APKs
nlohmann_json
openxr-loader
pipewire
systemdLibs # udev
vulkan-loader
vulkan-headers
x264
])
);
in
buildFHSEnv rec {
name = "envision";
inherit (envision-unwrapped) version;

extraOutputsToInstall = [
"dev"
"lib"
];

strictDeps = true;

targetPkgs =
pkgs':
[
(pkgs'.envision-unwrapped.overrideAttrs (oldAttrs: {
patches = (oldAttrs.patches or [ ]) ++ [ ./autopatchelf.patch ]; # Adds an envision build step to run autopatchelf
}))
pkgs'.auto-patchelf
pkgs'.gcc
pkgs'.android-tools # For adb installing WiVRn APKs
]
++ (runtimeBuildDeps pkgs');

profile = ''
export CMAKE_LIBRARY_PATH=/usr/lib
Expand All @@ -82,7 +116,10 @@ buildFHSEnv {
ln -s ${envision-unwrapped}/share $out/share
'';

runScript = "envision";
# Putting libgcc.lib in runtimeBuildDeps causes error "ld: cannot find crt1.o: No such file or directory"
runScript = "env libs=${
lib.makeLibraryPath ((runtimeBuildDeps pkgs) ++ [ pkgs.libgcc.lib ])
} envision --skip-dependency-check";

meta = envision-unwrapped.meta // {
description = "${envision-unwrapped.meta.description} (with build environment)";
Expand Down

0 comments on commit cb45ad8

Please sign in to comment.