Repository: tauri-apps/tauri
File: crates/tauri-build/src/lib.rs (Rust)

Code before:
        println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET={version}");
      }
    }
  }

  if target_triple.contains("ios") {
    println!(
      "cargo:rustc-env=IPHONEOS_DEPLOYMENT_TARGET={}",
      config.bundle.ios.minimum_system_version
    );
  }

  if target_triple.contains("windows") {
    use semver::Version;
    use tauri_winres::{VersionInfo, WindowsResource};

    fn find_icon<F: Fn(&&String) -> bool>(config: &Config, predicate: F, default: &str) -> PathBuf {
      let icon_path = config
        .bundle
        .icon
        .iter()
        .find(|i| predicate(i))
        .map(AsRef::as_ref)
        .unwrap_or_else(|| default);
      icon_path.into()
    }

    let window_icon_path = attributes
      .windows_attributes
      .window_icon_path
      .unwrap_or_else(|| find_icon(&config, |i| i.ends_with(".ico"), "icons/icon.ico"));

    let mut res = WindowsResource::new();

    if let Some(manifest) = attributes.windows_attributes.app_manifest {
      res.set_manifest(&manifest);
    }

    if let Some(version_str) = &config.version {
      if let Ok(v) = Version::parse(version_str) {
        let version = (v.major << 48) | (v.minor << 32) | (v.patch << 16);
        res.set_version_info(VersionInfo::FILEVERSION, version);
        res.set_version_info(VersionInfo::PRODUCTVERSION, version);
      }
    }

    if let Some(product_name) = &config.product_name {
      res.set("ProductName", product_name);
    }

    let company_name = config.bundle.publisher.unwrap_or_else(|| {

Review comment (suggestion):
The `Fn(&&String) -> bool` would also be more natural as `Fn(&str) -> bool` and we don't need to clone into a `PathBuf` to return it. But then we need to both annotate lifetimes and the `find_icon` name is a bit unidiomatic, un-std-like in that it returns something else than an `Option<&T>`.

Suggestion, we make the function mirror the stdlib function, and move the `unwrap_or` to the callsite.

```rust
    fn find_icon<F: Fn(&str) -> bool>(config: &Config, predicate: F) -> Option<&str> {
      config
        .bundle
        .icon
        .iter()
        .find(|i| predicate(i))
        .map(|s| s.as_str())
    }

    let window_icon_path = attributes
      .windows_attributes
      .window_icon_path
      .unwrap_or_else(|| {
        find_icon(&config, |i| i.ends_with(".ico"))
          .unwrap_or("icons/icon.ico")
          .into()
      });
```

This is just marginally longer, but bubbles clones up the call chain. The higher up, the better visibility we have about whether they are really necessary or just an artifact of our own making.

Code after:
        println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET={version}");
      }
    }
  }

  if target_triple.contains("ios") {
    println!(
      "cargo:rustc-env=IPHONEOS_DEPLOYMENT_TARGET={}",
      config.bundle.ios.minimum_system_version
    );
  }

  if target_triple.contains("windows") {
    use semver::Version;
    use tauri_winres::{VersionInfo, WindowsResource};

    let window_icon_path = attributes
      .windows_attributes
      .window_icon_path
      .unwrap_or_else(|| {
        config
          .bundle
          .icon
          .iter()
          .find(|i| i.ends_with(".ico"))
          .map(AsRef::as_ref)
          .unwrap_or("icons/icon.ico")
          .into()
      });

    let mut res = WindowsResource::new();

    if let Some(manifest) = attributes.windows_attributes.app_manifest {
      res.set_manifest(&manifest);
    }

    if let Some(version_str) = &config.version {
      if let Ok(v) = Version::parse(version_str) {
        let version = (v.major << 48) | (v.minor << 32) | (v.patch << 16);
        res.set_version_info(VersionInfo::FILEVERSION, version);
        res.set_version_info(VersionInfo::PRODUCTVERSION, version);
      }
    }

    if let Some(product_name) = &config.product_name {
      res.set("ProductName", product_name);
    }

    let company_name = config.bundle.publisher.unwrap_or_else(|| {
      config
        .identifier