Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/change-pr-14379.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-cli": patch:enhance
---

Properly read the `required-features` field of binaries in Cargo.toml to prevent bundling issues when the features weren't enabled.
4 changes: 2 additions & 2 deletions crates/tauri-cli/src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub trait AppSettings {
features: &[String],
) -> crate::Result<tauri_bundler::BundleSettings>;
fn app_binary_path(&self, options: &Options) -> crate::Result<PathBuf>;
fn get_binaries(&self) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
fn get_binaries(&self, options: &Options) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
fn app_name(&self) -> Option<String>;
fn lib_name(&self) -> Option<String>;

Expand All @@ -57,7 +57,7 @@ pub trait AppSettings {
tauri_utils::platform::target_triple().context("failed to get target triple")?
};

let mut bins = self.get_binaries()?;
let mut bins = self.get_binaries(&options)?;
if let Some(main_binary_name) = &config.main_binary_name {
let main = bins.iter_mut().find(|b| b.main()).context("no main bin?")?;
main.set_name(main_binary_name.to_owned());
Expand Down
18 changes: 14 additions & 4 deletions crates/tauri-cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,13 @@ struct WorkspacePackageSettings {
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
struct BinarySettings {
name: String,
/// This is from nightly: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#different-binary-name
filename: Option<String>,
path: Option<String>,
required_features: Option<Vec<String>>,
}

impl BinarySettings {
Expand Down Expand Up @@ -919,7 +921,7 @@ impl AppSettings for RustAppSettings {
}

fn app_binary_path(&self, options: &Options) -> crate::Result<PathBuf> {
let binaries = self.get_binaries()?;
let binaries = self.get_binaries(options)?;
let bin_name = binaries
.iter()
.find(|x| x.main())
Expand All @@ -945,8 +947,8 @@ impl AppSettings for RustAppSettings {
Ok(path)
}

fn get_binaries(&self) -> crate::Result<Vec<BundleBinary>> {
let mut binaries: Vec<BundleBinary> = vec![];
fn get_binaries(&self, options: &Options) -> crate::Result<Vec<BundleBinary>> {
let mut binaries = Vec::new();

if let Some(bins) = &self.cargo_settings.bin {
let default_run = self
Expand All @@ -955,6 +957,14 @@ impl AppSettings for RustAppSettings {
.clone()
.unwrap_or_default();
for bin in bins {
if let (Some(req_features), Some(opt_features)) =
(&bin.required_features, &options.features)
{
// Check if all required features are enabled.
if !req_features.iter().all(|feat| opt_features.contains(feat)) {
continue;
}
}
Comment on lines +960 to +967
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this have the same code path if options.features == None vs options.features == Some(["a", "b"]) when req_features == Some(["c"])? The continue will be hit in the latter case, but not in the former.

Looking into this due to #14607

let file_name = bin.file_name();
let is_main = file_name == self.cargo_package_settings.name || file_name == default_run;
binaries.push(BundleBinary::with_path(
Expand Down Expand Up @@ -1659,7 +1669,7 @@ mod tests {

#[test]
fn parse_cargo_option() {
let args = vec![
let args = [
"build".into(),
"--".into(),
"--profile".into(),
Expand Down
Loading