From e09dab5dc44d729e2bd0a0819535926eb3f6aa7b Mon Sep 17 00:00:00 2001 From: bebecue Date: Sat, 18 Feb 2023 00:47:58 +0800 Subject: [PATCH 1/3] fix: unsupported protocol error on old macos version fix #11726 --- src/cargo/sources/registry/http_remote.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/cargo/sources/registry/http_remote.rs b/src/cargo/sources/registry/http_remote.rs index 7fbcaa7aa25..a57ebf46ff8 100644 --- a/src/cargo/sources/registry/http_remote.rs +++ b/src/cargo/sources/registry/http_remote.rs @@ -14,7 +14,7 @@ use anyhow::Context; use cargo_util::paths; use curl::easy::{HttpVersion, List}; use curl::multi::{EasyHandle, Multi}; -use log::{debug, trace}; +use log::{debug, trace, warn}; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::fs::{self, File}; @@ -391,6 +391,25 @@ impl<'cfg> HttpRegistry<'cfg> { } } +// copied from src/cargo/core/package.rs to keep change minimal +// +// When dynamically linked against libcurl, we want to ignore some failures +// when using old versions that don't support certain features. +macro_rules! try_old_curl { + ($e:expr, $msg:expr) => { + let result = $e; + if cfg!(target_os = "macos") { + if let Err(e) = result { + warn!("ignoring libcurl {} error: {}", $msg, e); + } + } else { + result.with_context(|| { + anyhow::format_err!("failed to enable {}, is curl not built right?", $msg) + })?; + } + }; +} + impl<'cfg> RegistryData for HttpRegistry<'cfg> { fn prepare(&self) -> CargoResult<()> { Ok(()) @@ -553,7 +572,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> { // Enable HTTP/2 if possible. if self.multiplexing { - handle.http_version(HttpVersion::V2)?; + try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2"); } else { handle.http_version(HttpVersion::V11)?; } From 02343aaf274aae76b0c213f539d26f25f1dba3ff Mon Sep 17 00:00:00 2001 From: bebecue Date: Sat, 18 Feb 2023 01:24:53 +0800 Subject: [PATCH 2/3] refactor: move try_old_curl!() to util::network --- src/cargo/core/package.rs | 21 ++------------------- src/cargo/sources/registry/http_remote.rs | 21 +-------------------- src/cargo/util/network.rs | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 1c7532cb3e6..bb7442e011a 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -652,23 +652,6 @@ impl<'cfg> PackageSet<'cfg> { } } -// When dynamically linked against libcurl, we want to ignore some failures -// when using old versions that don't support certain features. -macro_rules! try_old_curl { - ($e:expr, $msg:expr) => { - let result = $e; - if cfg!(target_os = "macos") { - if let Err(e) = result { - warn!("ignoring libcurl {} error: {}", $msg, e); - } - } else { - result.with_context(|| { - anyhow::format_err!("failed to enable {}, is curl not built right?", $msg) - })?; - } - }; -} - impl<'a, 'cfg> Downloads<'a, 'cfg> { /// Starts to download the package for the `id` specified. /// @@ -749,7 +732,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> { // errors here on OSX, but consider this a fatal error to not activate // HTTP/2 on all other platforms. if self.set.multiplexing { - try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2"); + crate::try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2"); } else { handle.http_version(HttpVersion::V11)?; } @@ -761,7 +744,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> { // Once the main one is opened we realized that pipelining is possible // and multiplexing is possible with static.crates.io. All in all this // reduces the number of connections down to a more manageable state. - try_old_curl!(handle.pipewait(true), "pipewait"); + crate::try_old_curl!(handle.pipewait(true), "pipewait"); handle.write_function(move |buf| { debug!("{} - {} bytes of data", token, buf.len()); diff --git a/src/cargo/sources/registry/http_remote.rs b/src/cargo/sources/registry/http_remote.rs index a57ebf46ff8..d5c433a3a21 100644 --- a/src/cargo/sources/registry/http_remote.rs +++ b/src/cargo/sources/registry/http_remote.rs @@ -391,25 +391,6 @@ impl<'cfg> HttpRegistry<'cfg> { } } -// copied from src/cargo/core/package.rs to keep change minimal -// -// When dynamically linked against libcurl, we want to ignore some failures -// when using old versions that don't support certain features. -macro_rules! try_old_curl { - ($e:expr, $msg:expr) => { - let result = $e; - if cfg!(target_os = "macos") { - if let Err(e) = result { - warn!("ignoring libcurl {} error: {}", $msg, e); - } - } else { - result.with_context(|| { - anyhow::format_err!("failed to enable {}, is curl not built right?", $msg) - })?; - } - }; -} - impl<'cfg> RegistryData for HttpRegistry<'cfg> { fn prepare(&self) -> CargoResult<()> { Ok(()) @@ -572,7 +553,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> { // Enable HTTP/2 if possible. if self.multiplexing { - try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2"); + crate::try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2"); } else { handle.http_version(HttpVersion::V11)?; } diff --git a/src/cargo/util/network.rs b/src/cargo/util/network.rs index 337eef0b950..4b27160b009 100644 --- a/src/cargo/util/network.rs +++ b/src/cargo/util/network.rs @@ -110,6 +110,24 @@ where } } +// When dynamically linked against libcurl, we want to ignore some failures +// when using old versions that don't support certain features. +#[macro_export] +macro_rules! try_old_curl { + ($e:expr, $msg:expr) => { + let result = $e; + if cfg!(target_os = "macos") { + if let Err(e) = result { + warn!("ignoring libcurl {} error: {}", $msg, e); + } + } else { + result.with_context(|| { + anyhow::format_err!("failed to enable {}, is curl not built right?", $msg) + })?; + } + }; +} + #[test] fn with_retry_repeats_the_call_then_works() { use crate::core::Shell; From a1d5889991277a759238bb920cbf0cdb167cbf3f Mon Sep 17 00:00:00 2001 From: bebecue Date: Sat, 18 Feb 2023 01:31:00 +0800 Subject: [PATCH 3/3] fix: also ignore pipewait error --- src/cargo/sources/registry/http_remote.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/sources/registry/http_remote.rs b/src/cargo/sources/registry/http_remote.rs index d5c433a3a21..c3bcadf60bf 100644 --- a/src/cargo/sources/registry/http_remote.rs +++ b/src/cargo/sources/registry/http_remote.rs @@ -565,7 +565,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> { // Once the main one is opened we realized that pipelining is possible // and multiplexing is possible with static.crates.io. All in all this // reduces the number of connections done to a more manageable state. - handle.pipewait(true)?; + crate::try_old_curl!(handle.pipewait(true), "pipewait"); let mut headers = List::new(); // Include a header to identify the protocol. This allows the server to