Skip to content

Commit e82885a

Browse files
authored
feat: set clang version min and max at compile time (#333)
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 any CI job that builds the new build script that employs gh-cli instead of directly downloading the version info on every build in CI. Re-tuned platform support for static binaries. Linux and MacOS have builds for amd64 and arm64, while windows currently only has x86_64 builds. Fixes a bug where PyPI wheels were ignored if the version was not a strict semantic spec. The new approach weights a fourth component (consecutive build number of same clang version) so that can outrank earlier builds of the same clang version. Added `--verbose` flag to installer CLI to enable debug level log output.
1 parent 701217d commit e82885a

17 files changed

Lines changed: 430 additions & 176 deletions

.github/workflows/benchmark.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,26 @@ concurrency:
2525
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
2626

2727
jobs:
28+
seed-build-script:
29+
runs-on: ubuntu-latest
30+
name: Pre-seed static binaries' versions
31+
steps:
32+
- env:
33+
GITHUB_TOKEN: ${{ github.token }}
34+
run: >-
35+
gh release download
36+
-R cpp-linter/clang-tools-static-binaries
37+
--pattern versions.json
38+
--output versions.json
39+
- name: Upload versions.json
40+
uses: actions/upload-artifact@v7
41+
with:
42+
name: static-binary-versions
43+
path: versions.json
44+
if-no-files-found: error
45+
2846
build-bin:
47+
needs: [seed-build-script]
2948
name: Build ${{ matrix.name }} binary
3049
runs-on: ubuntu-latest
3150
strategy:
@@ -60,6 +79,12 @@ jobs:
6079
fi
6180
- run: rustup update --no-self-update
6281
if: steps.cache.outputs.cache-hit != 'true' || steps.validate.outputs.cache-valid == 'false'
82+
- name: Restore build script seed
83+
if: steps.cache.outputs.cache-hit != 'true' || steps.validate.outputs.cache-valid == 'false'
84+
uses: actions/download-artifact@v8
85+
with:
86+
name: static-binary-versions
87+
path: clang-installer
6388
- run: cargo build --bin cpp-linter --features bin --release
6489
if: steps.cache.outputs.cache-hit != 'true' || steps.validate.outputs.cache-valid == 'false'
6590
- name: Upload build artifact

.github/workflows/binary-builds.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,26 @@ concurrency:
3434
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
3535

3636
jobs:
37+
seed-build-script:
38+
runs-on: ubuntu-latest
39+
name: Pre-seed static binaries' versions
40+
steps:
41+
- env:
42+
GITHUB_TOKEN: ${{ github.token }}
43+
run: >-
44+
gh release download
45+
-R cpp-linter/clang-tools-static-binaries
46+
--pattern versions.json
47+
--output versions.json
48+
- name: Upload versions.json
49+
uses: actions/upload-artifact@v7
50+
with:
51+
name: static-binary-versions
52+
path: versions.json
53+
if-no-files-found: error
54+
3755
create-assets:
56+
needs: [seed-build-script]
3857
name: ${{ matrix.target }}
3958
strategy:
4059
fail-fast: false
@@ -113,6 +132,12 @@ jobs:
113132
GITHUB_TOKEN: ${{ github.token }}
114133
run: cargo binstall -y cross
115134

135+
- name: Restore build script seed
136+
uses: actions/download-artifact@v8
137+
with:
138+
name: static-binary-versions
139+
path: clang-installer
140+
116141
- name: Build
117142
run: >-
118143
${{ matrix.cross && 'cross' || 'cargo '}}

.github/workflows/build-docs.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,27 @@ jobs:
4444
key: ${{ runner.os }}-docs-cargo-${{ hashFiles('Cargo.lock') }}
4545
- run: cargo fetch
4646

47+
seed-build-script:
48+
runs-on: ubuntu-latest
49+
name: Pre-seed static binaries' versions
50+
steps:
51+
- env:
52+
GITHUB_TOKEN: ${{ github.token }}
53+
run: >-
54+
gh release download
55+
-R cpp-linter/clang-tools-static-binaries
56+
--pattern versions.json
57+
--output versions.json
58+
- name: Upload versions.json
59+
uses: actions/upload-artifact@v7
60+
with:
61+
name: static-binary-versions
62+
path: versions.json
63+
if-no-files-found: error
64+
4765
build-mkdocs:
4866
runs-on: ubuntu-latest
49-
needs: [cache-deps]
67+
needs: [cache-deps, seed-build-script]
5068
steps:
5169
- uses: actions/checkout@v6
5270
with:
@@ -66,6 +84,11 @@ jobs:
6684
run: cargo binstall -y nur
6785
env:
6886
GITHUB_TOKEN: ${{ github.token }}
87+
- name: Restore build script seed
88+
uses: actions/download-artifact@v8
89+
with:
90+
name: static-binary-versions
91+
path: clang-installer
6992
- name: Build docs
7093
run: nur docs --build
7194
- name: Upload docs build as artifact
@@ -76,7 +99,7 @@ jobs:
7699

77100
build-rustdoc:
78101
runs-on: ubuntu-latest
79-
needs: [cache-deps]
102+
needs: [cache-deps, seed-build-script]
80103
steps:
81104
- uses: actions/checkout@v6
82105
with:
@@ -97,6 +120,11 @@ jobs:
97120
run: cargo binstall -y nur
98121
env:
99122
GITHUB_TOKEN: ${{ github.token }}
123+
- name: Restore build script seed
124+
uses: actions/download-artifact@v8
125+
with:
126+
name: static-binary-versions
127+
path: clang-installer
100128
- run: nur docs rs
101129
- name: upload rustdoc build as artifact
102130
uses: actions/upload-artifact@v7

.github/workflows/bump-n-release.nu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ export def bump-version [
168168
run-cmd 'yarn' 'version' ($result | get 'new')
169169
print 'Updated version in bindings/node/package.json'
170170
cd '../..'
171+
print "Regenerating index.js"
172+
run-cmd yarn build:debug
171173
}
172174
$result | get new
173175
}

