@@ -19,8 +19,7 @@ pub enum StaticDistDownloadError {
1919 UnsupportedVersion ,
2020
2121 /// The static binaries are only built for
22- /// x86_64 and aarch64 architecture on Linux MacOS, and
23- /// Windows (not aarch64 for Windows currently).
22+ /// x86_64 and aarch64 architecture on Linux, MacOS, and Windows.
2423 #[ error( "The static binaries are not built for {OS} {ARCH} architecture" ) ]
2524 UnsupportedArchitecture ,
2625
@@ -54,11 +53,9 @@ impl StaticDistDownloader {
5453}
5554
5655#[ cfg( any(
57- // Windows support is only for x86_64 architecture (for now)
58- all( target_os = "windows" , not( target_arch = "x86_64" ) ) ,
59- // Linux and macOS support only x86_64 and aarch64 architectures
56+ // Windows, Linux, and MacOS support only x86_64 and aarch64 architectures
6057 all(
61- any( target_os = "linux" , target_os = "macos" ) ,
58+ any( target_os = "windows" , target_os = " linux", target_os = "macos" ) ,
6259 not( any( target_arch = "x86_64" , target_arch = "aarch64" ) )
6360 ) ,
6461 // Any OS other than Windows, Linux, or macOS is unsupported
@@ -81,18 +78,17 @@ mod unsupported_platform {
8178 }
8279}
8380
84- #[ cfg( any(
85- // Windows support is only for x86_64 architecture (for now)
86- all( target_os = "windows" , target_arch = "x86_64" ) ,
87- // Linux and macOS support only x86_64 and aarch64 architectures
81+ #[ cfg(
82+ // Windows, Linux, and MacOS support only x86_64 and aarch64 architectures
8883 all(
89- any( target_os = "linux" , target_os = "macos" ) ,
84+ any( target_os = "windows" , target_os = " linux", target_os = "macos" ) ,
9085 any( target_arch = "x86_64" , target_arch = "aarch64" )
9186 ) ,
92- ) ) ]
87+ ) ]
9388mod supported_platform {
9489 use std:: {
9590 fs,
91+ io:: { BufRead , BufReader } ,
9692 ops:: RangeInclusive ,
9793 path:: { Path , PathBuf } ,
9894 } ;
@@ -125,18 +121,28 @@ mod supported_platform {
125121
126122 /// Verifies the SHA512 checksum of the downloaded file.
127123 ///
128- /// The expected checksum is extracted from another downloaded `*.sha512sum ` file
124+ /// The expected checksum is extracted from another downloaded `SHA512SUMS ` file
129125 /// (pointed to by `sha512_path`).
130126 fn verify_sha512 (
131127 file_path : & Path ,
128+ tool : & str ,
132129 sha512_path : & Path ,
133130 ) -> Result < ( ) , StaticDistDownloadError > {
134- let checksum_file_content = fs:: read_to_string ( sha512_path) ?;
135- let expected = checksum_file_content
136- . split ( ' ' )
137- . next ( )
138- . ok_or ( StaticDistDownloadError :: Sha512Corruption ) ?;
139- HashAlgorithm :: Sha512 ( expected. to_string ( ) ) . verify ( file_path) ?;
131+ let expected = {
132+ let checksum_file_handle = fs:: File :: open ( sha512_path) ?;
133+ let checksum_file_content = BufReader :: new ( checksum_file_handle) ;
134+ let mut found = None ;
135+ for line in checksum_file_content. lines ( ) {
136+ let line = line?;
137+ if line. ends_with ( tool) {
138+ found = line. split ( ' ' ) . next ( ) . map ( |s| s. trim ( ) . to_string ( ) ) ;
139+ break ;
140+ }
141+ }
142+ found
143+ }
144+ . ok_or ( StaticDistDownloadError :: Sha512Corruption ) ?;
145+ HashAlgorithm :: Sha512 ( expected) . verify ( file_path) ?;
140146 Ok ( ( ) )
141147 }
142148
@@ -169,15 +175,14 @@ mod supported_platform {
169175 "linux"
170176 } ;
171177
172- let base_url = format ! (
173- "{CLANG_TOOLS_REPO}/releases/download/{CLANG_TOOLS_TAG}/{tool}-{ver_str}_{platform}-{arch}" ,
174- ) ;
178+ let base_url = format ! ( "{CLANG_TOOLS_REPO}/releases/download/{CLANG_TOOLS_TAG}/" , ) ;
175179 let suffix = if cfg ! ( target_os = "windows" ) {
176180 ".exe"
177181 } else {
178182 ""
179183 } ;
180- let url = Url :: parse ( format ! ( "{base_url}{suffix}" ) . as_str ( ) ) ?;
184+ let tool_url_path = format ! ( "{tool}-{ver_str}_{platform}-{arch}{suffix}" ) ;
185+ let url = Url :: parse ( format ! ( "{base_url}{tool_url_path}" ) . as_str ( ) ) ?;
181186 let cache_path = Self :: get_cache_dir ( ) ;
182187 let bin_name = format ! ( "{tool}-{ver_str}{suffix}" ) ;
183188 let download_path = match directory {
@@ -196,22 +201,18 @@ mod supported_platform {
196201 #[ cfg( unix) ]
197202 super :: super :: chmod_file ( & download_path, None ) ?;
198203 }
199- let sha512_cache_path = cache_path
200- . join ( "static_dist" )
201- . join ( format ! ( "{tool}-{ver_str}.sha512" ) ) ;
204+ let sha512_cache_path = cache_path. join ( "static_dist" ) . join ( "SHA512SUMS" ) ;
202205 if sha512_cache_path. exists ( ) {
203206 log:: info!(
204- "Using cached SHA512 checksum for {tool} version {ver_str} from {:?}" ,
207+ "Using cached SHA512 checksums for static binaries from {:?}" ,
205208 sha512_cache_path. to_string_lossy( )
206209 ) ;
207210 } else {
208- let sha512_url = Url :: parse ( format ! ( "{base_url}{suffix}.sha512sum" ) . as_str ( ) ) ?;
209- log:: info!(
210- "Downloading SHA512 checksum for {tool} version {ver_str} from {sha512_url}"
211- ) ;
211+ let sha512_url = Url :: parse ( format ! ( "{base_url}SHA512SUMS" ) . as_str ( ) ) ?;
212+ log:: info!( "Downloading SHA512 checksum for static binaries from {sha512_url}" ) ;
212213 download ( & sha512_url, & sha512_cache_path, 10 ) . await ?;
213214 }
214- Self :: verify_sha512 ( & download_path, & sha512_cache_path) ?;
215+ Self :: verify_sha512 ( & download_path, & tool_url_path , & sha512_cache_path) ?;
215216 file_lock. unlock ( ) ?;
216217 Ok ( download_path)
217218 }
0 commit comments