make debug build of fullstack applications load faster by default

This commit is contained in:
Evan Almloff 2023-10-10 14:23:58 -05:00
parent 426a342700
commit b26985ea6c
3 changed files with 75 additions and 0 deletions

View file

@ -1,5 +1,7 @@
#[cfg(feature = "plugin")]
use crate::plugin::PluginManager;
use crate::server::fullstack::FullstackServerEnvGuard;
use crate::server::fullstack::FullstackWebEnvGuard;
use crate::{cfg::Platform, WebAssetConfigDropGuard};
use super::*;
@ -60,6 +62,7 @@ impl Build {
}
None => web_config.features = Some(vec![web_feature]),
};
let _gaurd = FullstackWebEnvGuard::new(self.build.debug);
crate::builder::build(&crate_config, false, self.build.skip_assets)?;
}
{
@ -72,6 +75,7 @@ impl Build {
}
None => desktop_config.features = Some(vec![desktop_feature]),
};
let _gaurd = FullstackServerEnvGuard::new(self.build.debug);
crate::builder::build_desktop(&desktop_config, false, self.build.skip_assets)?;
}
}

View file

@ -15,6 +15,11 @@ pub struct ConfigOptsBuild {
#[serde(default)]
pub release: bool,
/// Build with all debug info [default: false]
#[clap(long)]
#[serde(default)]
pub debug: bool,
// Use verbose output [default: false]
#[clap(long)]
#[serde(default)]
@ -63,6 +68,7 @@ impl From<ConfigOptsServe> for ConfigOptsBuild {
client_feature: serve.client_feature,
server_feature: serve.server_feature,
skip_assets: serve.skip_assets,
debug: serve.debug,
}
}
}
@ -92,6 +98,11 @@ pub struct ConfigOptsServe {
#[serde(default)]
pub release: bool,
/// Build with all debug info [default: false]
#[clap(long)]
#[serde(default)]
pub debug: bool,
// Use verbose output [default: false]
#[clap(long)]
#[serde(default)]

View file

@ -55,6 +55,7 @@ impl Platform for FullstackPlatform {
}
None => desktop_config.features = Some(vec![desktop_feature]),
};
let _gaurd = FullstackServerEnvGuard::new(self.serve.debug);
self.desktop.rebuild(&desktop_config)
}
}
@ -71,5 +72,64 @@ fn build_web(serve: ConfigOptsServe) -> Result<()> {
None => web_config.features = Some(vec![web_feature]),
};
web_config.platform = Some(crate::cfg::Platform::Web);
let _gaurd = FullstackWebEnvGuard::new(web_config.debug);
crate::cli::build::Build { build: web_config }.build(None)
}
// Debug mode web builds have a very large size by default. If debug mode is not enabled, we strip some of the debug info by default
// This reduces a hello world from ~40MB to ~2MB
pub(crate) struct FullstackWebEnvGuard {
old_rustflags: Option<String>,
}
impl FullstackWebEnvGuard {
pub fn new(debug_mode: bool) -> Self {
Self {
old_rustflags: (!debug_mode).then(|| {
let old_rustflags = std::env::var("RUSTFLAGS").unwrap_or_default();
std::env::set_var(
"RUSTFLAGS",
format!("{old_rustflags} -C debuginfo=none -C strip=debuginfo"),
);
old_rustflags
}),
}
}
}
impl Drop for FullstackWebEnvGuard {
fn drop(&mut self) {
if let Some(old_rustflags) = self.old_rustflags.take() {
std::env::set_var("RUSTFLAGS", old_rustflags);
}
}
}
// Debug mode web builds have a very large size by default. If debug mode is not enabled, we strip some of the debug info by default
// This reduces a hello world from ~40MB to ~2MB
pub(crate) struct FullstackServerEnvGuard {
old_rustflags: Option<String>,
}
impl FullstackServerEnvGuard {
pub fn new(debug_mode: bool) -> Self {
Self {
old_rustflags: (!debug_mode).then(|| {
let old_rustflags = std::env::var("RUSTFLAGS").unwrap_or_default();
std::env::set_var("RUSTFLAGS", format!("{old_rustflags} -C opt-level=2"));
old_rustflags
}),
}
}
}
impl Drop for FullstackServerEnvGuard {
fn drop(&mut self) {
if let Some(old_rustflags) = self.old_rustflags.take() {
std::env::set_var("RUSTFLAGS", old_rustflags);
}
}
}