Skip to content

Commit bc074ab

Browse files
committed
readjust static binary release asset resolution
for newer static binary releases which - only use the major version - support arm64 (on unix but not windows) as well as amd64 (on all OS)
1 parent 45cfdef commit bc074ab

2 files changed

Lines changed: 30 additions & 35 deletions

File tree

clang-installer/src/downloader/static_dist.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! A module to download static binaries from cpp-linter/clang-tools-static-binaries.
22
33
use std::{
4-
env::consts,
54
fs,
65
ops::RangeInclusive,
76
path::{Path, PathBuf},
@@ -67,18 +66,10 @@ impl StaticDistDownloader {
6766
fn find_suitable_version(req_ver: &VersionReq) -> Option<Version> {
6867
let clang_tools_versions: RangeInclusive<u8> = Self::get_major_version_range();
6968
println!("Available clang tools versions: {clang_tools_versions:?}");
70-
let outlier = Version::new(12, 0, 1);
71-
for ver in clang_tools_versions
69+
clang_tools_versions
7270
.map(|v| Version::new(v as u64, 0, 0))
7371
.rev()
74-
{
75-
if ver.major == 12 && req_ver.matches(&outlier) {
76-
return Some(outlier);
77-
} else if req_ver.matches(&ver) {
78-
return Some(ver);
79-
}
80-
}
81-
None
72+
.find(|ver| req_ver.matches(ver))
8273
}
8374

8475
/// Verifies the SHA512 checksum of the downloaded file.
@@ -105,34 +96,43 @@ impl StaticDistDownloader {
10596
requested_version: &VersionReq,
10697
directory: Option<&PathBuf>,
10798
) -> Result<PathBuf, StaticDistDownloadError> {
108-
if consts::ARCH != "x86_64" {
109-
return Err(StaticDistDownloadError::UnsupportedArchitecture);
110-
}
99+
#[cfg(any(
100+
// Windows support is only for x86_64 architecture (for now)
101+
all(target_os = "windows", not(target_arch = "x86_64")),
102+
// Non-Windows platforms support only x86_64 and aarch64 architectures
103+
all(
104+
unix,
105+
not(any(target_arch = "x86_64", target_arch = "aarch64"))
106+
)
107+
))]
108+
return Err(StaticDistDownloadError::UnsupportedArchitecture);
109+
111110
let ver = Self::find_suitable_version(requested_version)
112111
.ok_or(StaticDistDownloadError::UnsupportedVersion)?;
113-
let ver_str = if ver.minor == 0 && ver.patch == 0 {
114-
ver.major.to_string()
112+
let ver_str = ver.major.to_string();
113+
// we already gated unsupported architectures above,
114+
// so we can assume it's either x86_64 or aarch64 here
115+
let arch = if cfg!(target_arch = "aarch64") {
116+
"arm64"
115117
} else {
116-
ver.to_string()
118+
"amd64"
117119
};
118-
let suffix = if cfg!(target_os = "windows") {
119-
".exe"
120+
let platform = if cfg!(target_os = "windows") {
121+
"windows"
122+
} else if cfg!(target_os = "macos") {
123+
"macos"
120124
} else {
121-
""
125+
"linux"
122126
};
123-
let clang_tools_repo: &str = option_env!("CLANG_TOOLS_REPO").unwrap_or(CLANG_TOOLS_REPO);
124-
let clang_tools_tag: &str = option_env!("CLANG_TOOLS_TAG").unwrap_or(CLANG_TOOLS_TAG);
125127

126128
let base_url = format!(
127-
"{clang_tools_repo}/releases/download/{clang_tools_tag}/{tool}-{ver_str}_{}-amd64",
128-
if cfg!(target_os = "windows") {
129-
"windows"
130-
} else if cfg!(target_os = "macos") {
131-
"macos"
132-
} else {
133-
"linux"
134-
},
129+
"{CLANG_TOOLS_REPO}/releases/download/{CLANG_TOOLS_TAG}/{tool}-{ver_str}_{platform}-{arch}",
135130
);
131+
let suffix = if cfg!(target_os = "windows") {
132+
".exe"
133+
} else {
134+
""
135+
};
136136
let url = Url::parse(format!("{base_url}{suffix}").as_str())?;
137137
let cache_path = Self::get_cache_dir();
138138
let bin_name = format!("{tool}-{ver_str}{suffix}");

clang-installer/tests/static_dist.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,3 @@ async fn setup(ver_spec: &str) {
4545
async fn download_clang_format_17() {
4646
setup("17").await;
4747
}
48-
49-
#[tokio::test]
50-
async fn download_clang_format_12_0_1() {
51-
setup("=12.0.1").await;
52-
}

0 commit comments

Comments
 (0)