Skip to content

Commit

Permalink
fix(cli): don't force native-tls feature on desktop (#12445)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianLars authored Jan 25, 2025
1 parent 6cbfc48 commit 27096cd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .changes/cli-core-native-tls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
tauri-cli: patch:bug
tauri: patch:bug
---

Fixed an issue that caused Tauri's CLI to enable tauri's `native-tls` feature even though it wasn't needed. Moved `reqwest` to a mobile-only dependency in `tauri` and enabled its `rustls-tls` feature flag.
2 changes: 1 addition & 1 deletion Cargo.lock

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

39 changes: 8 additions & 31 deletions crates/tauri-cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,35 +360,6 @@ fn lookup<F: FnMut(FileType, PathBuf)>(dir: &Path, mut f: F) {
}
}

fn shared_options(
desktop_dev: bool,
mobile: bool,
args: &mut Vec<String>,
features: &mut Option<Vec<String>>,
app_settings: &RustAppSettings,
) {
if mobile {
args.push("--lib".into());
features
.get_or_insert(Vec::new())
.push("tauri/rustls-tls".into());
} else {
if !desktop_dev {
args.push("--bins".into());
}
let all_features = app_settings
.manifest
.lock()
.unwrap()
.all_enabled_features(if let Some(f) = features { f } else { &[] });
if !all_features.contains(&"tauri/rustls-tls".into()) {
features
.get_or_insert(Vec::new())
.push("tauri/native-tls".into());
}
}
}

fn dev_options(
mobile: bool,
args: &mut Vec<String>,
Expand All @@ -409,7 +380,11 @@ fn dev_options(
}
*args = dev_args;

shared_options(true, mobile, args, features, app_settings);
if mobile {
args.push("--lib".into());
} else {
args.push("--bins".into());
}

if !args.contains(&"--no-default-features".into()) {
let manifest_features = app_settings.manifest.lock().unwrap().features();
Expand Down Expand Up @@ -489,7 +464,9 @@ impl Rust {
features
.get_or_insert(Vec::new())
.push("tauri/custom-protocol".into());
shared_options(false, mobile, args, features, &self.app_settings);
if mobile {
args.push("--lib".into());
}
}

fn run_dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
Expand Down
32 changes: 20 additions & 12 deletions crates/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ serde_repr = "0.1"
http = "1"
dirs = "6"
percent-encoding = "2"
reqwest = { version = "0.12", default-features = false, features = [
"json",
"stream",
] }
bytes = { version = "1", features = ["serde"] }
raw-window-handle = { version = "0.6", features = ["std"] }
glob = "0.3"
urlpattern = "0.3"
Expand All @@ -89,13 +84,16 @@ specta = { version = "^2.0.0-rc.16", optional = true, default-features = false,
"function",
"derive",
] }
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"windows\", target_os = \"macos\"))".dependencies]

# desktop
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "windows", target_os = "macos"))'.dependencies]
muda = { version = "0.15", default-features = false, features = ["serde"] }
tray-icon = { version = "0.19", default-features = false, features = [
"serde",
], optional = true }

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
# linux
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dependencies]
gtk = { version = "0.18", features = ["v3_24"] }
webkit2gtk = { version = "=2.0.1", features = ["v2_40"] }

Expand All @@ -120,15 +118,23 @@ objc2-app-kit = { version = "0.2", default-features = false, features = [
] }
window-vibrancy = "0.5"

# windows
[target."cfg(windows)".dependencies]
webview2-com = "0.34"
window-vibrancy = "0.5"
windows = { version = "0.58", features = ["Win32_Foundation"] }

[target."cfg(windows)".dependencies.windows]
version = "0.58"
features = ["Win32_Foundation"]
# mobile
[target.'cfg(any(target_os = "android", all(target_vendor = "apple", not(target_os = "macos"))))'.dependencies]
bytes = { version = "1", features = ["serde"] }
reqwest = { version = "0.12", default-features = false, features = [
"json",
"stream",
"rustls-tls",
] }

[target."cfg(target_os = \"android\")".dependencies]
# android
[target.'cfg(target_os = "android")'.dependencies]
jni = "0.21"

# UIKit, i.e. iOS/tvOS/watchOS/visionOS
Expand Down Expand Up @@ -179,9 +185,11 @@ objc-exception = ["tauri-runtime-wry/objc-exception"]
linux-libxdo = ["tray-icon/libxdo", "muda/libxdo"]
isolation = ["tauri-utils/isolation", "tauri-macros/isolation", "uuid"]
custom-protocol = ["tauri-macros/custom-protocol"]
# TODO: Remove these flags in v3 and/or enable them by default behind a mobile flag https://github.com/tauri-apps/tauri/issues/12384
# For now those feature flags keep enabling reqwest features in case some users depend on that by accident.
native-tls = ["reqwest/native-tls"]
native-tls-vendored = ["reqwest/native-tls-vendored"]
rustls-tls = ["reqwest/rustls-tls"]
rustls-tls = []
devtools = ["tauri-runtime/devtools", "tauri-runtime-wry/devtools"]
process-relaunch-dangerous-allow-symlink-macos = [
"tauri-utils/process-relaunch-dangerous-allow-symlink-macos",
Expand Down
1 change: 1 addition & 0 deletions crates/tauri/src/protocol/tauri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ fn get_response<R: Runtime>(
);

let mut proxy_builder = reqwest::ClientBuilder::new()
.use_rustls_tls()
.build()
.unwrap()
.request(request.method().clone(), &url);
Expand Down

0 comments on commit 27096cd

Please sign in to comment.