feat: cmake rust helper

This commit is contained in:
Gabriele Musco 2023-07-16 08:12:25 +00:00
parent 4fb3d37551
commit a2b5057931
4 changed files with 37 additions and 9 deletions

35
src/build_tools/cmake.rs Normal file
View file

@ -0,0 +1,35 @@
use std::collections::HashMap;
use crate::runner::Runner;
#[derive(Debug, Clone)]
pub struct Cmake {
pub build_dir: String,
pub source_dir: String,
pub vars: Option<HashMap<String, String>>,
pub env: Option<HashMap<String, String>>,
}
impl Cmake {
pub fn get_prepare_runner(&self) -> Runner {
let mut args = vec![
"-B".into(), self.build_dir.clone(),
"-G".into(), "Ninja".into(),
];
if self.vars.is_some() {
for (k, v) in self.vars.as_ref().unwrap() {
if k.contains(" ") {
panic!("Cmake vars cannot contain spaces!");
}
args.push(format!("-D{k}=\"{v}\"", k=k, v=v));
}
}
args.push(self.source_dir.clone());
Runner::new(self.env.clone(), "cmake".into(), args)
}
pub fn get_build_runner(&self) -> Runner {
Runner::new(self.env.clone(), "cmake".into(), vec![
"--build".into(), self.build_dir.clone()
])
}
}

1
src/build_tools/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod cmake;

View file

@ -32,6 +32,7 @@ pub mod runner;
pub mod runner_pipeline;
pub mod ui;
pub mod xr_devices;
pub mod build_tools;
fn restore_steam_xr_files() {
let active_runtime = get_current_active_runtime();

View file

@ -103,15 +103,6 @@ pub enum Msg {
}
impl App {
fn get_profile_by_name(&self, name: &String) -> Option<&Profile> {
for profile in &self.profiles {
if &profile.name == name {
return Some(profile);
}
}
return None;
}
pub fn get_selected_profile(&self) -> Profile {
self.config.get_selected_profile(&self.profiles)
}