.github/workflows/node-js-packaging.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,26 @@ concurrency:
3838
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
3939

4040
jobs:
41+
seed-build-script:
42+
runs-on: ubuntu-latest
43+
name: Pre-seed static binaries' versions
44+
steps:
45+
- env:
46+
GITHUB_TOKEN: ${{ github.token }}
47+
run: >-
48+
gh release download
49+
-R cpp-linter/clang-tools-static-binaries
50+
--pattern versions.json
51+
--output versions.json
52+
- name: Upload versions.json
53+
uses: actions/upload-artifact@v7
54+
with:
55+
name: static-binary-versions
56+
path: versions.json
57+
if-no-files-found: error
58+
4159
build:
60+
needs: [seed-build-script]
4261
strategy:
4362
fail-fast: false
4463
matrix:
@@ -121,6 +140,11 @@ jobs:
121140
shell: bash
122141
- name: Install dependencies
123142
run: yarn install
143+
- name: Restore build script seed
144+
uses: actions/download-artifact@v8
145+
with:
146+
name: static-binary-versions
147+
path: clang-installer
124148
- name: Build
125149
run: ${{ matrix.settings.build }}
126150
shell: bash
@@ -133,6 +157,7 @@ jobs:
133157
bindings/node/${{ env.APP_NAME }}.*.wasm
134158
if-no-files-found: error
135159
build-freebsd:
160+
needs: [seed-build-script]
136161
runs-on: ubuntu-latest
137162
name: Build FreeBSD
138163
steps:
@@ -150,6 +175,11 @@ jobs:
150175
memory: 8G
151176
cpu_count: 3
152177
environment_variables: DEBUG RUSTUP_IO_THREADS
178+
- name: Restore build script seed
179+
uses: actions/download-artifact@v8
180+
with:
181+
name: static-binary-versions
182+
path: clang-installer
153183
- name: Build
154184
shell: cpa.sh {0}
155185
run: |-

.github/workflows/python-packaging.yml

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,29 @@ concurrency:
4343
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
4444

