Skip to content

Commit

Permalink
Auto merge of rust-lang#11735 - bebecue:backport-11733, r=weihanglo
Browse files Browse the repository at this point in the history
[beta-1.68] backport rust-lang#11733

backport rust-lang#11733
  • Loading branch information
bors committed Feb 18, 2023
2 parents ddf05ad + a1d5889 commit 3469009
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
21 changes: 2 additions & 19 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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)?;
}
Expand All @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/sources/registry/http_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -553,7 +553,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {

// Enable HTTP/2 if possible.
if self.multiplexing {
handle.http_version(HttpVersion::V2)?;
crate::try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2");
} else {
handle.http_version(HttpVersion::V11)?;
}
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/cargo/util/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3469009

Please sign in to comment.