Skip to content

Commit

Permalink
fix: unsupported protocol error on old macos version
Browse files Browse the repository at this point in the history
fix #11726
  • Loading branch information
bebecue committed Feb 17, 2023
1 parent a66f123 commit f182b84
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 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 @@ -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(())
Expand Down Expand Up @@ -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)?;
}
Expand Down

0 comments on commit f182b84

Please sign in to comment.