4545
jobs:
46+
seed-build-script:
47+
runs-on: ubuntu-latest
48+
name: Pre-seed static binaries' versions
49+
steps:
50+
- env:
51+
GITHUB_TOKEN: ${{ github.token }}
52+
run: >-
53+
gh release download
54+
-R cpp-linter/clang-tools-static-binaries
55+
--pattern versions.json
56+
--output versions.json
57+
- name: Upload versions.json
58+
uses: actions/upload-artifact@v7
59+
with:
60+
name: static-binary-versions
61+
path: versions.json
62+
if-no-files-found: error
63+
4664
linux:
65+
needs: [seed-build-script]
4766
runs-on: ${{ matrix.platform.runner }}
4867
strategy:
68+
fail-fast: false
4969
matrix:
5070
platform:
5171
- runner: ubuntu-latest
@@ -56,54 +76,56 @@ jobs:
5676
target: aarch64
5777
- runner: ubuntu-latest
5878
target: armv7
59-
- runner: ubuntu-latest
60-
target: s390x
61-
- runner: ubuntu-latest
62-
target: ppc64le
79+
# These targets currently fail because the docker containers used for building manylinux wheels
80+
# use a known-bad C compiler version; aws-lc-sys refuses to build with the bad compiler:
81+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189
82+
# - runner: ubuntu-latest
83+
# target: s390x
84+
# - runner: ubuntu-latest
85+
# target: ppc64le
6386
steps:
6487
- uses: actions/checkout@v6
6588
with:
6689
persist-credentials: false
6790
- uses: actions/setup-python@v6
6891
with:
6992
python-version: '3.x'
70-
93+
- name: Restore build script seed
94+
uses: actions/download-artifact@v8
95+
with:
96+
name: static-binary-versions
97+
path: clang-installer
7198
- name: Build wheels
7299
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
73100
with:
74101
target: ${{ matrix.platform.target }}
75102
# Use the zig toolchain for all targets except ppc64le.
76103
# Note, this is meant to avoid build errors in aws-lc-sys crate, which compiles C code.
77104
args: >-
78-
--release --out dist --find-interpreter
79-
${{ matrix.platform.target != 'ppc64le' && '--zig' || ''}}
105+
--release --out dist --find-interpreter --zig
80106
# avoid cache-poisoning potential for actually distributed builds
81107
sccache: ${{ startsWith(github.ref, 'refs/tags') && 'false' || 'true' }}
82-
manylinux: auto
83-
# here we either install the ppc64le compiler/toolchain or install zig on all others
84-
before-script-linux: |
85-
case "${{ matrix.platform.target }}" in
86-
ppc64le)
87-
apt-get update
88-
apt-get install -y \
89-
pkg-config \
90-
gcc-powerpc64le-linux-gnu \
91-
g++-powerpc64le-linux-gnu \
92-
binutils-powerpc64le-linux-gnu \
93-
libc6-dev-ppc64el-cross
94-
;;
95-
*)
96-
# spell-checker: disable-next-line
97-
pip install ziglang
98-
;;
99-
esac
108+
manylinux: 'auto'
109+
# before-script-linux: |
110+
# case "${{ matrix.platform.target }}" in
111+
# ppc64le)
112+
# apt-get update
113+
# apt-get install -y \
114+
# pkg-config \
115+
# gcc-powerpc64le-linux-gnu \
116+
# g++-powerpc64le-linux-gnu \
117+
# binutils-powerpc64le-linux-gnu \
118+
# libc6-dev-ppc64el-cross
119+
# ;;
120+
# esac
100121
- name: Upload wheels
101122
uses: actions/upload-artifact@v7
102123
with:
103124
name: wheels-linux-${{ matrix.platform.target }}
104125
path: dist/*
105126

106127
windows:
128+
needs: [seed-build-script]
107129
runs-on: ${{ matrix.platform.runner }}
108130
strategy:
109131
matrix:
@@ -120,6 +142,11 @@ jobs:
120142
with:
121143
python-version: '3.x'
122144
architecture: ${{ matrix.platform.target }}
145+
- name: Restore build script seed
146+
uses: actions/download-artifact@v8
147+
with:
148+
name: static-binary-versions
149+
path: clang-installer
123150
- name: Build wheels
124151
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
125152
with:
@@ -133,6 +160,7 @@ jobs:
133160
path: dist/*
134161

135162
macos:
163+
needs: [seed-build-script]
136164
runs-on: ${{ matrix.platform.runner }}
137165
strategy:
138166
fail-fast: false
@@ -149,6 +177,11 @@ jobs:
149177
- uses: actions/setup-python@v6
150178
with:
151179
python-version: '3.x'
180+
- name: Restore build script seed
181+
uses: actions/download-artifact@v8
182+
with:
183+
name: static-binary-versions
184+
path: clang-installer
152185
- name: Build wheels
153186
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
154187
with:

0 commit comments

Comments
 (0)