Skip to content

Commit ace4f60

Browse files
authored
feat: get static binaries from per-version releases (#510)
Before: `clang-tools-manager` downloaded every static binary from the single release behind `releases/latest` (`2026.09.01-5fb8802d`), using that release's `versions.json` at build time. Since cpp-linter/clang-tools-static-binaries#142, new LLVM builds no longer go into that release, so they never reach clang-tools-manager. After: the build script reads the static binaries' [`index.json`](https://cpp-linter.github.io/clang-tools-static-binaries/index.json), which lists one immutable release per LLVM version (`llvm-12.0.1` … `llvm-23.1.0`). Each binary is downloaded from its own version's release and checked against that release's `SHA512SUMS`. How: `build.rs` fetches `index.json` (still cached for 24 hours, and still shipped in the crate for docs.rs, now as `static-binaries-index.json`), checks `schema_version == 1`, emits `MIN/MAX_CLANG_TOOLS_VERSION` as before, and writes a `(major, release tag)` table to `OUT_DIR`. `find_suitable_version()` now returns the tag along with the version. The cached `SHA512SUMS` moved to `static_dist/<tag>/SHA512SUMS`, so a rebuilt release (`llvm-X.Y.Z-2`) never reuses stale checksums. The pre-seed workflow, the dev-test version loop and `nur seed versions` read the new file. The public API does not change. Tested locally: lib tests pass, and a temporary test downloaded and verified clang-format 12 and 23 from their own releases. <!-- claude-projects-attribution: {"github_login":"shenxianpeng"} --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Static binary downloads now use version-specific release information and checksum data. * ARM64 is listed alongside x86_64 as a supported architecture, including on Windows. * **Bug Fixes** * Version information is now retrieved from the published static binaries index across builds, tests, and package preparation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com>
1 parent 4cb2e2c commit ace4f60

9 files changed

Lines changed: 108 additions & 65 deletions

File tree

‎.github/workflows/binary-builds.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ jobs:
224224
PKG_NAME: ${{ startsWith(github.ref_name, 'cpp-linter') && 'cpp-linter' || 'clang-tools-manager' }}
225225
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
226226
# `--allow-dirty` is required for clang-tools-manager
227-
# because the versions.json file is flagged as "not checked in",
228-
# but docs.rs build requires the versions.json file present to
227+
# because the static-binaries-index.json file is flagged as "not checked in",
228+
# but docs.rs build requires the static-binaries-index.json file present to
229229
# avoid clang-tools-manager/build.rs using network access.
230230
PUB_ARG: ${{ startsWith(github.ref_name, 'clang-tools-manager/v') && '--allow-dirty' || '' }}
231231
run: cargo publish -p ${PKG_NAME} ${PUB_ARG}

‎.github/workflows/pre-seed-versions.yml‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
outputs:
66
artifact-name:
77
description: >-
8-
The name of uploaded artifact containing the versions.json file.
8+
The name of uploaded artifact containing the static-binaries-index.json file.
99
value: static-binary-versions
1010

1111
permissions: {}
@@ -14,16 +14,14 @@ jobs:
1414
pre-seed-versions:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- env:
18-
GITHUB_TOKEN: ${{ github.token }}
17+
- name: Download static binaries index
1918
run: >-
20-
gh release download
21-
-R cpp-linter/clang-tools-static-binaries
22-
--pattern versions.json
23-
--output versions.json
24-
- name: Upload versions.json
19+
curl --fail --silent --show-error --location --retry 3
20+
--output static-binaries-index.json
21+
https://cpp-linter.github.io/clang-tools-static-binaries/index.json
22+
- name: Upload static-binaries-index.json
2523
uses: actions/upload-artifact@v7
2624
with:
2725
name: static-binary-versions
28-
path: versions.json
26+
path: static-binaries-index.json
2927
if-no-files-found: error

‎.github/workflows/run-dev-tests.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ jobs:
112112
- name: Run test suite
113113
shell: nu {0}
114114
run: |-
115-
let version_info = open "clang-tools-manager/versions.json"
115+
let version_info = open "clang-tools-manager/static-binaries-index.json"
116116
mut max_ver = 0
117117
mut min_ver = 99
118-
for ver in ($version_info.llvm_versions | columns) {
118+
for ver in ($version_info.versions | columns) {
119119
let ver = $ver | into int
120120
if ($ver < $min_ver) {
121121
$min_ver = $ver

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,4 @@ cpp-linter-py/docs/cli_args.rst
347347
lcov.info
348348
coverage.json
349349
.config/ReleaseNotes.md
350-
versions.json
350+
static-binaries-index.json

‎clang-tools-manager/Cargo.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ homepage.workspace = true
1010
license.workspace = true
1111
edition.workspace = true
1212
repository.workspace = true
13-
# Include a pre-seeded versions.json file in package published to crates.io.
13+
# Include a pre-seeded static-binaries-index.json file in package published to crates.io.
1414
# This is invalidated after 24 hours, but it allows docs.rs builds to succeed.
15-
include = ["versions.json", "src/**", "Cargo.toml", "README.md", "build.rs", "tests/**"]
15+
include = ["static-binaries-index.json", "src/**", "Cargo.toml", "README.md", "build.rs", "tests/**"]
1616

1717
[[bin]]
1818
path = "src/main.rs"

‎clang-tools-manager/build.rs‎

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
use std::{
2-
fs,
2+
collections::BTreeMap,
3+
env, fs,
34
io::Write,
45
path::PathBuf,
56
time::{Duration, SystemTime},
67
};
78

89
use reqwest::blocking::ClientBuilder;
910

10-
const URL: &str = "https://github.com/cpp-linter/clang-tools-static-binaries/releases/latest/download/versions.json";
11+
/// The index of all static binaries, one release per LLVM version.
12+
const URL: &str = "https://cpp-linter.github.io/clang-tools-static-binaries/index.json";
13+
14+
/// The only index format this build script understands.
15+
const INDEX_SCHEMA_VERSION: u8 = 1;
16+
17+
#[derive(Debug, serde::Deserialize)]
18+
struct StaticBinariesIndex {
19+
schema_version: u8,
20+
versions: BTreeMap<u8, VersionEntry>,
21+
}
1122

1223
#[derive(Debug, serde::Deserialize)]
13-
struct VersionInfo {
14-
release_tag: String,
15-
llvm_versions: std::collections::HashMap<u8, String>,
24+
struct VersionEntry {
25+
/// The release tag that holds this LLVM version's binaries.
26+
tag: String,
1627
}
28+
1729
fn main() {
18-
let pre_seed = PathBuf::from("versions.json");
19-
let version_info_str = if pre_seed.exists()
30+
let pre_seed = PathBuf::from("static-binaries-index.json");
31+
let index_str = if pre_seed.exists()
2032
&& let Ok(metadata) = fs::metadata(&pre_seed)
21-
// if this is a docs.rs build, then use the versions,json present in the package.
22-
&& (std::env::var_os("DOCS_RS").is_some()
33+
// if this is a docs.rs build, then use the index present in the package.
34+
&& (env::var_os("DOCS_RS").is_some()
2335
// otherwise, check if the file is not too old (24 hours)
2436
|| metadata.modified().is_ok_and(|d| {
2537
SystemTime::now()
@@ -28,7 +40,7 @@ fn main() {
2840
.unwrap_or(Duration::from_hours(25))
2941
< Duration::from_hours(24)
3042
})) {
31-
println!("cargo:warning=Using pre-seeded version info from {pre_seed:?}");
43+
println!("cargo:warning=Using pre-seeded static binaries index from {pre_seed:?}");
3244
fs::read_to_string(&pre_seed).unwrap()
3345
} else {
3446
let versions = ClientBuilder::new()
@@ -51,23 +63,30 @@ fn main() {
5163
cached_seed.set_modified(SystemTime::now()).unwrap();
5264
versions
5365
};
54-
let version_info: VersionInfo = serde_json::from_str(&version_info_str).unwrap();
55-
let (min_ver, max_ver) = {
56-
let (mut min_v, mut max_v) = (None, None);
57-
for ver in version_info.llvm_versions.keys() {
58-
if min_v.is_none_or(|v| v > ver) {
59-
min_v = Some(ver);
60-
}
61-
if max_v.is_none_or(|v| v < ver) {
62-
max_v = Some(ver);
63-
}
64-
}
65-
(min_v.unwrap(), max_v.unwrap())
66-
};
67-
println!(
68-
"cargo:rustc-env=CLANG_TOOLS_TAG={}",
69-
version_info.release_tag
66+
let index: StaticBinariesIndex = serde_json::from_str(&index_str).unwrap();
67+
assert_eq!(
68+
index.schema_version, INDEX_SCHEMA_VERSION,
69+
"Unsupported schema version of {URL}"
7070
);
71+
let min_ver = index
72+
.versions
73+
.keys()
74+
.next()
75+
.expect("index lists no versions");
76+
let max_ver = index.versions.keys().next_back().unwrap();
7177
println!("cargo:rustc-env=MIN_CLANG_TOOLS_VERSION={min_ver}");
7278
println!("cargo:rustc-env=MAX_CLANG_TOOLS_VERSION={max_ver}");
79+
80+
// Each LLVM version is published in its own release.
81+
let release_tags = index
82+
.versions
83+
.iter()
84+
.map(|(major, entry)| format!(" ({major}, {:?}),\n", entry.tag))
85+
.collect::<String>();
86+
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
87+
fs::write(
88+
out_dir.join("release_tags.rs"),
89+
format!("&[\n{release_tags}]\n"),
90+
)
91+
.unwrap();
7392
}

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

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ mod supported_platform {
8989
use std::{
9090
fs,
9191
io::{BufRead, BufReader},
92-
ops::RangeInclusive,
9392
path::{Path, PathBuf},
9493
};
9594

@@ -104,19 +103,24 @@ mod supported_platform {
104103
};
105104

106105
const CLANG_TOOLS_REPO: &str = "https://github.com/cpp-linter/clang-tools-static-binaries";
107-
const CLANG_TOOLS_TAG: &str = env!("CLANG_TOOLS_TAG");
106+
107+
/// Each available LLVM major version and the release tag that holds its binaries.
108+
const RELEASE_TAGS: &[(u8, &str)] = include!(concat!(env!("OUT_DIR"), "/release_tags.rs"));
108109

109110
impl StaticDistDownloader {
110-
/// Finds a suitable version from `req_ver` within the range of available clang tools versions.
111+
/// Finds the newest available version that satisfies `req_ver`,
112+
/// along with the release tag that holds its binaries.
111113
///
112-
/// The available versions are determined by the `MIN_CLANG_TOOLS_VERSION` and
113-
/// `MAX_CLANG_TOOLS_VERSION` environment variables (inclusive) at compile time.
114-
fn find_suitable_version(req_ver: &VersionReq) -> Option<Version> {
115-
let clang_tools_versions: RangeInclusive<u8> = Self::get_major_version_range();
116-
clang_tools_versions
117-
.map(|v| Version::new(v as u64, 0, 0))
114+
/// The available versions (and their release tags) are read from the
115+
/// static binaries' `index.json` at compile time.
116+
pub(crate) fn find_suitable_version(
117+
req_ver: &VersionReq,
118+
) -> Option<(Version, &'static str)> {
119+
RELEASE_TAGS
120+
.iter()
118121
.rev()
119-
.find(|ver| req_ver.matches(ver))
122+
.map(|(major, tag)| (Version::new(*major as u64, 0, 0), *tag))
123+
.find(|(ver, _)| req_ver.matches(ver))
120124
}
121125

122126
/// Verifies the SHA512 checksum of the downloaded file.
@@ -146,18 +150,25 @@ mod supported_platform {
146150
Ok(())
147151
}
148152

153+
/// The cached `SHA512SUMS` file of the release tagged `release_tag`.
154+
pub(crate) fn sha512_cache_path(release_tag: &str) -> PathBuf {
155+
Self::get_cache_dir()
156+
.join("static_dist")
157+
.join(release_tag)
158+
.join("SHA512SUMS")
159+
}
160+
149161
/// Downloads the `requested_version` of the specified `tool` from a distribution of statically linked binaries.
150162
///
151163
/// The distribution is maintained at <https://github.com/cpp-linter/clang-tools-static-binaries>.
152164
/// Supported platforms includes Windows, Linux, and MacOS.
153-
/// Supported architectures is limited to `x86_64` (`amd64`) and `aarch64` (`arm64`);
154-
/// Windows only supports x86_64 architecture (for now).
165+
/// Supported architectures is limited to `x86_64` (`amd64`) and `aarch64` (`arm64`).
155166
pub async fn download_tool(
156167
tool: &ClangTool,
157168
requested_version: &VersionReq,
158169
directory: Option<&PathBuf>,
159170
) -> Result<PathBuf, StaticDistDownloadError> {
160-
let ver = Self::find_suitable_version(requested_version)
171+
let (ver, release_tag) = Self::find_suitable_version(requested_version)
161172
.ok_or(StaticDistDownloadError::UnsupportedVersion)?;
162173
let ver_str = ver.major.to_string();
163174
// we already gated unsupported architectures above,
@@ -175,7 +186,7 @@ mod supported_platform {
175186
"linux"
176187
};
177188

178-
let base_url = format!("{CLANG_TOOLS_REPO}/releases/download/{CLANG_TOOLS_TAG}/",);
189+
let base_url = format!("{CLANG_TOOLS_REPO}/releases/download/{release_tag}/");
179190
let suffix = if cfg!(target_os = "windows") {
180191
".exe"
181192
} else {
@@ -201,7 +212,7 @@ mod supported_platform {
201212
#[cfg(unix)]
202213
super::super::chmod_file(&download_path, None)?;
203214
}
204-
let sha512_cache_path = cache_path.join("static_dist").join("SHA512SUMS");
215+
let sha512_cache_path = Self::sha512_cache_path(release_tag);
205216
if sha512_cache_path.exists() {
206217
log::info!(
207218
"Using cached SHA512 checksums for static binaries from {:?}",
@@ -227,6 +238,14 @@ mod supported_platform {
227238
use semver::VersionReq;
228239
use tempfile::TempDir;
229240

241+
#[test]
242+
fn find_newest_with_tag() {
243+
let req_ver = VersionReq::parse(">=12").unwrap();
244+
let (ver, tag) = StaticDistDownloader::find_suitable_version(&req_ver).unwrap();
245+
assert_eq!(ver.major.to_string(), super::super::MAX_CLANG_TOOLS_VERSION);
246+
assert!(tag.starts_with(&format!("llvm-{}.", ver.major)));
247+
}
248+
230249
#[test]
231250
fn find_none() {
232251
let req_ver = VersionReq::parse("=8").unwrap();
@@ -262,7 +281,11 @@ mod supported_platform {
262281
));
263282
}
264283
}
265-
let sha512_sums = cache.path().join("static_dist").join("SHA512SUMS");
284+
let sha512_sums = StaticDistDownloader::sha512_cache_path(
285+
StaticDistDownloader::find_suitable_version(&VersionReq::parse("17").unwrap())
286+
.unwrap()
287+
.1,
288+
);
266289
fs::create_dir_all(sha512_sums.parent().unwrap()).unwrap();
267290
fs::write(&sha512_sums, sums).unwrap();
268291

‎clang-tools-manager/src/version.rs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ mod tests {
392392
use tempfile::TempDir;
393393

394394
use crate::{
395-
ClangTool, GetToolError, RequestedVersion,
395+
ClangTool, GetToolError, RequestedVersion, StaticDistDownloader,
396396
test_utils_unix::{
397397
enable_logs, fake_clang_tool, fake_exe, isolate_path, set_cache_dir,
398398
},
@@ -455,9 +455,12 @@ mod tests {
455455
checksums.push_str(&format!("{hash} clang-format-17_{platform}-{arch}\n"));
456456
}
457457
}
458-
let sums = self.cache.path().join("static_dist");
459-
fs::create_dir_all(&sums).unwrap();
460-
fs::write(sums.join("SHA512SUMS"), checksums).unwrap();
458+
let (_, release_tag) =
459+
StaticDistDownloader::find_suitable_version(&VersionReq::parse("17").unwrap())
460+
.unwrap();
461+
let sums = StaticDistDownloader::sha512_cache_path(release_tag);
462+
fs::create_dir_all(sums.parent().unwrap()).unwrap();
463+
fs::write(sums, checksums).unwrap();
461464
}
462465

463466
async fn eval(

‎nurfile‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ def "nur docs rs" [
2020
run-cmd ...$cmd
2121
}
2222

23-
const URL = "https://github.com/cpp-linter/clang-tools-static-binaries/releases/latest/download/versions.json"
23+
const URL = "https://cpp-linter.github.io/clang-tools-static-binaries/index.json"
2424

25-
# Seed the versions.json file with the latest release from GitHub.
25+
# Seed the static-binaries-index.json file with the latest index of static binaries.
2626
#
2727
# Useful to avoid network requests in local dev builds of clang-tools-manager crate.
2828
# This will instigate a warning, but that is expected.
2929
def "nur seed versions" [] {
30-
let versions = (http get $URL) | save --force clang-tools-manager/versions.json
30+
let versions = (http get $URL) | save --force clang-tools-manager/static-binaries-index.json
3131
}
3232

3333
# Build mkdocs output.

0 commit comments

Comments
 (0)