@@ -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,15 +78,13 @@ 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,
@@ -129,12 +124,14 @@ mod supported_platform {
129124 /// (pointed to by `sha512_path`).
130125 fn verify_sha512 (
131126 file_path : & Path ,
127+ tool : & str ,
132128 sha512_path : & Path ,
133129 ) -> Result < ( ) , StaticDistDownloadError > {
134130 let checksum_file_content = fs:: read_to_string ( sha512_path) ?;
135131 let expected = checksum_file_content
136- . split ( ' ' )
137- . next ( )
132+ . lines ( )
133+ . find ( |line| line. ends_with ( tool) )
134+ . and_then ( |line| line. split ( ' ' ) . next ( ) )
138135 . ok_or ( StaticDistDownloadError :: Sha512Corruption ) ?;
139136 HashAlgorithm :: Sha512 ( expected. to_string ( ) ) . verify ( file_path) ?;
140137 Ok ( ( ) )
@@ -169,15 +166,14 @@ mod supported_platform {
169166 "linux"
170167 } ;
171168
172- let base_url = format ! (
173- "{CLANG_TOOLS_REPO}/releases/download/{CLANG_TOOLS_TAG}/{tool}-{ver_str}_{platform}-{arch}" ,
174- ) ;
169+ let base_url = format ! ( "{CLANG_TOOLS_REPO}/releases/download/{CLANG_TOOLS_TAG}/" , ) ;
175170 let suffix = if cfg ! ( target_os = "windows" ) {
176171 ".exe"
177172 } else {
178173 ""
179174 } ;
180- let url = Url :: parse ( format ! ( "{base_url}{suffix}" ) . as_str ( ) ) ?;
175+ let tool_url_path = format ! ( "{tool}-{ver_str}_{platform}-{arch}{suffix}" ) ;
176+ let url = Url :: parse ( format ! ( "{base_url}{tool_url_path}" ) . as_str ( ) ) ?;
181177 let cache_path = Self :: get_cache_dir ( ) ;
182178 let bin_name = format ! ( "{tool}-{ver_str}{suffix}" ) ;
183179 let download_path = match directory {
@@ -196,22 +192,18 @@ mod supported_platform {
196192 #[ cfg( unix) ]
197193 super :: super :: chmod_file ( & download_path, None ) ?;
198194 }
199- let sha512_cache_path = cache_path
200- . join ( "static_dist" )
201- . join ( format ! ( "{tool}-{ver_str}.sha512" ) ) ;
195+ let sha512_cache_path = cache_path. join ( "static_dist" ) . join ( "SHA512SUMS" ) ;
202196 if sha512_cache_path. exists ( ) {
203197 log:: info!(
204- "Using cached SHA512 checksum for {tool} version {ver_str} from {:?}" ,
198+ "Using cached SHA512 checksums for static binaries from {:?}" ,
205199 sha512_cache_path. to_string_lossy( )
206200 ) ;
207201 } 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- ) ;
202+ let sha512_url = Url :: parse ( format ! ( "{base_url}SHA512SUMS" ) . as_str ( ) ) ?;
203+ log:: info!( "Downloading SHA512 checksum for static binaries from {sha512_url}" ) ;
212204 download ( & sha512_url, & sha512_cache_path, 10 ) . await ?;
213205 }
214- Self :: verify_sha512 ( & download_path, & sha512_cache_path) ?;
206+ Self :: verify_sha512 ( & download_path, & tool_url_path , & sha512_cache_path) ?;
215207 file_lock. unlock ( ) ?;
216208 Ok ( download_path)
217209 }
0 commit comments