feat: switch to rust for build orchestration of monado, opencomp, libsurvive, wivrn

This commit is contained in:
Gabriele Musco 2023-07-16 22:57:22 +02:00
parent a2b5057931
commit cefdf35734
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE
15 changed files with 262 additions and 241 deletions

View file

@ -1,36 +0,0 @@
#!/bin/bash
set -ev
REPO_DIR=$1
PREFIX=$2
DO_PULL=$3
REPO_URL=$4
if [[ -z $REPO_DIR ]] || [[ -z $PREFIX ]] || [[ -z $DO_PULL ]]; then
echo "Usage: $0 REPO_DIR PREFIX DO_PULL [REPO_URL]"
exit 1
fi
if [[ -z $REPO_URL ]]; then
REPO_URL="https://github.com/cntools/libsurvive"
fi
"$(dirname -- "$0")/_clone_or_pull.sh" "$REPO_URL" "$REPO_DIR" "$DO_PULL"
cd "$REPO_DIR"
rm -rf build
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release \
-DENABLE_api_example=OFF \
-DCMAKE_SKIP_INSTALL_RPATH=YES \
-Wno-dev \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-DCMAKE_INSTALL_LIBDIR="${PREFIX}/lib" \
.. -G Ninja
cmake --build .
cmake --install .

View file

@ -1,39 +0,0 @@
#!/bin/bash
# exit on error
# echo commands
set -ev
REPO_DIR=$1
PREFIX=$2
DO_PULL=$3
REPO_URL=$4
if [[ -z $REPO_DIR ]] || [[ -z $PREFIX ]] || [[ -z $DO_PULL ]]; then
echo "Usage: $0 REPO_DIR PREFIX DO_PULL [REPO_URL]"
exit 1
fi
if [[ -z $REPO_URL ]]; then
REPO_URL="https://gitlab.freedesktop.org/monado/monado"
fi
"$(dirname -- "$0")/_clone_or_pull.sh" "$REPO_URL" "$REPO_DIR" "$DO_PULL"
cd "$REPO_DIR"
rm -rf build
mkdir -p build
cd build
export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
cmake -DCMAKE_BUILD_TYPE=Release \
-DXRT_HAVE_SYSTEM_CJSON=NO \
-DCMAKE_LIBDIR="${PREFIX}/lib" \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-DCMAKE_C_FLAGS="-Wl,-rpath ${PREFIX}/lib" \
-DCMAKE_CXX_FLAGS="-Wl,-rpath ${PREFIX}/lib" \
.. -G Ninja
cmake --build .
cmake --install .

View file

@ -1,29 +0,0 @@
#!/bin/bash
# exit on error
# echo commands
set -ev
REPO_DIR=$1
DO_PULL=$2
REPO_URL=$3
if [[ -z $REPO_DIR ]] || [[ -z $DO_PULL ]]; then
echo "Usage: $0 REPO_DIR DO_PULL [REPO_URL]"
exit 1
fi
if [[ -z $REPO_URL ]]; then
REPO_URL="https://gitlab.com/znixian/OpenOVR.git"
fi
"$(dirname -- "$0")/_clone_or_pull.sh" "$REPO_URL" "$REPO_DIR" "$DO_PULL"
cd "$REPO_DIR"
rm -rf build
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release .. -G Ninja
cmake --build .

View file

@ -1,36 +0,0 @@
#!/bin/bash
# exit on error
# echo commands
set -ev
REPO_DIR=$1
PREFIX=$2
DO_PULL=$3
REPO_URL=$4
if [[ -z $REPO_DIR ]] || [[ -z $PREFIX ]] || [[ -z $DO_PULL ]]; then
echo "Usage: $0 REPO_DIR PREFIX DO_PULL [REPO_URL]"
exit 1
fi
if [[ -z $REPO_URL ]]; then
REPO_URL="https://github.com/Meumeu/WiVRn"
fi
"$(dirname -- "$0")/_clone_or_pull.sh" "$REPO_URL" "$REPO_DIR" "$DO_PULL"
cd "$REPO_DIR"
rm -rf build
mkdir -p build
cd build
cmake -B build-server -DCMAKE_BUILD_TYPE=Release \
-DXRT_HAVE_SYSTEM_CJSON=NO \
-DWIVRN_BUILD_CLIENT=OFF \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
.. -GNinja
cmake --build build-server
ninja -C build-server install

