Skip to content

Commit

Permalink
fix(core): Android compilation on Windows (#5658)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Nov 20, 2022
1 parent 03d6c6a commit f6f9192
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 170 deletions.
5 changes: 5 additions & 0 deletions .changes/default-tls-features.md
@@ -0,0 +1,5 @@
---
"tauri": major
---

Added the `default-tls` and `reqwest-default-tls` Cargo features for enabling TLS suppport to connect over HTTPS.
76 changes: 39 additions & 37 deletions core/tauri-build/src/lib.rs
Expand Up @@ -348,11 +348,12 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
.window_icon_path
.unwrap_or_else(|| find_icon(&config, |i| i.ends_with(".ico"), "icons/icon.ico"));

if window_icon_path.exists() {
let mut res = WindowsResource::new();
if target_triple.contains("windows") {
if window_icon_path.exists() {
let mut res = WindowsResource::new();

res.set_manifest(
r#"
res.set_manifest(
r#"
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
<dependentAssembly>
Expand All @@ -368,42 +369,43 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
</dependency>
</assembly>
"#,
);

if let Some(sdk_dir) = &attributes.windows_attributes.sdk_dir {
if let Some(sdk_dir_str) = sdk_dir.to_str() {
res.set_toolkit_path(sdk_dir_str);
} else {
return Err(anyhow!(
"sdk_dir path is not valid; only UTF-8 characters are allowed"
));
);

if let Some(sdk_dir) = &attributes.windows_attributes.sdk_dir {
if let Some(sdk_dir_str) = sdk_dir.to_str() {
res.set_toolkit_path(sdk_dir_str);
} else {
return Err(anyhow!(
"sdk_dir path is not valid; only UTF-8 characters are allowed"
));
}
}
}
if let Some(version) = &config.package.version {
if let Ok(v) = Version::parse(version) {
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(version) = &config.package.version {
if let Ok(v) = Version::parse(version) {
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);
}
res.set("FileVersion", version);
res.set("ProductVersion", version);
}
res.set("FileVersion", version);
res.set("ProductVersion", version);
}
if let Some(product_name) = &config.package.product_name {
res.set("ProductName", product_name);
res.set("FileDescription", product_name);
}
res.set_icon_with_id(&window_icon_path.display().to_string(), "32512");
res.compile().with_context(|| {
format!(
"failed to compile `{}` into a Windows Resource file during tauri-build",
if let Some(product_name) = &config.package.product_name {
res.set("ProductName", product_name);
res.set("FileDescription", product_name);
}
res.set_icon_with_id(&window_icon_path.display().to_string(), "32512");
res.compile().with_context(|| {
format!(
"failed to compile `{}` into a Windows Resource file during tauri-build",
window_icon_path.display()
)
})?;
} else {
return Err(anyhow!(format!(
"`{}` not found; required for generating a Windows Resource file during tauri-build",
window_icon_path.display()
)
})?;
} else {
return Err(anyhow!(format!(
"`{}` not found; required for generating a Windows Resource file during tauri-build",
window_icon_path.display()
)));
)));
}
}

let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
Expand Down
6 changes: 4 additions & 2 deletions core/tauri/Cargo.toml
Expand Up @@ -67,9 +67,9 @@ dirs-next = "2.0"
percent-encoding = "2.2"
base64 = { version = "0.13", optional = true }
clap = { version = "3", optional = true }
reqwest = { version = "0.11", features = [ "json", "stream" ], optional = true }
reqwest = { version = "0.11", default-features = false, features = [ "json", "stream" ], optional = true }
bytes = { version = "1", features = [ "serde" ], optional = true }
attohttpc = { version = "0.22", features = [ "compress", "json", "form" ] }
attohttpc = { version = "0.24", default-features = false, features = [ "compress", "json", "form" ] }
open = { version = "3.0", optional = true }
shared_child = { version = "1.0", optional = true }
os_pipe = { version = "1.0", optional = true }
Expand Down Expand Up @@ -147,6 +147,8 @@ http-multipart = [ "attohttpc/multipart-form", "reqwest/multipart" ]
shell-open-api = [ "open", "regex", "tauri-macros/shell-scope" ]
fs-extract-api = [ "zip" ]
reqwest-client = [ "reqwest", "bytes" ]
reqwest-default-tls = [ "reqwest-client", "reqwest/default-tls" ]
default-tls = [ "attohttpc/tls-native" ]
reqwest-native-tls-vendored = [ "reqwest-client", "reqwest/native-tls-vendored" ]
native-tls-vendored = [ "attohttpc/tls-vendored" ]
process-command-api = [ "shared_child", "os_pipe" ]
Expand Down
2 changes: 2 additions & 0 deletions core/tauri/src/lib.rs
Expand Up @@ -22,6 +22,8 @@
//! - **http-api**: Enables the [`api::http`] module.
//! - **http-multipart**: Adds support to `multipart/form-data` requests.
//! - **reqwest-client**: Uses `reqwest` as HTTP client on the `http` APIs. Improves performance, but increases the bundle size.
//! - **default-tls**: Provides TLS support to connect over HTTPS (applies to the default HTTP client).
//! - **reqwest-default-tls**: Provides TLS support to connect over HTTPS (applies to the `reqwest` HTTP client).
//! - **native-tls-vendored**: Compile and statically link to a vendored copy of OpenSSL (applies to the default HTTP client).
//! - **reqwest-native-tls-vendored**: Compile and statically link to a vendored copy of OpenSSL (applies to the `reqwest` HTTP client).
//! - **process-command-api**: Enables the [`api::process::Command`] APIs.
Expand Down
129 changes: 0 additions & 129 deletions examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tooling/cli/src/interface/rust.rs
Expand Up @@ -353,8 +353,8 @@ fn shared_options(
let all_features = app_settings
.manifest
.all_enabled_features(if let Some(f) = features { f } else { &[] });
if !all_features.contains(&"tauri/native-tls-vendored".into())
&& !all_features.contains(&"tauri/reqwest-native-tls-vendored".into())
if all_features.contains(&"tauri/default-tls".into())
|| all_features.contains(&"tauri/reqwest-default-tls".into())
{
if all_features.contains(&"tauri/reqwest-client".into()) {
features
Expand Down

0 comments on commit f6f9192

Please sign in to comment.