@@ -12,6 +12,8 @@ use anyhow::{anyhow, bail, Context, Result};
12
12
use retry:: delay:: { jitter, Fibonacci } ;
13
13
use retry:: { retry, OperationResult } ;
14
14
use sha2:: Sha256 ;
15
+ #[ cfg( feature = "reqwest-backend" ) ]
16
+ use tracing:: info;
15
17
use url:: Url ;
16
18
17
19
use crate :: errors:: * ;
@@ -211,7 +213,9 @@ async fn download_file_(
211
213
process : & Process ,
212
214
) -> Result < ( ) > {
213
215
use download:: download_to_path_with_backend;
214
- use download:: { Backend , Event , TlsBackend } ;
216
+ #[ cfg( feature = "reqwest-backend" ) ]
217
+ use download:: TlsBackend ;
218
+ use download:: { Backend , Event } ;
215
219
use sha2:: Digest ;
216
220
use std:: cell:: RefCell ;
217
221
@@ -246,28 +250,70 @@ async fn download_file_(
246
250
// Download the file
247
251
248
252
// Keep the curl env var around for a bit
249
- let use_curl_backend = process
250
- . var_os ( "RUSTUP_USE_CURL" )
251
- . is_some_and ( |it| it != "0" ) ;
252
- let use_rustls = process
253
- . var_os ( "RUSTUP_USE_RUSTLS" )
254
- . is_none_or ( |it| it != "0" ) ;
255
- let backend = if use_curl_backend {
256
- Backend :: Curl
257
- } else {
258
- let tls_backend = if use_rustls {
259
- TlsBackend :: Rustls
260
- } else {
253
+ let use_curl_backend = process. var_os ( "RUSTUP_USE_CURL" ) . map ( |it| it != "0" ) ;
254
+ #[ cfg( not( feature = "curl-backend" ) ) ]
255
+ if use_curl_backend == Some ( true ) {
256
+ return Err ( anyhow ! (
257
+ "RUSTUP_USE_CURL is set, but this rustup distribution was not built with the curl-backend feature"
258
+ ) ) ;
259
+ }
260
+
261
+ let use_rustls = process. var_os ( "RUSTUP_USE_RUSTLS" ) . map ( |it| it != "0" ) ;
262
+ #[ cfg( not( feature = "reqwest-rustls-tls" ) ) ]
263
+ if use_rustls == Some ( true ) {
264
+ return Err ( anyhow ! (
265
+ "RUSTUP_USE_RUSTLS is set, but this rustup distribution was not built with the reqwest-rustls-tls feature"
266
+ ) ) ;
267
+ }
268
+ #[ cfg( not( feature = "reqwest-native-tls" ) ) ]
269
+ if use_rustls == Some ( false ) {
270
+ return Err ( anyhow ! (
271
+ "RUSTUP_USE_RUSTLS is set to false, but this rustup distribution was not built with the reqwest-native-tls feature"
272
+ ) ) ;
273
+ }
274
+
275
+ let backend = match use_curl_backend {
276
+ #[ cfg( feature = "reqwest-backend" ) ]
277
+ None | Some ( false ) => Backend :: Reqwest ( match use_rustls {
278
+ #[ cfg( feature = "reqwest-rustls-tls" ) ]
279
+ Some ( true ) | None => {
280
+ if use_curl_backend == Some ( true ) {
281
+ info ! (
282
+ "both RUSTUP_USE_CURL and RUSTUP_USE_RUSTLS are set, using reqwest with rustls"
283
+ ) ;
284
+ }
285
+ TlsBackend :: Rustls
286
+ }
261
287
#[ cfg( feature = "reqwest-native-tls" ) ]
262
- {
288
+ Some ( false ) => {
289
+ if use_curl_backend == Some ( true ) {
290
+ info ! ( "RUSTUP_USE_CURL is set and RUSTUP_USE_RUSTLS is set to off, using reqwest with native-tls" ) ;
291
+ }
263
292
TlsBackend :: NativeTls
264
293
}
294
+ #[ cfg( not( feature = "reqwest-rustls-tls" ) ) ]
295
+ None => TlsBackend :: NativeTls ,
265
296
#[ cfg( not( feature = "reqwest-native-tls" ) ) ]
266
- {
267
- TlsBackend :: Rustls
268
- }
269
- } ;
270
- Backend :: Reqwest ( tls_backend)
297
+ Some ( false ) => return Err ( anyhow ! (
298
+ "RUSTUP_USE_RUSTLS is set to false, but this rustup distribution was not built with the reqwest-native-tls feature"
299
+ ) ) ,
300
+ #[ cfg( not( feature = "reqwest-rustls-tls" ) ) ]
301
+ Some ( true ) => return Err ( anyhow ! (
302
+ "RUSTUP_USE_RUSTLS is set, but this rustup distribution was not built with the reqwest-rustls-tls feature"
303
+ ) ) ,
304
+ } ) ,
305
+ #[ cfg( feature = "curl-backend" ) ]
306
+ Some ( true ) => Backend :: Curl ,
307
+ #[ cfg( not( feature = "curl-backend" ) ) ]
308
+ Some ( true ) => return Err ( anyhow ! (
309
+ "RUSTUP_USE_CURL is set, but this rustup distribution was not built with the curl-backend feature"
310
+ ) ) ,
311
+ #[ cfg( not( feature = "reqwest-backend" ) ) ]
312
+ Some ( false ) => return Err ( anyhow ! (
313
+ "RUSTUP_USE_CURL is set, but this rustup distribution was not built with the reqwest-backend feature"
314
+ ) ) ,
315
+ #[ cfg( not( feature = "reqwest-backend" ) ) ]
316
+ None => Backend :: Curl ,
271
317
} ;
272
318
273
319
notify_handler ( match backend {
0 commit comments