diff --git a/src/builders/build_vapor.rs b/src/builders/build_vapor.rs new file mode 100644 index 0000000..10206fe --- /dev/null +++ b/src/builders/build_vapor.rs @@ -0,0 +1,85 @@ +use crate::{ + build_tools::{cmake::Cmake, git::Git}, + profile::Profile, + termcolor::TermColor, + ui::job_worker::job::{FuncWorkerData, FuncWorkerOut, WorkerJob}, + util::file_utils::{copy_file, rm_rf}, +}; +use std::{ + collections::{HashMap, VecDeque}, + fs::create_dir_all, + path::Path, +}; + +pub fn get_build_vapor_jobs(profile: &Profile, clean_build: bool) -> VecDeque { + let mut jobs = VecDeque::::new(); + jobs.push_back(WorkerJob::new_printer( + "Building VapoR...", + Some(TermColor::Blue), + )); + + let git = Git { + repo: profile + .ovr_comp + .repo + .as_ref() + .unwrap_or(&"https://github.com/micheal65536/VapoR.git".into()) + .clone(), + dir: profile.ovr_comp.path.clone(), + branch: profile + .ovr_comp + .branch + .as_ref() + .unwrap_or(&"master".into()) + .clone(), + }; + + jobs.extend(git.get_pre_build_jobs(profile.pull_on_build)); + + let build_dir = profile.ovr_comp.path.join("build"); + let cmake = Cmake { + env: None, + vars: Some({ + let mut cmake_vars: HashMap = HashMap::new(); + for (k, v) in [ + ("VAPOR_LOG_SILENT=ON", "ON"), + ("CMAKE_BUILD_TYPE", "RelWithDebInfo"), + ] { + cmake_vars.insert(k.to_string(), v.to_string()); + } + cmake_vars + }), + source_dir: profile.ovr_comp.path.clone(), + build_dir: build_dir.clone(), + }; + if !Path::new(&build_dir).is_dir() || clean_build { + rm_rf(&build_dir); + jobs.push_back(cmake.get_prepare_job()); + } + jobs.push_back(cmake.get_build_job()); + jobs.push_back(WorkerJob::Func(FuncWorkerData { + func: Box::new(move || { + let dest_dir = build_dir.join("bin/linux64"); + if let Err(e) = create_dir_all(&dest_dir) { + return FuncWorkerOut { + success: false, + out: vec![format!( + "failed to create dir {}: {e}", + dest_dir.to_string_lossy() + )], + }; + } + copy_file( + &build_dir.join("src/vrclient.so"), + &dest_dir.join("vrclient.so"), + ); + + FuncWorkerOut { + success: true, + out: Vec::default(), + } + }), + })); + + jobs +} diff --git a/src/builders/mod.rs b/src/builders/mod.rs index 1f66748..9d57245 100644 --- a/src/builders/mod.rs +++ b/src/builders/mod.rs @@ -4,5 +4,6 @@ pub mod build_mercury; pub mod build_monado; pub mod build_opencomposite; pub mod build_openhmd; +pub mod build_vapor; pub mod build_wivrn; pub mod build_xrizer; diff --git a/src/profile.rs b/src/profile.rs index ad6b170..7433de9 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -265,6 +265,7 @@ pub enum OvrCompatibilityModuleType { #[default] Opencomposite, Xrizer, + Vapor, } impl Display for OvrCompatibilityModuleType { @@ -272,13 +273,14 @@ impl Display for OvrCompatibilityModuleType { f.write_str(match self { Self::Opencomposite => "OpenComposite", Self::Xrizer => "xrizer", + Self::Vapor => "VapoR", }) } } impl OvrCompatibilityModuleType { pub fn iter() -> Iter<'static, Self> { - [Self::Opencomposite, Self::Xrizer].iter() + [Self::Opencomposite, Self::Xrizer, Self::Vapor].iter() } } @@ -289,6 +291,7 @@ impl FromStr for OvrCompatibilityModuleType { match s.to_lowercase().trim() { "opencomposite" => Ok(Self::Opencomposite), "xrizer" => Ok(Self::Xrizer), + "vapor" => Ok(Self::Vapor), _ => Err(format!("no match for ovr compatibility module `{s}`")), } } @@ -299,7 +302,8 @@ impl From for OvrCompatibilityModuleType { match value { 0 => Self::Opencomposite, 1 => Self::Xrizer, - _ => panic!("OvrCompatibilityModuleType index out of bounds"), + 2 => Self::Vapor, + _ => panic!("OvrCompatibilityModuleType index out of bounds"), } } } @@ -327,7 +331,9 @@ impl ProfileOvrCompatibilityModule { /// this should correspond to the build output directory pub fn runtime_dir(&self) -> PathBuf { match self.mod_type { - OvrCompatibilityModuleType::Opencomposite => self.path.join("build"), + OvrCompatibilityModuleType::Opencomposite | OvrCompatibilityModuleType::Vapor => { + self.path.join("build") + } OvrCompatibilityModuleType::Xrizer => self.path.join("target/release"), } } diff --git a/src/ui/app.rs b/src/ui/app.rs index 5df4dba..9910d2d 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -20,7 +20,8 @@ use crate::{ build_basalt::get_build_basalt_jobs, build_libsurvive::get_build_libsurvive_jobs, build_mercury::get_build_mercury_jobs, build_monado::get_build_monado_jobs, build_opencomposite::get_build_opencomposite_jobs, build_openhmd::get_build_openhmd_jobs, - build_wivrn::get_build_wivrn_jobs, build_xrizer::get_build_xrizer_jobs, + build_vapor::get_build_vapor_jobs, build_wivrn::get_build_wivrn_jobs, + build_xrizer::get_build_xrizer_jobs, }, config::{Config, PluginConfig}, constants::APP_NAME, @@ -533,6 +534,9 @@ impl AsyncComponent for App { OvrCompatibilityModuleType::Xrizer => { get_build_xrizer_jobs(&profile, clean_build) } + OvrCompatibilityModuleType::Vapor => { + get_build_vapor_jobs(&profile, clean_build) + } }); let missing_deps = profile.missing_dependencies(); if !(self.skip_depcheck || profile.skip_dependency_check || missing_deps.is_empty())