View file

@ -1,7 +1,3 @@
install_data('_clone_or_pull.sh', install_dir: pkgdatadir / 'scripts')
install_data('build_basalt.sh', install_dir: pkgdatadir / 'scripts')
install_data('build_libsurvive.sh', install_dir: pkgdatadir / 'scripts')
install_data('build_monado.sh', install_dir: pkgdatadir / 'scripts')
install_data('build_mercury.sh', install_dir: pkgdatadir / 'scripts')
install_data('build_opencomposite.sh', install_dir: pkgdatadir / 'scripts')
install_data('build_wivrn.sh', install_dir: pkgdatadir / 'scripts')

View file

@ -20,7 +20,12 @@ impl Cmake {
if k.contains(" ") {
panic!("Cmake vars cannot contain spaces!");
}
args.push(format!("-D{k}=\"{v}\"", k=k, v=v));
if v.contains(" ") {
args.push(format!("-D{k}=\"{v}\"", k=k, v=v));
}
else {
args.push(format!("-D{k}={v}", k=k, v=v));
}
}
}
args.push(self.source_dir.clone());
@ -32,4 +37,10 @@ impl Cmake {
"--build".into(), self.build_dir.clone()
])
}
pub fn get_install_runner(&self) -> Runner {
Runner::new(self.env.clone(), "cmake".into(), vec![
"--install".into(), self.build_dir.clone()
])
}
}

59
src/build_tools/git.rs Normal file
View file

@ -0,0 +1,59 @@
use std::path::Path;
use crate::{profile::Profile, runner::Runner};
#[derive(Debug, Clone)]
pub struct Git {
pub repo: String,
pub dir: String,
}
impl Git {
pub fn get_reset_runner(&self) -> Runner {
Runner::new(
None,
"git".into(),
vec![
"-C".into(),
self.dir.clone(),
"reset".into(),
"--hard".into(),
],
)
}
pub fn get_pull_runner(&self) -> Runner {
Runner::new(
None,
"git".into(),
vec!["-C".into(), self.dir.clone(), "pull".into()],
)
}
pub fn get_clone_runner(&self) -> Runner {
Runner::new(
None,
"git".into(),
vec!["clone".into(), self.repo.clone(), self.dir.clone()],
)
}
pub fn get_clone_or_not_runner(&self) -> Option<Runner> {
let path_s = format!("{}/.git", self.dir.clone());
let path = Path::new(&path_s);
if path.is_dir() {
return None;
}
Some(self.get_clone_runner())
}
pub fn clone_or_pull(&self, profile: &Profile) -> Option<Runner> {
match self.get_clone_or_not_runner() {
Some(r) => Some(r),
None => match profile.pull_on_build {
true => Some(self.get_pull_runner()),
false => None,
},
}
}
}

View file

@ -1 +1,2 @@
pub mod cmake;
pub mod git;

View file

