Skip to content

Commit d3922e7

Browse files
authored
fix: updates for latest static binaries (#398)
- use unified SHA512 checksums file - download binaries for windows arm64 also includes some changes that satisify new clippy lints (per Rust v1.97.0). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Expanded static binary downloads to support both x86_64 and aarch64 on Windows, Linux, and macOS. * **Bug Fixes** * Improved static distribution verification by matching downloads against a shared `SHA512SUMS` entry. * Updated SHA-512 support selection for the relevant platform/architecture targets. * **Documentation / Improvements** * Refined clang-tidy output formatting for generated suggestions and line filtering. * Adjusted CLI subcommand help text generation to avoid minor formatting inconsistencies. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent d41b370 commit d3922e7

5 files changed

Lines changed: 55 additions & 52 deletions

File tree

clang-tools-manager/src/downloader/hashing.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,25 @@ use std::{fs, io::Read, num::NonZero, path::Path};
1515
#[derive(Debug, Clone)]
1616
pub enum HashAlgorithm {
1717
/// SHA-256 hash algorithm with the expected checksum value.
18+
///
19+
/// Used by the PyPI downloader.
1820
Sha256(String),
1921

2022
/// BLAKE2b-256 hash algorithm with the expected checksum value.
23+
///
24+
/// Used by the PyPI downloader.
2125
Blake2b256(String),
2226

2327
/// SHA-512 hash algorithm with the expected checksum value.
24-
#[cfg(any(
25-
// Windows support is only for x86_64 architecture (for now)
26-
all(target_os = "windows", target_arch = "x86_64"),
27-
// Linux and macOS support only x86_64 and aarch64 architectures
28+
///
29+
/// Used exclusively by the static distribution downloader.
30+
#[cfg(
31+
// Windows, Linux, and MacOS support only x86_64 and aarch64 architectures
2832
all(
29-
any(target_os = "linux", target_os = "macos"),
33+
any(target_os = "windows", target_os = "linux", target_os = "macos"),
3034
any(target_arch = "x86_64", target_arch = "aarch64")
31-
),
32-
))]
35+
)
36+
)]
3337
Sha512(String),
3438
}
3539

@@ -85,15 +89,13 @@ impl HashAlgorithm {
8589
let hasher = Blake2b::<U32>::new();
8690
Self::hash_file(hasher, file_path, expected)
8791
}
88-
#[cfg(any(
89-
// Windows support is only for x86_64 architecture (for now)
90-
all(target_os = "windows", target_arch = "x86_64"),
91-
// Linux and macOS support only x86_64 and aarch64 architectures
92+
#[cfg(
93+
// Windows, Linux, and MacOS support only x86_64 and aarch64 architectures
9294
all(
93-
any(target_os = "linux", target_os = "macos"),
95+
any(target_os = "windows", target_os = "linux", target_os = "macos"),
9496
any(target_arch = "x86_64", target_arch = "aarch64")
9597
),
96-
))]
98+
)]
9799
HashAlgorithm::Sha512(expected) => {
98100
use sha2::{Digest, Sha512};
99101

clang-tools-manager/src/downloader/static_dist.rs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
)]
9388
mod 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
}

cpp-linter/src/clang_tools/clang_tidy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub fn run_clang_tidy(
306306
if !ranges.is_empty() {
307307
let filter = format!(
308308
"[{{\"name\":{:?},\"lines\":{:?}}}]",
309-
&file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
309+
file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
310310
ranges
311311
.iter()
312312
.map(|r| [r.start(), r.end()])

cpp-linter/src/common_fs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,15 @@ impl FileObj {
258258
}
259259
let mut suggestion = format!(
260260
"### clang-tidy diagnostic\n**{file_name}:{}:{}** {}: [{}]\n\n> {}\n",
261-
&note.line,
262-
&note.cols,
263-
&note.severity,
261+
note.line,
262+
note.cols,
263+
note.severity,
264264
note.diagnostic_link(),
265-
&note.rationale
265+
note.rationale
266266
);
267267
if !note.suggestion.is_empty() {
268268
suggestion.push_str(
269-
format!("\n```{file_ext}\n{}\n```\n", &note.suggestion.join("\n"))
269+
format!("\n```{file_ext}\n{}\n```\n", note.suggestion.join("\n"))
270270
.as_str(),
271271
);
272272
}

docs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn generate_cli_doc(metadata: HashMap<String, HashMap<String, Py<PyAny>>>) -> Py
3535
out.push_str(
3636
format!(
3737
"{}\n",
38-
&cmd.get_about()
38+
cmd.get_about()
3939
.ok_or(PyValueError::new_err(format!(
4040
"{} command has no help message",
4141
cmd.get_name()

0 commit comments

Comments
 (0)