Skip to content

Commit

Permalink
fix(cli): don't build library when building desktop targets, closes #…
Browse files Browse the repository at this point in the history
…7007 (#7014)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
FlysoftBeta and lucasfernog committed May 22, 2023
1 parent 8e85576 commit aa6c916
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changes/cli-library-compilation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---

Don't build library files when building desktop targets.
1 change: 0 additions & 1 deletion examples/api/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
#[cfg(desktop)]
api_lib::run();
}
2 changes: 1 addition & 1 deletion tooling/cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ pub fn setup(options: &mut Options, mobile: bool) -> Result<AppInterface> {
.features
.get_or_insert(Vec::new())
.extend(config_.build.features.clone().unwrap_or_default());
interface.build_options(&mut options.features, mobile);
interface.build_options(&mut options.args, &mut options.features, mobile);

Ok(interface)
}
Expand Down
14 changes: 11 additions & 3 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,17 @@ fn lookup<F: FnMut(FileType, PathBuf)>(dir: &Path, mut f: F) {

fn shared_options(
mobile: bool,
args: &mut Vec<String>,
features: &mut Option<Vec<String>>,
app_settings: &RustAppSettings,
) {
if mobile {
args.push("--lib".into());
features
.get_or_insert(Vec::new())
.push("tauri/rustls-tls".into());
} else {
args.push("--bins".into());
let all_features = app_settings
.manifest
.all_enabled_features(if let Some(f) = features { f } else { &[] });
Expand Down Expand Up @@ -385,7 +388,7 @@ fn dev_options(
}
*args = dev_args;

shared_options(mobile, features, app_settings);
shared_options(mobile, args, features, app_settings);

if !args.contains(&"--no-default-features".into()) {
let manifest_features = app_settings.manifest.features();
Expand All @@ -410,11 +413,16 @@ fn dev_options(
}

impl Rust {
pub fn build_options(&self, features: &mut Option<Vec<String>>, mobile: bool) {
pub fn build_options(
&self,
args: &mut Vec<String>,
features: &mut Option<Vec<String>>,
mobile: bool,
) {
features
.get_or_insert(Vec::new())
.push("custom-protocol".into());
shared_options(mobile, features, &self.app_settings);
shared_options(mobile, args, features, &self.app_settings);
}

fn run_dev<F: Fn(ExitStatus, ExitReason) + Send + Sync + 'static>(
Expand Down
13 changes: 12 additions & 1 deletion tooling/cli/src/mobile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,25 @@ impl Target {
}
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CliOptions {
pub features: Option<Vec<String>>,
pub args: Vec<String>,
pub noise_level: NoiseLevel,
pub vars: HashMap<String, OsString>,
}

impl Default for CliOptions {
fn default() -> Self {
Self {
features: None,
args: vec!["--lib".into()],
noise_level: Default::default(),
vars: Default::default(),
}
}
}

fn setup_dev_config(
config_extension: &mut Option<String>,
force_ip_prompt: bool,
Expand Down
1 change: 0 additions & 1 deletion tooling/cli/templates/app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
#[cfg(desktop)]
app_lib::run();
}

0 comments on commit aa6c916

Please sign in to comment.