@ -1,18 +1,18 @@
use crate::{constants::pkg_data_dir, profile::Profile, runner::Runner};
pub fn get_build_basalt_runner(profile: Profile) -> Runner {
pub fn get_build_basalt_runner(profile: &Profile) -> Runner {
let mut args = vec![
profile
.features.basalt.path
.features.basalt.path.clone()
.expect("Missing basalt path for given profile"),
profile.prefix,
profile.prefix.clone(),
match profile.pull_on_build {
true => "1".into(),
false => "0".into(),
},
];
if profile.features.basalt.repo.is_some() {
args.push(profile.features.basalt.repo.unwrap());
args.push(profile.features.basalt.repo.as_ref().unwrap().clone());
}
let runner = Runner::new(
None,

View file

@ -1,26 +1,49 @@
use crate::{constants::pkg_data_dir, profile::Profile, runner::Runner};
use crate::{
build_tools::{cmake::Cmake, git::Git},
file_utils::rm_rf,
profile::Profile,
runner::Runner,
};
use std::collections::HashMap;
pub fn get_build_libsurvive_runner(profile: Profile) -> Runner {
let mut args = vec![
profile
.features.libsurvive.path
.expect("Missing libsurvive path for given profile"),
profile.prefix,
match profile.pull_on_build {
true => "1".into(),
false => "0".into(),
pub fn get_build_libsurvive_runners(profile: &Profile) -> Vec<Runner> {
let mut runners: Vec<Runner> = vec![];
let git = Git {
repo: match profile.features.libsurvive.repo.as_ref() {
Some(r) => r.clone(),
None => "https://github.com/cntools/libsurvive".into(),
},
];
if profile.features.libsurvive.repo.is_some() {
args.push(profile.features.libsurvive.repo.unwrap());
}
let runner = Runner::new(
None,
format!(
"{sysdata}/scripts/build_libsurvive.sh",
sysdata = pkg_data_dir()
),
args,
dir: profile.features.libsurvive.path.as_ref().unwrap().clone(),
};
match git.clone_or_pull(profile) {
Some(r) => runners.push(r),
None => {}
};
let build_dir = format!(
"{}/build",
profile.features.libsurvive.path.as_ref().unwrap()
);
runner
rm_rf(&build_dir);
let mut cmake_vars: HashMap<String, String> = HashMap::new();
cmake_vars.insert("CMAKE_BUILD_TYPE".into(), "Release".into());
cmake_vars.insert("ENABLE_api_example".into(), "OFF".into());
cmake_vars.insert("CMAKE_SKIP_INSTALL_RPATH".into(), "YES".into());
cmake_vars.insert("CMAKE_INSTALL_PREFIX".into(), profile.prefix.clone());
cmake_vars.insert(
"CMAKE_INSTALL_LIBDIR".into(),
format!("{}/lib", profile.prefix),
);
let cmake = Cmake {
env: None,
vars: Some(cmake_vars),
source_dir: profile.features.libsurvive.path.as_ref().unwrap().clone(),
build_dir,
};
runners.push(cmake.get_prepare_runner());
runners.push(cmake.get_build_runner());
runners.push(cmake.get_install_runner());
runners
}

View file

@ -1,7 +1,7 @@
use crate::{constants::pkg_data_dir, paths::get_cache_dir, profile::Profile, runner::Runner};
pub fn get_build_mercury_runner(profile: Profile) -> Runner {
let args = vec![profile.prefix, get_cache_dir()];
pub fn get_build_mercury_runner(profile: &Profile) -> Runner {
let args = vec![profile.prefix.clone(), get_cache_dir()];
let runner = Runner::new(
None,
format!(

View file

@ -1,21 +1,55 @@
use crate::{constants::pkg_data_dir, profile::Profile, runner::Runner};
use crate::{
build_tools::{cmake::Cmake, git::Git},
file_utils::rm_rf,
profile::Profile,
runner::Runner,
};
use std::collections::HashMap;
pub fn get_build_monado_runner(profile: Profile) -> Runner {
let mut args = vec![
profile.xrservice_path,
profile.prefix,
match profile.pull_on_build {
true => "1".into(),
false => "0".into(),
pub fn get_build_monado_runners(profile: &Profile) -> Vec<Runner> {
let mut runners: Vec<Runner> = vec![];
let git = Git {
repo: match profile.xrservice_repo.as_ref() {
Some(r) => r.clone(),
None => "https://gitlab.freedesktop.org/monado/monado".into(),
},
];
if profile.xrservice_repo.is_some() {
args.push(profile.xrservice_repo.unwrap());
}
let runner = Runner::new(
None,
format!("{sysdata}/scripts/build_monado.sh", sysdata = pkg_data_dir()),
args,
dir: profile.xrservice_path.clone(),
};
match git.clone_or_pull(profile) {
Some(r) => runners.push(r),
None => {}
};
let build_dir = format!("{}/build", profile.xrservice_path);
rm_rf(&build_dir);
let mut env: HashMap<String, String> = HashMap::new();
env.insert(
"PKG_CONFIG_PATH".into(),
format!("{}/lib/pkgconfig", profile.prefix),
);
runner
let mut cmake_vars: HashMap<String, String> = HashMap::new();
cmake_vars.insert("CMAKE_BUILD_TYPE".into(), "Release".into());
cmake_vars.insert("XRT_HAVE_SYSTEM_CJSON".into(), "NO".into());
cmake_vars.insert("CMAKE_LIBDIR".into(), format!("{}/lib", profile.prefix));
cmake_vars.insert("CMAKE_INSTALL_PREFIX".into(), profile.prefix.clone());
cmake_vars.insert(
"CMAKE_C_FLAGS".into(),
format!("-Wl,-rpath='{}/lib'", profile.prefix),
);
cmake_vars.insert(
"CMAKE_CXX_FLAGS".into(),
format!("-Wl,-rpath='{}/lib'", profile.prefix),
);
let cmake = Cmake {
env: Some(env),
vars: Some(cmake_vars),
source_dir: profile.xrservice_path.clone(),
build_dir,
};
runners.push(cmake.get_prepare_runner());
runners.push(cmake.get_build_runner());
runners.push(cmake.get_install_runner());
runners
}

View file

@ -1,23 +1,37 @@
use crate::{constants::pkg_data_dir, profile::Profile, runner::Runner};
use crate::{
build_tools::{cmake::Cmake, git::Git},
file_utils::rm_rf,
profile::Profile,
runner::Runner,
};
use std::collections::HashMap;
pub fn get_build_opencomposite_runner(profile: Profile) -> Runner {
let mut args = vec![
profile.opencomposite_path,
match profile.pull_on_build {
true => "1".into(),
false => "0".into(),
pub fn get_build_opencomposite_runners(profile: &Profile) -> Vec<Runner> {
let mut runners: Vec<Runner> = vec![];
let git = Git {
repo: match profile.opencomposite_repo.as_ref() {
Some(r) => r.clone(),
None => "https://gitlab.com/znixian/OpenOVR.git".into(),
},
];
if profile.opencomposite_repo.is_some() {
args.push(profile.opencomposite_repo.unwrap());
}
let runner = Runner::new(
None,
format!(
"{sysdata}/scripts/build_opencomposite.sh",
sysdata = pkg_data_dir()
),
args,
);
runner
dir: profile.opencomposite_path.clone(),
};
match git.clone_or_pull(profile) {
Some(r) => runners.push(r),
None => {}
};
let build_dir = format!("{}/build", profile.opencomposite_path);
rm_rf(&build_dir);
let mut cmake_vars: HashMap<String, String> = HashMap::new();
cmake_vars.insert("CMAKE_BUILD_TYPE".into(), "Release".into());
let cmake = Cmake {
env: None,
vars: Some(cmake_vars),
source_dir: profile.opencomposite_path.clone(),
build_dir,
};
runners.push(cmake.get_prepare_runner());
runners.push(cmake.get_build_runner());
runners
}

View file

@ -1,21 +1,42 @@
use crate::{constants::pkg_data_dir, profile::Profile, runner::Runner};
use crate::{
build_tools::{cmake::Cmake, git::Git},
file_utils::rm_rf,
profile::Profile,
runner::Runner,
};
use std::collections::HashMap;
pub fn get_build_wivrn_runner(profile: Profile) -> Runner {
let mut args = vec![
profile.xrservice_path,
profile.prefix,
match profile.pull_on_build {
true => "1".into(),
false => "0".into(),
pub fn get_build_wivrn_runners(profile: &Profile) -> Vec<Runner> {
let mut runners: Vec<Runner> = vec![];
let git = Git {
repo: match profile.xrservice_repo.as_ref() {
Some(r) => r.clone(),
None => "https://github.com/Meumeu/WiVRn".into(),
},
];
if profile.xrservice_repo.is_some() {
args.push(profile.xrservice_repo.unwrap());
}
let runner = Runner::new(
None,
format!("{sysdata}/scripts/build_wivrn.sh", sysdata = pkg_data_dir()),
args,
);
runner
dir: profile.xrservice_path.clone(),
};
match git.clone_or_pull(profile) {
Some(r) => runners.push(r),
None => {}
};
let build_dir = format!("{}/build", profile.xrservice_path);
rm_rf(&build_dir);
let mut cmake_vars: HashMap<String, String> = HashMap::new();
cmake_vars.insert("CMAKE_BUILD_TYPE".into(), "Release".into());
cmake_vars.insert("XRT_HAVE_SYSTEM_CJSON".into(), "NO".into());
cmake_vars.insert("WIVRN_BUILD_CLIENT".into(), "OFF".into());
cmake_vars.insert("CMAKE_INSTALL_PREFIX".into(), profile.prefix.clone());
let cmake = Cmake {
env: None,
vars: Some(cmake_vars),
source_dir: profile.xrservice_path.clone(),
build_dir,
};
runners.push(cmake.get_prepare_runner());
runners.push(cmake.get_build_runner());
runners.push(cmake.get_install_runner());
runners
}

View file

@ -4,11 +4,11 @@ use super::debug_view::{DebugView, DebugViewMsg};
use super::libsurvive_setup_window::LibsurviveSetupWindow;
use super::main_view::MainViewMsg;
use crate::builders::build_basalt::get_build_basalt_runner;
use crate::builders::build_libsurvive::get_build_libsurvive_runner;
use crate::builders::build_libsurvive::get_build_libsurvive_runners;
use crate::builders::build_mercury::get_build_mercury_runner;
use crate::builders::build_monado::get_build_monado_runner;
use crate::builders::build_opencomposite::get_build_opencomposite_runner;
use crate::builders::build_wivrn::get_build_wivrn_runner;
use crate::builders::build_monado::get_build_monado_runners;
use crate::builders::build_opencomposite::get_build_opencomposite_runners;
use crate::builders::build_wivrn::get_build_wivrn_runners;
use crate::config::Config;
use crate::constants::APP_NAME;
use crate::depcheck::check_dependency;
@ -346,11 +346,13 @@ impl SimpleComponent for App {
RunnerStatus::Stopped(_) => {}
RunnerStatus::Running => {
if self.xrservice_runner.is_some() {
if self.xrservice_runner.as_mut().unwrap().status() == RunnerStatus::Running {
if self.xrservice_runner.as_mut().unwrap().status()
== RunnerStatus::Running
{
self.xrservice_runner.as_mut().unwrap().terminate();
}
}
},
}
},
}
self.start_xrservice();
@ -367,23 +369,23 @@ impl SimpleComponent for App {
});
if profile.features.libsurvive.enabled {
missing_deps.extend(get_missing_libsurvive_deps());
runners.push(get_build_libsurvive_runner(profile.clone()));
runners.extend(get_build_libsurvive_runners(&profile));
}
if profile.features.basalt.enabled {
missing_deps.extend(get_missing_basalt_deps());
runners.push(get_build_basalt_runner(profile.clone()));
runners.push(get_build_basalt_runner(&profile));
}
if profile.features.mercury_enabled {
missing_deps.extend(get_missing_mercury_deps());
runners.push(get_build_mercury_runner(profile.clone()));
runners.push(get_build_mercury_runner(&profile));
}
runners.push(match profile.xrservice_type {
XRServiceType::Monado => get_build_monado_runner(profile.clone()),
XRServiceType::Wivrn => get_build_wivrn_runner(profile.clone()),
runners.extend(match profile.xrservice_type {
XRServiceType::Monado => get_build_monado_runners(&profile),
XRServiceType::Wivrn => get_build_wivrn_runners(&profile),
});
// no listed deps for opencomp
}
runners.push(get_build_opencomposite_runner(profile.clone()));
runners.extend(get_build_opencomposite_runners(&profile));
if !missing_deps.is_empty() {
missing_deps.sort_unstable();
missing_deps.dedup(); // dedup only works if sorted, hence the above