Skip to content

Commit 941f543

Browse files
djcrami3l
authored andcommitted
Fold download crate back into rustup
1 parent 77efaf1 commit 941f543

File tree

8 files changed

+55
-100
lines changed

8 files changed

+55
-100
lines changed

Cargo.lock

+8-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+17-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ repository = "https://github.com/rust-lang/rustup"
1111
build = "build.rs"
1212

1313
[features]
14-
curl-backend = ["download/curl-backend"]
14+
curl-backend = ["dep:curl"]
1515
default = ["curl-backend", "reqwest-native-tls", "reqwest-rustls-tls"]
1616

1717
vendored-openssl = ['openssl/vendored']
1818

19-
reqwest-native-tls = ["download/reqwest-native-tls"]
20-
reqwest-rustls-tls = ["download/reqwest-rustls-tls"]
19+
reqwest-native-tls = ["reqwest/native-tls", "dep:reqwest", "dep:env_proxy"]
20+
reqwest-rustls-tls = [
21+
"reqwest/rustls-tls-manual-roots-no-provider",
22+
"dep:env_proxy",
23+
"dep:reqwest",
24+
"dep:rustls",
25+
"dep:rustls-platform-verifier",
26+
]
2127

2228
# Include in the default set to disable self-update and uninstall.
2329
no-self-update = []
@@ -40,9 +46,10 @@ cfg-if = "1.0"
4046
chrono = { version = "0.4", default-features = false, features = ["std"] }
4147
clap = { version = "4", features = ["derive", "wrap_help"] }
4248
clap_complete = "4"
43-
download = { path = "download", default-features = false }
49+
curl = { version = "0.4.44", optional = true }
4450
effective-limits = "0.5.5"
4551
enum-map = "2.5.0"
52+
env_proxy = { version = "0.4.1", optional = true }
4653
flate2 = "1"
4754
fs_at.workspace = true
4855
git-testament = "0.2"
@@ -60,8 +67,11 @@ pulldown-cmark = { version = "0.13", default-features = false }
6067
rand = "0.9"
6168
regex = "1"
6269
remove_dir_all = { version = "1.0.0", features = ["parallel"] }
70+
reqwest = { version = "0.12", default-features = false, features = ["blocking", "gzip", "socks", "stream"], optional = true }
6371
retry = { version = "2", default-features = false, features = ["random"] }
6472
rs_tracing = { version = "1.1", features = ["rs_tracing"] }
73+
rustls = { version = "0.23", optional = true, default-features = false, features = ["logging", "aws_lc_rs", "tls12"] }
74+
rustls-platform-verifier = { version = "0.5", optional = true }
6575
same-file = "1"
6676
semver = "1.0"
6777
serde = { version = "1.0", features = ["derive"] }
@@ -115,6 +125,9 @@ version = "0.59"
115125

116126
[dev-dependencies]
117127
enum-map = "2.5.0"
128+
http-body-util = "0.1.0"
129+
hyper = { version = "1.0", default-features = false, features = ["server", "http1"] }
130+
hyper-util = { version = "0.1.1", features = ["tokio"] }
118131
platforms.workspace = true
119132
proptest.workspace = true
120133
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
@@ -126,9 +139,6 @@ platforms.workspace = true
126139
[lints]
127140
workspace = true
128141

129-
[workspace]
130-
members = ["download"]
131-
132142
[workspace.package]
133143
version = "1.28.1"
134144
edition = "2024"

ci/run.bash

+14-18
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,18 @@ target_cargo() {
5050

5151
target_cargo build
5252

53-
download_pkg_test() {
54-
features=('--no-default-features' '--features' 'curl-backend,reqwest-native-tls')
53+
# Machines have 7GB of RAM, and our target/ contents is large enough that
54+
# thrashing will occur if we build-run-build-run rather than
55+
# build-build-build-run-run-run. Since this is used solely for non-release
56+
# artifacts, we try to keep features consistent across the builds, whether for
57+
# docs/test/runs etc.
58+
build_test() {
59+
cmd="$1"
60+
shift
61+
62+
features=('--features' 'curl-backend,reqwest-native-tls')
5563
case "$TARGET" in
56-
# these platforms aren't supported by ring:
64+
# these platforms aren't supported by aws-lc-rs:
5765
powerpc* ) ;;
5866
mips* ) ;;
5967
riscv* ) ;;
@@ -62,23 +70,11 @@ download_pkg_test() {
6270
* ) features+=('--features' 'reqwest-rustls-tls') ;;
6371
esac
6472

