Skip to content

Commit f182b84

Browse files
committed
fix: unsupported protocol error on old macos version
fix #11726
1 parent a66f123 commit f182b84

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/cargo/sources/registry/http_remote.rs

Lines changed: 21 additions & 2 deletions
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};
@@ -391,6 +391,25 @@ impl<'cfg> HttpRegistry<'cfg> {
391391
}
392392
}
393393

394+
// copied from src/cargo/core/package.rs to keep change minimal
395+
//
396+
// When dynamically linked against libcurl, we want to ignore some failures
397+
// when using old versions that don't support certain features.
398+
macro_rules! try_old_curl {
399+
($e:expr, $msg:expr) => {
400+
let result = $e;
401+
if cfg!(target_os = "macos") {
402+
if let Err(e) = result {
403+
warn!("ignoring libcurl {} error: {}", $msg, e);
404+
}
405+
} else {
406+
result.with_context(|| {
407+
anyhow::format_err!("failed to enable {}, is curl not built right?", $msg)
408+
})?;
409+
}
410+
};
411+
}
412+
394413
impl<'cfg> RegistryData for HttpRegistry<'cfg> {
395414
fn prepare(&self) -> CargoResult<()> {
396415
Ok(())
@@ -553,7 +572,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
553572

554573
// Enable HTTP/2 if possible.
555574
if self.multiplexing {
556-
handle.http_version(HttpVersion::V2)?;
575+
try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2");
557576
} else {
558577
handle.http_version(HttpVersion::V11)?;
559578
}

0 commit comments

Comments
 (0)