Repository: seanmonstar/reqwest (language: rust)

Issue:
Add `macos-system-configuration` feature flag
The `system-configuration` crate was added in https://github.com/seanmonstar/reqwest/pull/1955 to support macOS system proxy settings. However, it forces users to link to the SystemConfiguration framework.

This PR makes macOS system proxy a default feature in reqwest. Users can disable the feature and avoid the `dyld` startup cost of loading the framework.


Discussion / hints:
I'm curious, does v0.11.25 (which includes #2130) fix it so that this isn't needed?

If it's still needed, we can include this in the 0.12 release that is coming up soon. But wanted to check.
> I'm curious, does v0.11.25 (which includes #2130) fix it so that this isn't needed?
> 
> If it's still needed, we can include this in the 0.12 release that is coming up soon. But wanted to check.

@seanmonstar  Yes, please include this fix. The inclusion of `system-configuration` let's our builds break left and right ever since `reqwest` shipped it. We now manually patch each release and probably will soon automate it. Moreover, since `reqwest` 0.11.25 shipped with #2130, MSRV is broken on macOS, see https://github.com/seanmonstar/reqwest/issues/2169.

Btw, given that MSRV keeps breaking, I'd highly suggest to re-add the Windows and macOS MSRV checks you had me drop in https://github.com/seanmonstar/reqwest/pull/1993.

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 4e0d8966a..69a1f522c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,7 +27,7 @@ features = [
 ]
 
 [features]
-default = ["default-tls", "http2"]
+default = ["default-tls", "http2", "macos-system-configuration"]
 
 # Note: this doesn't enable the 'native-tls' feature, which adds specific
 # functionality for it.
@@ -65,6 +65,9 @@ stream = ["tokio/fs", "dep:tokio-util", "dep:wasm-streams"]
 
 socks = ["dep:tokio-socks"]
 
+# Use the system's proxy configuration.
+macos-system-configuration = ["dep:system-configuration"]
+
 # Experimental HTTP/3 client.
 # Disabled while waiting for quinn to upgrade.
 #http3 = ["rustls-tls-manual-roots", "dep:h3", "dep:h3-quinn", "dep:quinn", "dep:futures-channel"]
@@ -168,7 +171,7 @@ futures-util = { version = "0.3.0", default-features = false, features = ["std",
 winreg = "0.50.0"
 
 [target.'cfg(target_os = "macos")'.dependencies]
-system-configuration = "0.6"
+system-configuration = { version = "0.5.1", optional = true }
 
 # wasm
 
diff --git a/src/proxy.rs b/src/proxy.rs
index e4ad3a98c..17670cf4a 100644
--- a/src/proxy.rs
+++ b/src/proxy.rs
@@ -13,7 +13,7 @@ use std::collections::HashMap;
 use std::env;
 use std::error::Error;
 use std::net::IpAddr;
-#[cfg(target_os = "macos")]
+#[cfg(all(target_os = "macos", feature = "macos-system-configuration"))]
 use system_configuration::{
     core_foundation::{
         base::CFType,
@@ -947,7 +947,7 @@ fn get_from_platform_impl() -> Result<Option<String>, Box<dyn Error>> {
     Ok((proxy_enable == 1).then_some(proxy_server))
 }
 
-#[cfg(target_os = "macos")]
+#[cfg(all(target_os = "macos", feature = "macos-system-configuration"))]
 fn parse_setting_from_dynamic_store(
     proxies_map: &CFDictionary<CFString, CFType>,
     enabled_key: CFStringRef,
@@ -985,7 +985,7 @@ fn parse_setting_from_dynamic_store(
     None
 }
 
-#[cfg(target_os = "macos")]
+#[cfg(all(target_os = "macos", feature = "macos-system-configuration"))]
 fn get_from_platform_impl() -> Result<Option<String>, Box<dyn Error>> {
     let store = SCDynamicStoreBuilder::new("reqwest").build();
 
@@ -1016,12 +1016,18 @@ fn get_from_platform_impl() -> Result<Option<String>, Box<dyn Error>> {
     }
 }
 
-#[cfg(any(target_os = "windows", target_os = "macos"))]
+#[cfg(any(
+    target_os = "windows",
+    all(target_os = "macos", feature = "macos-system-configuration")
+))]
 fn get_from_platform() -> Option<String> {
     get_from_platform_impl().ok().flatten()
 }
 
-#[cfg(not(any(target_os = "windows", target_os = "macos")))]
+#[cfg(not(any(
+    target_os = "windows",
+    all(target_os = "macos", feature = "macos-system-configuration")
+)))]
 fn get_from_platform() -> Option<String> {
     None
 }


Test patch: