Skip to content

Commit 6618512

Browse files
authored
Regenerate header bindings for the current target instead of reusing incompatible x64 Windows bindings (#32)
This change removes the pregenerated bindings and instead always generates the bindings at compile time. This results in less work needed to support all targets from cpuinfo. With bindings being generated at compile time, the cross compilation CI tests now also validate the bindings. Before it would always test against the windows bindings which would "succeed" even though its ABI compared against the compiled cpuinfo static library was incorrect. To simplify this CI flow, I've decided to move the cross compilation checks into the general ci.yaml workflow. I've also patched up our higher level rust code (lib.rs) to incorporate platform and target specific fields in cpuinfo.h. As a result, this crate now properly supports all targets from cpuinfo.
1 parent a9cfae2 commit 6618512

File tree

9 files changed

+187
-963
lines changed

9 files changed

+187
-963
lines changed

.github/workflows/ci.yml

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
name: CI
2+
13
on:
24
push:
3-
pull_request:
45

56
jobs:
67
rust:
@@ -14,8 +15,6 @@ jobs:
1415
run: cargo fmt --all -- --check
1516
- name: Cargo clippy
1617
run: cargo clippy --workspace --all-targets -- -D warnings
17-
- name: Cargo test
18-
run: cargo test --workspace
1918

2019
rust-msrv:
2120
name: Build-test MSRV (1.74) with minimal crate dependencies
@@ -30,6 +29,90 @@ jobs:
3029
- uses: dtolnay/rust-toolchain@nightly
3130
- name: Generate minimal-version dependencies
3231
run: cargo -Zminimal-versions generate-lockfile
32+
# The latest bindgen release has an underspecified proc-macro2 dependency: https://github.com/rust-lang/rust-bindgen/issues/3149
33+
- name: Update proc-macro2 to 1.0.80
34+
run: cargo update -p proc-macro2 --precise 1.0.80
3335
- uses: dtolnay/[email protected]
3436
- name: Cargo check
3537
run: cargo check --workspace --all-targets
38+
39+
cross:
40+
name: ${{ matrix.name }} (${{ matrix.target }})
41+
runs-on: ${{ matrix.os }}
42+
env:
43+
PROGRAM: ${{ matrix.cross && 'cross' || 'cargo' }}
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
include:
48+
- target: x86_64-unknown-linux-gnu
49+
os: ubuntu-latest
50+
name: Linux
51+
cross: false
52+
test: true
53+
54+
- target: x86_64-apple-darwin
55+
os: macos-latest
56+
name: macOS
57+
cross: false
58+
test: true
59+
60+
- os: windows-latest
61+
name: Windows
62+
target: x86_64-pc-windows-msvc
63+
cross: false
64+
test: true
65+
66+
# - os: ubuntu-latest
67+
# name: FreeBSD
68+
# target: x86_64-unknown-freebsd
69+
# cross: true
70+
# test: false
71+
72+
- target: aarch64-linux-android
73+
os: ubuntu-latest
74+
name: Android
75+
cross: true
76+
test: true
77+
78+
# - os: ubuntu-latest
79+
# name: OpenWrt
80+
# target: aarch64-unknown-linux-gnu
81+
# cross: true
82+
# test: true
83+
# cargo_args: --features "openwrt"
84+
85+
# - target: armv7-unknown-linux-gnueabihf
86+
# os: ubuntu-latest
87+
# name: Linux ARMv7
88+
# cross: true
89+
# test: true
90+
91+
steps:
92+
- name: Checkout
93+
uses: actions/checkout@v4
94+
with:
95+
submodules: true
96+
97+
- name: Bootstrap
98+
uses: dtolnay/rust-toolchain@stable
99+
with:
100+
targets: ${{ matrix.target }}
101+
102+
- name: Install cross
103+
run: cargo install cross
104+
if: ${{ matrix.cross }}
105+
106+
- name: Build
107+
run: ${{ env.PROGRAM }} build --target=${{ matrix.target }} ${{ matrix.cargo_args }}
108+
109+
- name: Test
110+
run: ${{ env.PROGRAM }} test --target=${{ matrix.target }} ${{ matrix.cargo_args }}
111+
if: ${{ matrix.test }}
112+
113+
- name: Run example
114+
run: cargo run --example info
115+
- uses: actions/upload-artifact@v4
116+
with:
117+
name: info-${{ matrix.target }}
118+
path: info.txt

.github/workflows/cross.yaml

Lines changed: 0 additions & 95 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/target
22
/Cargo.lock
3-
info.txt
3+
/info.txt

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ categories = ["hardware-support"] # https://crates.io/category_slugs
1212
keywords = []
1313
rust-version = "1.74"
1414

15-
[features]
16-
generate_bindings = ["dep:bindgen"]
17-
1815
[dependencies]
1916
bytemuck = "1"
2017
serde = { version = "1", features = ["derive", "rc"] }
@@ -23,5 +20,5 @@ serde = { version = "1", features = ["derive", "rc"] }
2320
serde_json = "1"
2421

2522
[build-dependencies]
26-
bindgen = { version = "0.69", optional = true }
23+
bindgen = "0.71"
2724
cc = "1.1"

0 commit comments

Comments
 (0)