feat: debug build and run options

This commit is contained in:
Gabriele Musco 2023-10-08 00:06:44 +02:00
commit 5778b9e979
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE
6 changed files with 125 additions and 33 deletions

View file

@ -9,7 +9,11 @@ use std::{
path::Path, path::Path,
}; };
pub fn get_build_monado_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> { pub fn get_build_monado_jobs(
profile: &Profile,
clean_build: bool,
debug_build: bool,
) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new(); let mut jobs = VecDeque::<WorkerJob>::new();
let git = Git { let git = Git {
@ -39,17 +43,36 @@ pub fn get_build_monado_jobs(profile: &Profile, clean_build: bool) -> VecDeque<W
format!("{}/lib/pkgconfig", profile.prefix), format!("{}/lib/pkgconfig", profile.prefix),
); );
let mut cmake_vars: HashMap<String, String> = HashMap::new(); let mut cmake_vars: HashMap<String, String> = HashMap::new();
cmake_vars.insert("CMAKE_BUILD_TYPE".into(), "Release".into()); cmake_vars.insert(
"CMAKE_BUILD_TYPE".into(),
(if debug_build { "Debug" } else { "Release" }).into(),
);
cmake_vars.insert("XRT_HAVE_SYSTEM_CJSON".into(), "NO".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_LIBDIR".into(), format!("{}/lib", profile.prefix));
cmake_vars.insert("CMAKE_INSTALL_PREFIX".into(), profile.prefix.clone()); cmake_vars.insert("CMAKE_INSTALL_PREFIX".into(), profile.prefix.clone());
cmake_vars.insert( cmake_vars.insert(
"CMAKE_C_FLAGS".into(), "CMAKE_C_FLAGS".into(),
format!("-Wl,-rpath='{}/lib'", profile.prefix), format!(
"-Wl,-rpath='{}/lib'{}",
profile.prefix,
if debug_build {
" -g -march=native -O3 -fno-omit-frame-pointer"
} else {
""
}
),
); );
cmake_vars.insert( cmake_vars.insert(
"CMAKE_CXX_FLAGS".into(), "CMAKE_CXX_FLAGS".into(),
format!("-Wl,-rpath='{}/lib'", profile.prefix), format!(
"-Wl,-rpath='{}/lib'{}",
profile.prefix,
if debug_build {
" -g -march=native -O3 -fno-omit-frame-pointer"
} else {
""
}
),
); );
profile.xrservice_cmake_flags.iter().for_each(|(k, v)| { profile.xrservice_cmake_flags.iter().for_each(|(k, v)| {
if k == "CMAKE_C_FLAGS" || k == "CMAKE_CXX_FLAGS" { if k == "CMAKE_C_FLAGS" || k == "CMAKE_CXX_FLAGS" {

View file

@ -9,7 +9,11 @@ use std::{
path::Path, path::Path,
}; };
pub fn get_build_wivrn_jobs(profile: &Profile, clean_build: bool) -> VecDeque<WorkerJob> { pub fn get_build_wivrn_jobs(
profile: &Profile,
clean_build: bool,
debug_build: bool,
) -> VecDeque<WorkerJob> {
let mut jobs = VecDeque::<WorkerJob>::new(); let mut jobs = VecDeque::<WorkerJob>::new();
let git = Git { let git = Git {
@ -35,17 +39,33 @@ pub fn get_build_wivrn_jobs(profile: &Profile, clean_build: bool) -> VecDeque<Wo
let build_dir = format!("{}/build", profile.xrservice_path); let build_dir = format!("{}/build", profile.xrservice_path);
let mut cmake_vars: HashMap<String, String> = HashMap::new(); let mut cmake_vars: HashMap<String, String> = HashMap::new();
cmake_vars.insert("CMAKE_BUILD_TYPE".into(), "Release".into()); cmake_vars.insert(
"CMAKE_BUILD_TYPE".into(),
(if debug_build { "Debug" } else { "Release" }).into(),
);
cmake_vars.insert("XRT_HAVE_SYSTEM_CJSON".into(), "NO".into()); cmake_vars.insert("XRT_HAVE_SYSTEM_CJSON".into(), "NO".into());
cmake_vars.insert("WIVRN_BUILD_CLIENT".into(), "OFF".into()); cmake_vars.insert("WIVRN_BUILD_CLIENT".into(), "OFF".into());
cmake_vars.insert("CMAKE_INSTALL_PREFIX".into(), profile.prefix.clone()); cmake_vars.insert("CMAKE_INSTALL_PREFIX".into(), profile.prefix.clone());
profile.xrservice_cmake_flags.iter().for_each(|(k, v)| {
if k == "CMAKE_C_FLAGS" || k == "CMAKE_CXX_FLAGS" { if debug_build {
cmake_vars.insert(k.clone(), format!("{} {}", cmake_vars.get(k).unwrap(), v)); for k in ["CMAKE_C_FLAGS", "CMAKE_CXX_FLAGS"] {
} else { cmake_vars.insert(
cmake_vars.insert(k.clone(), v.clone()); k.into(),
"-g -march=native -O3 -fno-omit-frame-pointer".into(),
);
} }
}); profile.xrservice_cmake_flags.iter().for_each(|(k, v)| {
if k == "CMAKE_C_FLAGS" || k == "CMAKE_CXX_FLAGS" {
cmake_vars.insert(k.clone(), format!("{} {}", cmake_vars.get(k).unwrap(), v));
} else {
cmake_vars.insert(k.clone(), v.clone());
}
});
} else {
profile.xrservice_cmake_flags.iter().for_each(|(k, v)| {
cmake_vars.insert(k.clone(), v.clone());
});
}
let cmake = Cmake { let cmake = Cmake {
env: None, env: None,

View file

@ -108,10 +108,11 @@ pub enum Msg {
OnBuildLog(Vec<String>), OnBuildLog(Vec<String>),
OnBuildExit(i32), OnBuildExit(i32),
ClockTicking, ClockTicking,
BuildProfile(bool), BuildProfile(bool, bool),
CancelBuild, CancelBuild,
EnableDebugViewChanged(bool), EnableDebugViewChanged(bool),
DoStartStopXRService, DoStartStopXRService,
StartWithDebug,
RestartXRService, RestartXRService,
ProfileSelected(Profile), ProfileSelected(Profile),
DeleteProfile, DeleteProfile,
@ -148,7 +149,7 @@ impl App {
} }
} }
pub fn start_xrservice(&mut self, sender: ComponentSender<Self>) { pub fn start_xrservice(&mut self, sender: ComponentSender<Self>, debug: bool) {
let prof = self.get_selected_profile(); let prof = self.get_selected_profile();
if set_current_active_runtime_to_profile(&prof).is_err() { if set_current_active_runtime_to_profile(&prof).is_err() {
alert( alert(
@ -179,6 +180,7 @@ impl App {
JobWorkerOut::Log(rows) => Msg::OnServiceLog(rows), JobWorkerOut::Log(rows) => Msg::OnServiceLog(rows),
JobWorkerOut::Exit(code) => Msg::OnServiceExit(code), JobWorkerOut::Exit(code) => Msg::OnServiceExit(code),
}, },
debug
); );
worker.start(); worker.start();
self.xrservice_worker = Some(worker); self.xrservice_worker = Some(worker);
@ -324,7 +326,7 @@ impl SimpleComponent for App {
self.xrservice_worker = None; self.xrservice_worker = None;
if self.restart_xrservice { if self.restart_xrservice {
self.restart_xrservice = false; self.restart_xrservice = false;
self.start_xrservice(sender); self.start_xrservice(sender, false);
} }
} }
Msg::ClockTicking => { Msg::ClockTicking => {
@ -388,21 +390,24 @@ impl SimpleComponent for App {
} }
Msg::DoStartStopXRService => match &mut self.xrservice_worker { Msg::DoStartStopXRService => match &mut self.xrservice_worker {
None => { None => {
self.start_xrservice(sender); self.start_xrservice(sender, false);
} }
Some(_) => { Some(_) => {
self.shutdown_xrservice(); self.shutdown_xrservice();
} }
}, },
Msg::StartWithDebug => {
self.start_xrservice(sender, true)
}
Msg::RestartXRService => match &mut self.xrservice_worker { Msg::RestartXRService => match &mut self.xrservice_worker {
None => { None => {
self.start_xrservice(sender); self.start_xrservice(sender, false);
} }
Some(worker) => { Some(worker) => {
let status = worker.state.lock().unwrap().exit_status.clone(); let status = worker.state.lock().unwrap().exit_status.clone();
match status { match status {
Some(_) => { Some(_) => {
self.start_xrservice(sender); self.start_xrservice(sender, false);
} }
None => { None => {
self.shutdown_xrservice(); self.shutdown_xrservice();
@ -411,7 +416,7 @@ impl SimpleComponent for App {
} }
} }
}, },
Msg::BuildProfile(clean_build) => { Msg::BuildProfile(clean_build, debug_build) => {
let profile = self.get_selected_profile(); let profile = self.get_selected_profile();
let mut missing_deps = vec![]; let mut missing_deps = vec![];
let mut jobs = VecDeque::<WorkerJob>::new(); let mut jobs = VecDeque::<WorkerJob>::new();
@ -438,8 +443,8 @@ impl SimpleComponent for App {
jobs.push_back(get_build_mercury_job(&profile)); jobs.push_back(get_build_mercury_job(&profile));
} }
jobs.extend(match profile.xrservice_type { jobs.extend(match profile.xrservice_type {
XRServiceType::Monado => get_build_monado_jobs(&profile, clean_build), XRServiceType::Monado => get_build_monado_jobs(&profile, clean_build, debug_build),
XRServiceType::Wivrn => get_build_wivrn_jobs(&profile, clean_build), XRServiceType::Wivrn => get_build_wivrn_jobs(&profile, clean_build, debug_build),
}); });
// no listed deps for opencomp // no listed deps for opencomp
} }
@ -650,6 +655,7 @@ impl SimpleComponent for App {
.forward(sender.input_sender(), |message| match message { .forward(sender.input_sender(), |message| match message {
MainViewOutMsg::EnableDebugViewChanged(val) => Msg::EnableDebugViewChanged(val), MainViewOutMsg::EnableDebugViewChanged(val) => Msg::EnableDebugViewChanged(val),
MainViewOutMsg::DoStartStopXRService => Msg::DoStartStopXRService, MainViewOutMsg::DoStartStopXRService => Msg::DoStartStopXRService,
MainViewOutMsg::StartWithDebug => Msg::StartWithDebug,
MainViewOutMsg::RestartXRService => Msg::RestartXRService, MainViewOutMsg::RestartXRService => Msg::RestartXRService,
MainViewOutMsg::ProfileSelected(uuid) => Msg::ProfileSelected(uuid), MainViewOutMsg::ProfileSelected(uuid) => Msg::ProfileSelected(uuid),
MainViewOutMsg::DeleteProfile => Msg::DeleteProfile, MainViewOutMsg::DeleteProfile => Msg::DeleteProfile,
@ -696,13 +702,25 @@ impl SimpleComponent for App {
{ {
withclones![sender]; withclones![sender];
stateless_action!(actions, BuildProfileAction, { stateless_action!(actions, BuildProfileAction, {
sender.input_sender().emit(Msg::BuildProfile(false)); sender.input_sender().emit(Msg::BuildProfile(false, false));
}); });
} }
{ {
withclones![sender]; withclones![sender];
stateless_action!(actions, BuildProfileCleanAction, { stateless_action!(actions, BuildProfileCleanAction, {
sender.input_sender().emit(Msg::BuildProfile(true)); sender.input_sender().emit(Msg::BuildProfile(true, false));
});
}
{
withclones![sender];
stateless_action!(actions, BuildProfileDebugAction, {
sender.input_sender().emit(Msg::BuildProfile(false, true));
});
}
{
withclones![sender];
stateless_action!(actions, BuildProfileCleanDebugAction, {
sender.input_sender().emit(Msg::BuildProfile(true, true));
}); });
} }
{ {
@ -767,6 +785,8 @@ new_action_group!(pub AppActionGroup, "win");
new_stateless_action!(pub AboutAction, AppActionGroup, "about"); new_stateless_action!(pub AboutAction, AppActionGroup, "about");
new_stateless_action!(pub BuildProfileAction, AppActionGroup, "buildprofile"); new_stateless_action!(pub BuildProfileAction, AppActionGroup, "buildprofile");
new_stateless_action!(pub BuildProfileCleanAction, AppActionGroup, "buildprofileclean"); new_stateless_action!(pub BuildProfileCleanAction, AppActionGroup, "buildprofileclean");
new_stateless_action!(pub BuildProfileDebugAction, AppActionGroup, "buildprofiledebug");
new_stateless_action!(pub BuildProfileCleanDebugAction, AppActionGroup, "buildprofilecleandebug");
new_stateless_action!(pub ConfigFbtAction, AppActionGroup, "configfbt"); new_stateless_action!(pub ConfigFbtAction, AppActionGroup, "configfbt");
new_stateless_action!(pub QuitAction, AppActionGroup, "quit"); new_stateless_action!(pub QuitAction, AppActionGroup, "quit");
new_stateful_action!(pub DebugViewToggleAction, AppActionGroup, "debugviewtoggle", (), bool); new_stateful_action!(pub DebugViewToggleAction, AppActionGroup, "debugviewtoggle", (), bool);

View file

@ -157,6 +157,7 @@ impl InternalJobWorker {
pub fn xrservice_worker_from_profile( pub fn xrservice_worker_from_profile(
prof: &Profile, prof: &Profile,
state: Arc<Mutex<JobWorkerState>>, state: Arc<Mutex<JobWorkerState>>,
debug: bool,
) -> relm4::WorkerHandle<InternalJobWorker> { ) -> relm4::WorkerHandle<InternalJobWorker> {
let mut env = prof.environment.clone(); let mut env = prof.environment.clone();
if !env.contains_key("LH_DRIVER") { if !env.contains_key("LH_DRIVER") {
@ -165,7 +166,18 @@ impl InternalJobWorker {
prof.lighthouse_driver.to_string().to_lowercase(), prof.lighthouse_driver.to_string().to_lowercase(),
); );
} }
let launch_opts = prof.xrservice_launch_options.trim(); let mut launch_opts = prof.xrservice_launch_options.trim();
let debug_launch_opts = if debug {
if launch_opts.contains(LAUNCH_OPTS_CMD_PLACEHOLDER) {
format!("{} {}", "gdb -batch -ex run -ex bt --args", launch_opts)
} else {
format!(
"{} {} {}",
"gdb -batch -ex run -ex bt --args", LAUNCH_OPTS_CMD_PLACEHOLDER, launch_opts
)
}
} else {String::default()};
launch_opts = if debug { debug_launch_opts.as_str() } else { launch_opts };
let (command, args) = match launch_opts.is_empty() { let (command, args) = match launch_opts.is_empty() {
false => ( false => (
"sh".into(), "sh".into(),

View file

@ -48,10 +48,11 @@ impl JobWorker {
prof: &Profile, prof: &Profile,
sender: &Sender<X>, sender: &Sender<X>,
transform: F, transform: F,
debug: bool
) -> Self { ) -> Self {
let state = Arc::new(Mutex::new(JobWorkerState::default())); let state = Arc::new(Mutex::new(JobWorkerState::default()));
Self { Self {
worker: InternalJobWorker::xrservice_worker_from_profile(prof, state.clone()) worker: InternalJobWorker::xrservice_worker_from_profile(prof, state.clone(), debug)
.forward(sender, transform), .forward(sender, transform),
state, state,
} }

View file

@ -13,8 +13,8 @@ use crate::gpu_profile::{
use crate::profile::{LighthouseDriver, Profile}; use crate::profile::{LighthouseDriver, Profile};
use crate::steamvr_utils::chaperone_info_exists; use crate::steamvr_utils::chaperone_info_exists;
use crate::ui::app::{ use crate::ui::app::{
AboutAction, BuildProfileAction, BuildProfileCleanAction, ConfigFbtAction, AboutAction, BuildProfileAction, BuildProfileCleanAction, BuildProfileCleanDebugAction,
DebugViewToggleAction, BuildProfileDebugAction, ConfigFbtAction, DebugViewToggleAction,
}; };
use crate::ui::profile_editor::ProfileEditorInit; use crate::ui::profile_editor::ProfileEditorInit;
use crate::ui::util::{limit_dropdown_width, warning_heading}; use crate::ui::util::{limit_dropdown_width, warning_heading};
@ -54,6 +54,7 @@ pub struct MainView {
pub enum MainViewMsg { pub enum MainViewMsg {
ClockTicking, ClockTicking,
StartStopClicked, StartStopClicked,
StartWithDebug,
RestartXRService, RestartXRService,
XRServiceActiveChanged(bool, Option<Profile>), XRServiceActiveChanged(bool, Option<Profile>),
EnableDebugViewChanged(bool), EnableDebugViewChanged(bool),
@ -73,6 +74,7 @@ pub enum MainViewMsg {
pub enum MainViewOutMsg { pub enum MainViewOutMsg {
EnableDebugViewChanged(bool), EnableDebugViewChanged(bool),
DoStartStopXRService, DoStartStopXRService,
StartWithDebug,
RestartXRService, RestartXRService,
ProfileSelected(Profile), ProfileSelected(Profile),
DeleteProfile, DeleteProfile,
@ -116,6 +118,10 @@ impl SimpleComponent for MainView {
"C_lean Build Profile" => BuildProfileCleanAction, "C_lean Build Profile" => BuildProfileCleanAction,
"Configure Full Body _Tracking" => ConfigFbtAction, "Configure Full Body _Tracking" => ConfigFbtAction,
}, },
section! {
"Build Profile with Debug Symbols" => BuildProfileDebugAction,
"Clean Build Profile with Debug Symbols" => BuildProfileCleanDebugAction,
},
section! { section! {
"_About" => AboutAction, "_About" => AboutAction,
} }
@ -155,14 +161,13 @@ impl SimpleComponent for MainView {
set_margin_all: 12, set_margin_all: 12,
set_orientation: gtk::Orientation::Vertical, set_orientation: gtk::Orientation::Vertical,
gtk::Box { gtk::Box {
set_halign: gtk::Align::Center, set_hexpand: true,
set_orientation: gtk::Orientation::Horizontal, set_orientation: gtk::Orientation::Horizontal,
set_spacing: 12, add_css_class: "linked",
gtk::Button { gtk::Button {
add_css_class: "pill",
add_css_class: "suggested-action", add_css_class: "suggested-action",
add_css_class: "destructive-action", add_css_class: "destructive-action",
set_halign: gtk::Align::Center, set_hexpand: true,
#[track = "model.changed(Self::xrservice_active())"] #[track = "model.changed(Self::xrservice_active())"]
set_class_active: ("suggested-action", !model.xrservice_active), set_class_active: ("suggested-action", !model.xrservice_active),
#[track = "model.changed(Self::xrservice_active())"] #[track = "model.changed(Self::xrservice_active())"]
@ -175,8 +180,14 @@ impl SimpleComponent for MainView {
}, },
}, },
gtk::Button { gtk::Button {
add_css_class: "circular", set_label: "Start with GDB",
add_css_class: "flat", #[track = "model.changed(Self::xrservice_active()) || model.changed(Self::enable_debug_view())"]
set_visible: model.enable_debug_view && !model.xrservice_active,
connect_clicked[sender] => move |_| {
sender.input(MainViewMsg::StartWithDebug);
},
},
gtk::Button {
set_halign: gtk::Align::Center, set_halign: gtk::Align::Center,
set_valign: gtk::Align::Center, set_valign: gtk::Align::Center,
set_icon_name: "view-refresh-symbolic", set_icon_name: "view-refresh-symbolic",
@ -445,6 +456,11 @@ impl SimpleComponent for MainView {
.output(Self::Output::DoStartStopXRService) .output(Self::Output::DoStartStopXRService)
.expect("Sender output failed"); .expect("Sender output failed");
} }
Self::Input::StartWithDebug => {
sender
.output(Self::Output::StartWithDebug)
.expect("Sender output failed");
}
Self::Input::RestartXRService => { Self::Input::RestartXRService => {
sender sender
.output(Self::Output::RestartXRService) .output(Self::Output::RestartXRService)