diff --git a/Cargo.toml b/Cargo.toml index 92010836f3..2c68587798 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,8 @@ alvr_events = { path = "alvr/events" } alvr_filesystem = { path = "alvr/filesystem" } alvr_server_data = { path = "alvr/server_data" } alvr_session = { path = "alvr/session" } -alvr_sockets = { path = "alvr/sockets" } \ No newline at end of file +alvr_sockets = { path = "alvr/sockets" } + +[profile.distribution] +inherits = "release" +lto = true diff --git a/alvr/xtask/src/build.rs b/alvr/xtask/src/build.rs index f82f57433f..9f2b8badf3 100644 --- a/alvr/xtask/src/build.rs +++ b/alvr/xtask/src/build.rs @@ -1,9 +1,28 @@ use crate::{command, dependencies, version}; use alvr_filesystem::{self as afs, Layout}; +use std::fmt::{self, Display, Formatter}; use xshell::{cmd, Shell}; +#[derive(Clone, Copy)] +pub enum Profile { + Debug, + Release, + Distribution, +} + +impl Display for Profile { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + let string = match self { + Profile::Distribution => "distribution", + Profile::Release => "release", + Profile::Debug => "debug", + }; + write!(f, "{string}") + } +} + pub fn build_server( - is_release: bool, + profile: Profile, gpl: bool, root: Option, reproducible: bool, @@ -14,11 +33,14 @@ pub fn build_server( let build_layout = Layout::new(&afs::server_build_dir()); - let build_type = if is_release { "release" } else { "debug" }; - let mut common_flags = vec![]; - if is_release { - common_flags.push("--release"); + match profile { + Profile::Distribution => { + common_flags.push("--profile"); + common_flags.push("distribution"); + } + Profile::Release => common_flags.push("--release"), + Profile::Debug => (), } if reproducible { common_flags.push("--locked"); @@ -29,7 +51,7 @@ pub fn build_server( .then(|| vec!["--features", if gpl { "gpl" } else { "local_ffmpeg" }]) .unwrap_or_default(); - let artifacts_dir = afs::target_dir().join(build_type); + let artifacts_dir = afs::target_dir().join(profile.to_string()); sh.remove_path(&afs::server_build_dir()).unwrap(); sh.create_dir(&afs::server_build_dir()).unwrap(); @@ -204,15 +226,20 @@ pub fn build_server( } } -pub fn build_client_lib(is_release: bool) { +pub fn build_client_lib(profile: Profile) { let sh = Shell::new().unwrap(); let build_dir = afs::build_dir().join("alvr_client_core"); sh.create_dir(&build_dir).unwrap(); let mut flags = vec![]; - if is_release { - flags.push("--release"); + match profile { + Profile::Distribution => { + flags.push("--profile"); + flags.push("distribution") + } + Profile::Release => flags.push("--release"), + Profile::Debug => (), } let flags_ref = &flags; @@ -229,18 +256,16 @@ pub fn build_client_lib(is_release: bool) { cmd!(sh, "cbindgen --output {out}").run().unwrap(); } -pub fn build_quest_client(is_release: bool) { +pub fn build_quest_client(profile: Profile) { let sh = Shell::new().unwrap(); - build_client_lib(is_release); + build_client_lib(profile); let is_nightly = version::version().contains("nightly"); - let is_release = if is_nightly { false } else { is_release }; let package_type = if is_nightly { "Nightly" } else { "Stable" }; - let build_type = if is_release { "release" } else { "debug" }; - let build_task = format!("assemble{package_type}{build_type}"); + let build_task = format!("assemble{package_type}{profile}"); let client_dir = afs::workspace_dir().join("android"); @@ -259,8 +284,8 @@ pub fn build_quest_client(is_release: bool) { client_dir .join("app/build/outputs/apk") .join(package_type) - .join(build_type) - .join(format!("app-{package_type}-{build_type}.apk")), + .join(profile.to_string()) + .join(format!("app-{package_type}-{profile}.apk")), afs::build_dir() .join(ARTIFACT_NAME) .join(format!("{ARTIFACT_NAME}.apk")), diff --git a/alvr/xtask/src/main.rs b/alvr/xtask/src/main.rs index f873f94621..2168acbc91 100644 --- a/alvr/xtask/src/main.rs +++ b/alvr/xtask/src/main.rs @@ -4,6 +4,7 @@ mod dependencies; mod packaging; mod version; +use crate::build::Profile; use afs::Layout; use alvr_filesystem as afs; use pico_args::Arguments; @@ -33,7 +34,7 @@ SUBCOMMANDS: FLAGS: --help Print this text --no-nvidia Disables nVidia support on Linux. For prepare-deps subcommand - --release Optimized build without debug info. For build subcommands + --release Optimized build with less debug checks. For build subcommands --gpl Bundle GPL libraries. For build subcommands --experiments Build unfinished features. For build subcommands --local-ffmpeg Use local build of ffmpeg in non GPL build. For build subcommands @@ -138,6 +139,11 @@ fn main() { } else if let Ok(Some(subcommand)) = args.subcommand() { let no_nvidia = args.contains("--no-nvidia"); let is_release = args.contains("--release"); + let profile = if is_release { + Profile::Release + } else { + Profile::Debug + }; let gpl = args.contains("--gpl"); let experiments = args.contains("--experiments"); let is_nightly = args.contains("--nightly"); @@ -174,27 +180,20 @@ fn main() { } } "build-server" => { - build::build_server(is_release, gpl, None, false, experiments, local_ffmpeg) + build::build_server(profile, gpl, None, false, experiments, local_ffmpeg) } - "build-client" => build::build_quest_client(is_release), - "build-client-lib" => build::build_client_lib(is_release), + "build-client" => build::build_quest_client(profile), + "build-client-lib" => build::build_client_lib(profile), "run-server" => { if !no_rebuild { - build::build_server( - is_release, - gpl, - None, - false, - experiments, - local_ffmpeg, - ); + build::build_server(profile, gpl, None, false, experiments, local_ffmpeg); } run_server(); } "package-server" => { packaging::package_server(root, gpl, local_ffmpeg, appimage, zsync) } - "package-client" => build::build_quest_client(true), + "package-client" => build::build_quest_client(Profile::Distribution), "package-client-lib" => packaging::package_client_lib(), "clean" => clean(), "bump" => version::bump_version(version, is_nightly), diff --git a/alvr/xtask/src/packaging.rs b/alvr/xtask/src/packaging.rs index 9cca314b55..86d5478f9d 100644 --- a/alvr/xtask/src/packaging.rs +++ b/alvr/xtask/src/packaging.rs @@ -1,4 +1,7 @@ -use crate::{build, command, version}; +use crate::{ + build::{self, Profile}, + command, version, +}; use alvr_filesystem as afs; use std::path::PathBuf; use xshell::{cmd, Shell}; @@ -53,7 +56,7 @@ pub fn package_server( ) { let sh = Shell::new().unwrap(); - build::build_server(true, gpl, root, true, false, local_ffmpeg); + build::build_server(Profile::Distribution, gpl, root, true, false, local_ffmpeg); // Add licenses let licenses_dir = afs::server_build_dir().join("licenses"); @@ -90,7 +93,9 @@ pub fn package_server( command::zip(&sh, &afs::server_build_dir()).unwrap(); sh.copy_file( - afs::target_dir().join("release").join("alvr_server.pdb"), + afs::target_dir() + .join(Profile::Distribution.to_string()) + .join("alvr_server.pdb"), afs::build_dir(), ) .unwrap(); @@ -187,7 +192,7 @@ pub fn server_appimage(release: bool, gpl: bool, update: bool) { pub fn package_client_lib() { let sh = Shell::new().unwrap(); - build::build_client_lib(true); + build::build_client_lib(Profile::Distribution); command::zip(&sh, &afs::build_dir().join("alvr_client_core")).unwrap(); }