Skip to content

Commit 997173f

Browse files
committed
feat: set clang version min and max at compile time
This adds a build script that downloads versions.json from `cpp-linter/clang-tools-static-binaries` latest release and injects it into the production code using compile-time-only environment variables. Includes a similar adjustment to the test CI job in some inline nu shell script that employs gh-cli instead of direct download.
1 parent 8e2fcad commit 997173f

7 files changed

Lines changed: 114 additions & 34 deletions

File tree

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,23 @@ jobs:
9797
uses: hustcer/setup-nu@92c296ba1ba2ba04cc948ab64ddefe192dc13f0c # v3.23
9898

9999
- name: Run test suite
100-
env:
101-
MIN_CLANG_TOOLS_VERSION: "11"
102-
MAX_CLANG_TOOLS_VERSION: "22"
103100
shell: nu {0}
104101
run: |-
105-
let max_ver = $env.MAX_CLANG_TOOLS_VERSION | into int
106-
let min_ver = $env.MIN_CLANG_TOOLS_VERSION | into int
102+
let version_info = (
103+
(^gh release download -R cpp-linter/clang-tools-static-binaries --pattern versions.json --output -)
104+
| from json
105+
)
106+
mut max_ver = 0
107+
mut min_ver = 99
108+
for ver in ($version_info.llvm_versions | columns) {
109+
let ver = $ver | into int
110+
if ($ver < $min_ver) {
111+
$min_ver = $ver
112+
}
113+
if ($ver > $max_ver) {
114+
$max_ver = $ver
115+
}
116+
}
107117
for $ver in ($min_ver..$max_ver) {
108118
print $"::group::Testing with clang v($ver)"
109119
with-env { CLANG_VERSION: $"($ver)" } {

Cargo.lock

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clang-installer/CHANGELOG.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77
<!-- markdownlint-disable MD024 -->
88

9-
## [clang-installer/v0.1.2] - 2026-06-05
9+
## [clang-downloader/v0.1.2] - 2026-06-05
1010

1111
### <!-- 4 --> 🛠️ Fixed
1212

1313
- Restore cargo binstall support by @2bndy5 in [#328](https://github.com/cpp-linter/cpp-linter-rs/pull/328)
1414

15-
[clang-installer/v0.1.2]: https://github.com/cpp-linter/cpp-linter-rs/compare/clang-installer/v0.1.1...clang-installer/v0.1.2
15+
[clang-downloader/v0.1.2]: https://github.com/cpp-linter/cpp-linter-rs/compare/clang-downloader/v0.1.1...clang-downloader/v0.1.2
1616

17-
Full commit diff: [`clang-installer/v0.1.1...clang-installer/v0.1.2`][clang-installer/v0.1.2]
17+
Full commit diff: [`clang-downloader/v0.1.1...clang-downloader/v0.1.2`][clang-downloader/v0.1.2]
1818

19-
## [clang-installer/v0.1.1] - 2026-06-04
19+
## [clang-downloader/v0.1.1] - 2026-06-04
2020

2121
### <!-- 1 --> 🚀 Added
2222

@@ -26,14 +26,14 @@ Full commit diff: [`clang-installer/v0.1.1...clang-installer/v0.1.2`][clang-inst
2626
### <!-- 6 --> 📦 Dependency updates
2727

2828
- Bump the cargo group across 1 directory with 8 updates by @dependabot[bot] in [#301](https://github.com/cpp-linter/cpp-linter-rs/pull/301)
29-
- Bump version to clang-installer/v0.1.1 by @2bndy5 in [`24ed0a4`](https://github.com/cpp-linter/cpp-linter-rs/commit/24ed0a4556bf5169b8da5c06eef29f5694caa2cd)
29+
- Bump version to clang-downloader/v0.1.1 by @2bndy5 in [`24ed0a4`](https://github.com/cpp-linter/cpp-linter-rs/commit/24ed0a4556bf5169b8da5c06eef29f5694caa2cd)
3030

3131
### <!-- 9 --> 🗨️ Changed
3232

3333
- Prepare to release individual packages by @2bndy5 in [#302](https://github.com/cpp-linter/cpp-linter-rs/pull/302)
3434

35-
[clang-installer/v0.1.1]: https://github.com/cpp-linter/cpp-linter-rs/compare/2e25fec0a447df24d0bcc1b80f6624040bab755e...clang-installer/v0.1.1
35+
[clang-downloader/v0.1.1]: https://github.com/cpp-linter/cpp-linter-rs/compare/2e25fec0a447df24d0bcc1b80f6624040bab755e...clang-downloader/v0.1.1
3636

37-
Full commit diff: [`2e25fec...clang-installer/v0.1.1`][clang-installer/v0.1.1]
37+
Full commit diff: [`2e25fec...clang-downloader/v0.1.1`][clang-downloader/v0.1.1]
3838

3939
<!-- generated by git-cliff -->

clang-installer/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,10 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
4747
[features]
4848
bin = ["dep:clap", "dep:tokio", "dep:anyhow", "dep:colored"]
4949

50+
[build-dependencies]
51+
serde = { workspace = true }
52+
serde_json = { workspace = true }
53+
ureq = { version = "3.3.0", default-features = false, features = ["rustls"] }
54+
5055
[package.metadata.binstall]
5156
pkg-url = "{ repo }/releases/download/clang-installer/v{ version }/{ name }-{ target }{ archive-suffix }"

clang-installer/build.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const URL: &str = "https://github.com/cpp-linter/clang-tools-static-binaries/releases/latest/download/versions.json";
2+
3+
#[derive(Debug, serde::Deserialize)]
4+
struct VersionInfo {
5+
release_tag: String,
6+
llvm_versions: std::collections::HashMap<u8, String>,
7+
}
8+
9+
fn main() {
10+
let mut response = ureq::get(URL)
11+
.call()
12+
.unwrap();
13+
let body = response.body_mut();
14+
let body_str = body
15+
.read_to_string()
16+
.unwrap();
17+
let version_info: VersionInfo = serde_json::from_str(&body_str).unwrap();
18+
let (min_ver, max_ver) = {
19+
let (mut min_v, mut max_v) = (None, None);
20+
for ver in version_info.llvm_versions.keys() {
21+
if min_v.is_none_or(|v| v > ver) {
22+
min_v = Some(ver);
23+
}
24+
if max_v.is_none_or(|v| v < ver) {
25+
max_v = Some(ver);
26+
}
27+
}
28+
(min_v.unwrap(), max_v.unwrap())
29+
};
30+
println!("cargo:rustc-env=CLANG_TOOLS_TAG={}", version_info.release_tag);
31+
println!("cargo:rustc-env=MIN_CLANG_TOOLS_VERSION={min_ver}");
32+
println!("cargo:rustc-env=MAX_CLANG_TOOLS_VERSION={max_ver}");
33+
}

clang-installer/src/downloader/static_dist.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ pub enum StaticDistDownloadError {
4343
#[error("Failed to parse the SHA512 sum file")]
4444
Sha512Corruption,
4545
}
46-
const MIN_CLANG_TOOLS_VERSION: u8 = 11;
47-
pub(crate) const MAX_CLANG_TOOLS_VERSION: u8 = 22;
46+
const MIN_CLANG_TOOLS_VERSION: &str = env!("MIN_CLANG_TOOLS_VERSION");
47+
pub(crate) const MAX_CLANG_TOOLS_VERSION: &str = env!("MAX_CLANG_TOOLS_VERSION");
4848
const CLANG_TOOLS_REPO: &str = "https://github.com/cpp-linter/clang-tools-static-binaries";
49-
const CLANG_TOOLS_TAG: &str = "master-6e612956";
49+
const CLANG_TOOLS_TAG: &str = env!("CLANG_TOOLS_TAG");
5050

5151
/// A downloader that uses statically linked binary distribution files
5252
/// provided by the cpp-linter team.
@@ -56,25 +56,8 @@ impl Cacher for StaticDistDownloader {}
5656

5757
impl StaticDistDownloader {
5858
pub fn get_major_version_range() -> RangeInclusive<u8> {
59-
let min_clang_tools_version: u8 = option_env!("MIN_CLANG_TOOLS_VERSION")
60-
.and_then(|v| match v.parse::<u8>() {
61-
Ok(parsed) => Some(parsed),
62-
Err(e) => {
63-
log::error!("Invalid MIN_CLANG_TOOLS_VERSION env var value: {v}. Error: {e}");
64-
None
65-
}
66-
})
67-
.unwrap_or(MIN_CLANG_TOOLS_VERSION);
68-
let max_clang_tools_version: u8 = option_env!("MAX_CLANG_TOOLS_VERSION")
69-
.and_then(|v| match v.parse::<u8>() {
70-
Ok(parsed) => Some(parsed),
71-
Err(e) => {
72-
log::error!("Invalid MAX_CLANG_TOOLS_VERSION env var value: {v}. Error: {e}");
73-
None
74-
}
75-
})
76-
.unwrap_or(MAX_CLANG_TOOLS_VERSION);
77-
min_clang_tools_version..=max_clang_tools_version
59+
MIN_CLANG_TOOLS_VERSION.parse().unwrap_or(11)
60+
..=MAX_CLANG_TOOLS_VERSION.parse().unwrap_or(22)
7861
}
7962

8063
/// Finds a suitable version from `req_ver` within the range of available clang tools versions.
@@ -83,6 +66,7 @@ impl StaticDistDownloader {
8366
/// `MAX_CLANG_TOOLS_VERSION` environment variables (inclusive) at compile time.
8467
fn find_suitable_version(req_ver: &VersionReq) -> Option<Version> {
8568
let clang_tools_versions: RangeInclusive<u8> = Self::get_major_version_range();
69+
println!("Available clang tools versions: {clang_tools_versions:?}");
8670
let outlier = Version::new(12, 0, 1);
8771
for ver in clang_tools_versions
8872
.map(|v| Version::new(v as u64, 0, 0))

cspell.config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ words:
100100
- rustc
101101
- rustdoc
102102
- rustflags
103+
- rustls
103104
- rustup
104105
- sccache
105106
- sdist
@@ -117,6 +118,7 @@ words:
117118
- thiserror
118119
- twemoji
119120
- upport
121+
- ureq
120122
- vararg
121123
- vcpkg
122124
- venv

0 commit comments

Comments
 (0)