Skip to content

Commit 17b3d0d

Browse files
committed
Auto merge of #11733 - bebecue:issue-11726, r=weihanglo
fix: unsupported protocol error on old macos version fix #11726
2 parents a66f123 + 9e2933e commit 17b3d0d

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/cargo/core/package.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -651,23 +651,6 @@ impl<'cfg> PackageSet<'cfg> {
651651
}
652652
}
653653

654-
// When dynamically linked against libcurl, we want to ignore some failures
655-
// when using old versions that don't support certain features.
656-
macro_rules! try_old_curl {
657-
($e:expr, $msg:expr) => {
658-
let result = $e;
659-
if cfg!(target_os = "macos") {
660-
if let Err(e) = result {
661-
warn!("ignoring libcurl {} error: {}", $msg, e);
662-
}
663-
} else {
664-
result.with_context(|| {
665-
anyhow::format_err!("failed to enable {}, is curl not built right?", $msg)
666-
})?;
667-
}
668-
};
669-
}
670-
671654
impl<'a, 'cfg> Downloads<'a, 'cfg> {
672655
/// Starts to download the package for the `id` specified.
673656
///
@@ -748,7 +731,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
748731
// errors here on OSX, but consider this a fatal error to not activate
749732
// HTTP/2 on all other platforms.
750733
if self.set.multiplexing {
751-
try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2");
734+
crate::try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2");
752735
} else {
753736
handle.http_version(HttpVersion::V11)?;
754737
}
@@ -760,7 +743,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
760743
// Once the main one is opened we realized that pipelining is possible
761744
// and multiplexing is possible with static.crates.io. All in all this
762745
// reduces the number of connections down to a more manageable state.
763-
try_old_curl!(handle.pipewait(true), "pipewait");
746+
crate::try_old_curl!(handle.pipewait(true), "pipewait");
764747

765748
handle.write_function(move |buf| {
766749
debug!("{} - {} bytes of data", token, buf.len());

src/cargo/sources/registry/http_remote.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use anyhow::Context;
1414
use cargo_util::paths;
1515
use curl::easy::{HttpVersion, List};
1616
use curl::multi::{EasyHandle, Multi};
17-
use log::{debug, trace};
17+
use log::{debug, trace, warn};
1818
use std::cell::RefCell;
1919
use std::collections::{HashMap, HashSet};
2020
use std::fs::{self, File};
@@ -553,7 +553,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
553553

554554
// Enable HTTP/2 if possible.
555555
if self.multiplexing {
556-
handle.http_version(HttpVersion::V2)?;
556+
crate::try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2");
557557
} else {
558558
handle.http_version(HttpVersion::V11)?;
559559
}
@@ -565,7 +565,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
565565
// Once the main one is opened we realized that pipelining is possible
566566
// and multiplexing is possible with static.crates.io. All in all this
567567
// reduces the number of connections done to a more manageable state.
568-
handle.pipewait(true)?;
568+
crate::try_old_curl!(handle.pipewait(true), "pipewait");
569569

570570
let mut headers = List::new();
571571
// Include a header to identify the protocol. This allows the server to

src/cargo/util/network.rs

+18
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ where
110110
}
111111
}
112112

113+
// When dynamically linked against libcurl, we want to ignore some failures
114+
// when using old versions that don't support certain features.
115+
#[macro_export]
116+
macro_rules! try_old_curl {
117+
($e:expr, $msg:expr) => {
118+
let result = $e;
119+
if cfg!(target_os = "macos") {
120+
if let Err(e) = result {
121+
warn!("ignoring libcurl {} error: {}", $msg, e);
122+
}
123+
} else {
124+
result.with_context(|| {
125+
anyhow::format_err!("failed to enable {}, is curl not built right?", $msg)
126+
})?;
127+
}
128+
};
129+
}
130+
113131
#[test]
114132
fn with_retry_repeats_the_call_then_works() {
115133
use crate::core::Shell;

0 commit comments

Comments
 (0)