@@ -13,8 +13,8 @@ use crate::docbuilder::Limits;
13
13
use crate :: error:: Result ;
14
14
use crate :: repositories:: RepositoryStatsUpdater ;
15
15
use crate :: storage:: {
16
- RustdocJsonFormatVersion , get_file_list , rustdoc_archive_path , rustdoc_json_path ,
17
- source_archive_path,
16
+ CompressionAlgorithm , RustdocJsonFormatVersion , compress , get_file_list , rustdoc_archive_path ,
17
+ rustdoc_json_path , source_archive_path,
18
18
} ;
19
19
use crate :: utils:: {
20
20
CargoMetadata , ConfigName , copy_dir_all, get_config, parse_rustc_version, report_error,
@@ -45,6 +45,9 @@ const COMPONENTS: &[&str] = &["llvm-tools-preview", "rustc-dev", "rustfmt"];
45
45
const DUMMY_CRATE_NAME : & str = "empty-library" ;
46
46
const DUMMY_CRATE_VERSION : & str = "1.0.0" ;
47
47
48
+ pub const RUSTDOC_JSON_COMPRESSION_ALGORITHMS : & [ CompressionAlgorithm ] =
49
+ & [ CompressionAlgorithm :: Zstd , CompressionAlgorithm :: Gzip ] ;
50
+
48
51
/// read the format version from a rustdoc JSON file.
49
52
fn read_format_version_from_rustdoc_json (
50
53
reader : impl std:: io:: Read ,
@@ -909,12 +912,25 @@ impl RustwideBuilder {
909
912
. context ( "couldn't parse rustdoc json to find format version" ) ?
910
913
} ;
911
914
912
- for format_version in [ format_version, RustdocJsonFormatVersion :: Latest ] {
913
- let _span = info_span ! ( "store_json" , %format_version) . entered ( ) ;
914
- let path = rustdoc_json_path ( name, version, target, format_version) ;
915
+ for alg in RUSTDOC_JSON_COMPRESSION_ALGORITHMS {
916
+ let compressed_json: Vec < u8 > = {
917
+ let _span =
918
+ info_span ! ( "compress_json" , file_size = json_filename. metadata( ) ?. len( ) , algorithm=%alg)
919
+ . entered ( ) ;
920
+
921
+ compress ( BufReader :: new ( File :: open ( & json_filename) ?) , * alg) ?
922
+ } ;
915
923
916
- self . storage . store_path ( & path, & json_filename) ?;
917
- self . storage . set_public_access ( & path, true ) ?;
924
+ for format_version in [ format_version, RustdocJsonFormatVersion :: Latest ] {
925
+ let path = rustdoc_json_path ( name, version, target, format_version, Some ( * alg) ) ;
926
+ let _span =
927
+ info_span ! ( "store_json" , %format_version, algorithm=%alg, target_path=%path)
928
+ . entered ( ) ;
929
+
930
+ self . storage
931
+ . store_one_uncompressed ( & path, compressed_json. clone ( ) ) ?;
932
+ self . storage . set_public_access ( & path, true ) ?;
933
+ }
918
934
}
919
935
920
936
Ok ( ( ) )
@@ -1279,7 +1295,7 @@ mod tests {
1279
1295
use super :: * ;
1280
1296
use crate :: db:: types:: Feature ;
1281
1297
use crate :: registry_api:: ReleaseData ;
1282
- use crate :: storage:: CompressionAlgorithm ;
1298
+ use crate :: storage:: { CompressionAlgorithm , compression } ;
1283
1299
use crate :: test:: { AxumRouterTestExt , TestEnvironment , wrapper} ;
1284
1300
use std:: { io, iter} ;
1285
1301
use test_case:: test_case;
@@ -1467,29 +1483,39 @@ mod tests {
1467
1483
1468
1484
// other targets too
1469
1485
for target in DEFAULT_TARGETS {
1470
- // check if rustdoc json files exist for all targets
1471
- let path = rustdoc_json_path (
1472
- crate_,
1473
- version,
1474
- target,
1475
- RustdocJsonFormatVersion :: Latest ,
1476
- ) ;
1477
- assert ! ( storage. exists( & path) ?) ;
1478
- assert ! ( storage. get_public_access( & path) ?) ;
1479
-
1480
- let json_prefix = format ! ( "rustdoc-json/{crate_}/{version}/{target}/" ) ;
1481
- let mut json_files: Vec < _ > = storage
1482
- . list_prefix ( & json_prefix)
1483
- . filter_map ( |res| res. ok ( ) )
1484
- . map ( |f| f. strip_prefix ( & json_prefix) . unwrap ( ) . to_owned ( ) )
1485
- . collect ( ) ;
1486
- json_files. sort ( ) ;
1487
- assert ! ( json_files[ 0 ] . starts_with( & format!( "empty-library_1.0.0_{target}_" ) ) ) ;
1488
- assert ! ( json_files[ 0 ] . ends_with( ".json" ) ) ;
1489
- assert_eq ! (
1490
- json_files[ 1 ] ,
1491
- format!( "empty-library_1.0.0_{target}_latest.json" )
1492
- ) ;
1486
+ for alg in RUSTDOC_JSON_COMPRESSION_ALGORITHMS {
1487
+ // check if rustdoc json files exist for all targets
1488
+ let path = rustdoc_json_path (
1489
+ crate_,
1490
+ version,
1491
+ target,
1492
+ RustdocJsonFormatVersion :: Latest ,
1493
+ Some ( * alg) ,
1494
+ ) ;
1495
+ assert ! ( storage. exists( & path) ?) ;
1496
+ assert ! ( storage. get_public_access( & path) ?) ;
1497
+
1498
+ let ext = compression:: file_extension_for ( * alg) ;
1499
+
1500
+ let json_prefix = format ! ( "rustdoc-json/{crate_}/{version}/{target}/" ) ;
1501
+ let mut json_files: Vec < _ > = storage
1502
+ . list_prefix ( & json_prefix)
1503
+ . filter_map ( |res| res. ok ( ) )
1504
+ . map ( |f| f. strip_prefix ( & json_prefix) . unwrap ( ) . to_owned ( ) )
1505
+ . collect ( ) ;
1506
+ json_files. retain ( |f| f. ends_with ( & format ! ( ".json.{ext}" ) ) ) ;
1507
+ json_files. sort ( ) ;
1508
+ dbg ! ( & json_files) ;
1509
+ assert ! (
1510
+ json_files[ 0 ] . starts_with( & format!( "empty-library_1.0.0_{target}_" ) )
1511
+ ) ;
1512
+
1513
+ assert ! ( json_files[ 0 ] . ends_with( & format!( ".json.{ext}" ) ) ) ;
1514
+ assert_eq ! (
1515
+ json_files[ 1 ] ,
1516
+ format!( "empty-library_1.0.0_{target}_latest.json.{ext}" )
1517
+ ) ;
1518
+ }
1493
1519
1494
1520
if target == & default_target {
1495
1521
continue ;
0 commit comments