65-
cargo "$1" --locked --profile "$BUILD_PROFILE" --target "$TARGET" "${features[@]}" -p download
66-
}
67-
68-
# Machines have 7GB of RAM, and our target/ contents is large enough that
69-
# thrashing will occur if we build-run-build-run rather than
70-
# build-build-build-run-run-run. Since this is used solely for non-release
71-
# artifacts, we try to keep features consistent across the builds, whether for
72-
# docs/test/runs etc.
73-
build_test() {
74-
cmd="$1"
75-
shift
76-
download_pkg_test "${cmd}"
7773
if [ "build" = "${cmd}" ]; then
78-
target_cargo "${cmd}" --workspace --all-targets --features test
74+
target_cargo "${cmd}" --workspace --all-targets "${features[@]}" --features test
7975
else
80-
target_cargo "${cmd}" --workspace --features test --tests
81-
target_cargo "${cmd}" --doc --workspace --features test
76+
target_cargo "${cmd}" --workspace "${features[@]}" --features test --tests
77+
target_cargo "${cmd}" --doc --workspace "${features[@]}" --features test
8278
fi
8379
}
8480

download/Cargo.toml

-44
This file was deleted.

download/src/lib.rs renamed to src/download/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
use std::fs::remove_file;
44
use std::path::Path;
55

6-
use anyhow::Context;
7-
pub use anyhow::Result;
6+
#[cfg(any(
7+
not(feature = "curl-backend"),
8+
not(feature = "reqwest-rustls-tls"),
9+
not(feature = "reqwest-native-tls")
10+
))]
11+
use anyhow::anyhow;
12+
use anyhow::{Context, Result};
813
use thiserror::Error;
914
use url::Url;
1015

16+
#[cfg(test)]
17+
mod tests;
18+
1119
/// User agent header value for HTTP request.
1220
/// See: https://github.com/rust-lang/rustup/issues/2860.
1321
#[cfg(feature = "curl-backend")]
@@ -488,8 +496,6 @@ pub enum DownloadError {
488496
HttpStatus(u32),
489497
#[error("file not found")]
490498
FileNotFound,
491-
#[error("download backend '{0}' unavailable")]
492-
BackendUnavailable(&'static str),
493499
#[error("{0}")]
494500
Message(String),
495501
#[error(transparent)]

download/tests/all.rs renamed to src/download/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod curl {
2121
use url::Url;
2222

2323
use super::{serve_file, tmp_dir, write_file};
24-
use download::*;
24+
use crate::download::{Backend, Event};
2525

2626
#[tokio::test]
2727
async fn partially_downloaded_file_gets_resumed_from_byte_offset() {
@@ -107,7 +107,7 @@ mod reqwest {
107107
use url::Url;
108108

109109
use super::{serve_file, tmp_dir, write_file};
110-
use download::{Backend, Event, TlsBackend};
110+
use crate::download::{Backend, Event, TlsBackend};
111111

112112
static SERIALISE_TESTS: LazyLock<tokio::sync::Mutex<()>> =
113113
LazyLock::new(|| tokio::sync::Mutex::new(()));

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ mod command;
7474
mod config;
7575
mod diskio;
7676
pub mod dist;
77+
mod download;
7778
pub mod env_var;
7879
pub mod errors;
7980
mod fallback_settings;

src/utils/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub(crate) async fn download_file_with_resume(
164164
notify_handler: &dyn Fn(Notification<'_>),
165165
process: &Process,
166166
) -> Result<()> {
167-
use download::DownloadError as DEK;
167+
use crate::download::DownloadError as DEK;
168168
match download_file_(
169169
url,
170170
path,
@@ -213,8 +213,7 @@ async fn download_file_(
213213
process: &Process,
214214
) -> Result<()> {
215215
#[cfg(any(feature = "reqwest-rustls-tls", feature = "reqwest-native-tls"))]
216-
use download::TlsBackend;
217-
use download::{Backend, Event};
216+
use crate::download::{TlsBackend, Backend, Event};
218217
use sha2::Digest;
219218
use std::cell::RefCell;
220219

@@ -224,7 +223,7 @@ async fn download_file_(
224223

225224
// This callback will write the download to disk and optionally
226225
// hash the contents, then forward the notification up the stack
227-
let callback: &dyn Fn(Event<'_>) -> download::Result<()> = &|msg| {
226+
let callback: &dyn Fn(Event<'_>) -> anyhow::Result<()> = &|msg| {
228227
if let Event::DownloadDataReceived(data) = msg {
229228
if let Some(h) = hasher.borrow_mut().as_mut() {
230229
h.update(data);

0 commit comments

Comments
 (0)