Repository: tauri-apps/tauri
File: crates/tauri-cli/src/interface/rust.rs (Rust)

Code before:
    } else {
      ""
    };

    if let Some(bins) = &self.cargo_settings.bin {
      let default_run = self
        .package_settings
        .default_run
        .clone()
        .unwrap_or_default();
      for bin in bins {
        let name = format!("{}{}", bin.name, ext);
        let is_main = bin.name == self.cargo_package_settings.name || bin.name == default_run;
        binaries.push(BundleBinary::new(name, is_main))
      }
    }

    let mut bins_path = tauri_dir().to_path_buf();
    bins_path.push("src/bin");
    if let Ok(fs_bins) = std::fs::read_dir(bins_path) {
      for entry in fs_bins {
        let path = entry?.path();
        if let Some(name) = path.file_stem() {
          if !binaries.iter().any(|bin| bin.name() == name) {
            binaries.push(BundleBinary::new(
              format!("{}{}", name.to_string_lossy(), ext),
              false,
            ))
          }
        }
      }
    }

    if let Some(default_run) = self.package_settings.default_run.as_ref() {
      if !binaries.iter_mut().any(|bin| bin.name() == default_run) {
        binaries.push(BundleBinary::new(format!("{}{}", default_run, ext), true));
      }
    }

    match binaries.len() {
      0 => binaries.push(BundleBinary::new(
        format!("{}{}", self.cargo_package_settings.name, ext),
        true,
      )),
      1 => binaries.get_mut(0).unwrap().set_main(true),
      _ => {}
    }

    Ok(binaries)
  }


Review comment (suggestion):
this check is here to fix the following issue:
- you have a `src-tauri/src/bin/app.rs` file (automatically discovered as a binary by Cargo)
- you configure the binary manually in Cargo.toml (yeah it's silly, but it's possible and allows you to configure more stuff)
```toml
[[bin]]
name = "lucass"
path = "src/bin/app.rs"
```

then the Tauri CLI will try to load both `app` and `lucass`, while only `lucass` exists

Code after:
      ".exe"
    } else {
      ""
    };

    if let Some(bins) = &self.cargo_settings.bin {
      let default_run = self
        .package_settings
        .default_run
        .clone()
        .unwrap_or_default();
      for bin in bins {
        let name = format!("{}{}", bin.name, ext);
        let is_main = bin.name == self.cargo_package_settings.name || bin.name == default_run;
        binaries.push(BundleBinary::with_path(name, is_main, bin.path.clone()))
      }
    }

    let mut bins_path = tauri_dir().to_path_buf();
    bins_path.push("src/bin");
    if let Ok(fs_bins) = std::fs::read_dir(bins_path) {
      for entry in fs_bins {
        let path = entry?.path();
        if let Some(name) = path.file_stem() {
          // see https://github.com/tauri-apps/tauri/pull/10977#discussion_r1759742414
          let bin_exists = binaries.iter().any(|bin| {
            bin.name() == name || path.ends_with(bin.src_path().unwrap_or(&"".to_string()))
          });
          if !bin_exists {
            binaries.push(BundleBinary::new(
              format!("{}{}", name.to_string_lossy(), ext),
              false,
            ))
          }
        }
      }
    }

    if let Some(default_run) = self.package_settings.default_run.as_ref() {
      if !binaries.iter_mut().any(|bin| bin.name() == default_run) {
        binaries.push(BundleBinary::new(format!("{}{}", default_run, ext), true));
      }
    }

    match binaries.len() {
      0 => binaries.push(BundleBinary::new(
        format!("{}{}", self.cargo_package_settings.name, ext),
        true,
      )),
      1 => binaries.get_mut(0).unwrap().set_main(true),
      _ => {}