Skip to content

Commit 779612a

Browse files
moubctezFabianLars
andauthored
fix(cli): respect required-features field from Cargo.toml (#14379)
Co-authored-by: Fabian-Lars <github@fabianlars.de>
1 parent 22edc65 commit 779612a

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

.changes/change-pr-14379.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-cli": patch:enhance
3+
---
4+
5+
Properly read the `required-features` field of binaries in Cargo.toml to prevent bundling issues when the features weren't enabled.

crates/tauri-cli/src/interface/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub trait AppSettings {
3434
features: &[String],
3535
) -> crate::Result<tauri_bundler::BundleSettings>;
3636
fn app_binary_path(&self, options: &Options) -> crate::Result<PathBuf>;
37-
fn get_binaries(&self) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
37+
fn get_binaries(&self, options: &Options) -> crate::Result<Vec<tauri_bundler::BundleBinary>>;
3838
fn app_name(&self) -> Option<String>;
3939
fn lib_name(&self) -> Option<String>;
4040

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

60-
let mut bins = self.get_binaries()?;
60+
let mut bins = self.get_binaries(&options)?;
6161
if let Some(main_binary_name) = &config.main_binary_name {
6262
let main = bins.iter_mut().find(|b| b.main()).context("no main bin?")?;
6363
main.set_name(main_binary_name.to_owned());

crates/tauri-cli/src/interface/rust.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,13 @@ struct WorkspacePackageSettings {
695695
}
696696

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

705707
impl BinarySettings {
@@ -919,7 +921,7 @@ impl AppSettings for RustAppSettings {
919921
}
920922

921923
fn app_binary_path(&self, options: &Options) -> crate::Result<PathBuf> {
922-
let binaries = self.get_binaries()?;
924+
let binaries = self.get_binaries(options)?;
923925
let bin_name = binaries
924926
.iter()
925927
.find(|x| x.main())
@@ -945,8 +947,8 @@ impl AppSettings for RustAppSettings {
945947
Ok(path)
946948
}
947949

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

951953
if let Some(bins) = &self.cargo_settings.bin {
952954
let default_run = self
@@ -955,6 +957,14 @@ impl AppSettings for RustAppSettings {
955957
.clone()
956958
.unwrap_or_default();
957959
for bin in bins {
960+
if let (Some(req_features), Some(opt_features)) =
961+
(&bin.required_features, &options.features)
962+
{
963+
// Check if all required features are enabled.
964+
if !req_features.iter().all(|feat| opt_features.contains(feat)) {
965+
continue;
966+
}
967+
}
958968
let file_name = bin.file_name();
959969
let is_main = file_name == self.cargo_package_settings.name || file_name == default_run;
960970
binaries.push(BundleBinary::with_path(
@@ -1659,7 +1669,7 @@ mod tests {
16591669

16601670
#[test]
16611671
fn parse_cargo_option() {
1662-
let args = vec![
1672+
let args = [
16631673
"build".into(),
16641674
"--".into(),
16651675
"--profile".into(),

0 commit comments

Comments
 (0)