Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): Apple platform dependencies are minimized as much as possible #414

Merged
merged 4 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ webpki-roots = ["dep:webpki-root-certs"]
# Use the system's proxy configuration.
macos-system-configuration = ["dep:system-configuration"]

# Use the Apple platform's network device binding.
apple-bindable-device = ["dep:libc"]

# Optional enable http2 tracing
http2-tracing = ["hyper2/http2-tracing"]

Expand Down Expand Up @@ -153,7 +156,7 @@ windows-registry = "0.4.0"
system-configuration = { version = "0.6.0", optional = true }

[target.'cfg(any(target_os = "ios", target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos"))'.dependencies]
libc = "0.2"
libc = { version = "0.2", optional = true }

[dev-dependencies]
hyper = { version = "1.1.0", default-features = false, features = [
Expand Down Expand Up @@ -308,6 +311,7 @@ required-features = ["websocket", "http2-tracing", "futures-util/std"]
[[example]]
name = "client_chain"
path = "examples/client_chain.rs"
required-features = ["apple-bindable-device"]

[[example]]
name = "request_with_redirect"
Expand Down
2 changes: 1 addition & 1 deletion examples/client_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn main() -> Result<(), rquest::Error> {
.as_mut()
.impersonate(Impersonate::Safari18)
.headers_order(HEADER_ORDER)
.interface("utun4")
.interface("utun6")
.apply()?;

let text = client
Expand Down
30 changes: 20 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,16 @@ macro_rules! cfg_bindable_device {
target_os = "android",
target_os = "fuchsia",
target_os = "linux",
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos",
target_os = "watchos"
all(
feature = "apple-bindable-device",
any(
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
)
)
))]
$(
$tt
Expand All @@ -306,11 +311,16 @@ macro_rules! cfg_non_bindable_device {
target_os = "android",
target_os = "fuchsia",
target_os = "linux",
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos",
target_os = "watchos"
all(
feature = "apple-bindable-device",
any(
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
)
)
)))]
$(
$tt
Expand Down
45 changes: 29 additions & 16 deletions src/util/client/connect/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ struct Config {
target_os = "android",
target_os = "fuchsia",
target_os = "linux",
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
all(
feature = "apple-bindable-device",
any(
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
)
)
))]
interface: Option<std::borrow::Cow<'static, str>>,
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
Expand Down Expand Up @@ -246,11 +251,16 @@ impl<R> HttpConnector<R> {
target_os = "android",
target_os = "fuchsia",
target_os = "linux",
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
all(
feature = "apple-bindable-device",
any(
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
)
)
))]
interface: None,
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
Expand Down Expand Up @@ -812,12 +822,15 @@ fn connect(
.map_err(ConnectError::m("tcp bind interface error"))?;
}

#[cfg(any(
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
#[cfg(all(
feature = "apple-bindable-device",
any(
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos",
target_os = "watchos",
)
))]
/// That this only supports ios, visionos, macos, tvos, watchos
if let Some(interface) = &config.interface {
Expand Down
Loading