Skip to content

Commit e357f6e

Browse files
phekizetanumbers
andauthored
Change to pre-generated bindings, add feature for generating at compile-time (#21)
* Change to pre-generated bindings, use feature for compile-time generated * Fix clippy lints * Ignore bindgen feature on docs.rs * Update generate-bindings.yml * Update build.yml * Fix clippy and missing-libs * Update docs * Add rust-toolchain.toml with nightly as the default * Update CHANGELOG.md * Add rustfmt component to update-bindings * Fix workflow file reference * Run bindgen from crate root on update-bindings CI * Add CI job to check bindings * On the CI to update bindings, get the submodule hash after updating * Bind is_build_rs to a variable to make function argument clearer * Rename sort keys to precedence and ident * When formatting fails, warn if running from build.rs, panic otherwise * Use CargoCallbacks instead of our own ParseCallbacks implementation * Gate env_logger under "log-build" feature To reduce dependencies for vitasdk-sys package * Use "build-util" profile for vitasdk-build-util "build-util" is identical to profile used by build.rs * `cargo update` * Watch DOCS_RS environment variable change * Add all-stubs feature Removes need for bindgen during docs.rs build * rename all_stubs field for serde * Revert adding redundant --missing-features check * Group foreign items by feature and refactor * Use doc_auto_cfg instead of doc_cfg * Link on same foreign mods as external definitions and sort by feature * Sort `impl` blocks by rendering the type using quote * Add note to README.md and comments to workflows about LLVM version used --------- Co-authored-by: Daria Sukhonina <dariasukhonina@gmail.com>
1 parent 4c737c0 commit e357f6e

20 files changed

+21172
-564
lines changed

.github/workflows/build.yml

+52-49
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
workflow_dispatch:
99

1010
env:
11+
# If you update LLVM_VERSION, remember to also update `update-bindings.yml`
12+
# and `README.md`
1113
LLVM_VERSION: "16"
1214

1315
jobs:
@@ -31,8 +33,6 @@ jobs:
3133
sha: ${{ github.sha }}
3234

3335
- uses: actions/checkout@v3
34-
with:
35-
submodules: true
3636

3737
- name: Restore vitasdk cache
3838
uses: actions/cache/restore@v3
@@ -41,21 +41,6 @@ jobs:
4141
key: ${{ runner.os }}-vitasdk
4242
fail-on-cache-miss: true
4343

44-
- name: Cache LLVM and Clang
45-
id: cache-llvm
46-
uses: actions/cache@v3
47-
with:
48-
path: |
49-
${{ runner.temp }}/llvm
50-
key: llvm
51-
52-
- name: Install LLVM and Clang
53-
uses: KyleMayes/install-llvm-action@v1
54-
with:
55-
version: ${{ env.LLVM_VERSION }}
56-
directory: ${{ runner.temp }}/llvm
57-
cached: ${{ steps.cache-llvm.outputs.cache-hit }}
58-
5944
- name: Cache dependencies
6045
uses: actions/cache@v3
6146
with:
@@ -134,8 +119,6 @@ jobs:
134119
sha: ${{ github.sha }}
135120

136121
- uses: actions/checkout@v3
137-
with:
138-
submodules: true
139122

140123
- name: Restore vitasdk cache
141124
uses: actions/cache/restore@v3
@@ -144,21 +127,6 @@ jobs:
144127
key: ${{ runner.os }}-vitasdk
145128
fail-on-cache-miss: true
146129

147-
- name: Cache LLVM and Clang
148-
id: cache-llvm
149-
uses: actions/cache@v3
150-
with:
151-
path: |
152-
${{ runner.temp }}/llvm
153-
key: llvm
154-
155-
- name: Install LLVM and Clang
156-
uses: KyleMayes/install-llvm-action@v1
157-
with:
158-
version: ${{ env.LLVM_VERSION }}
159-
directory: ${{ runner.temp }}/llvm
160-
cached: ${{ steps.cache-llvm.outputs.cache-hit }}
161-
162130
- uses: actions-rs/toolchain@v1
163131
with:
164132
toolchain: stable
@@ -234,7 +202,6 @@ jobs:
234202
- uses: actions/checkout@v3
235203
with:
236204
submodules: true
237-
238205
- name: Restore vitasdk cache
239206
uses: actions/cache/restore@v3
240207
with:
@@ -278,26 +245,24 @@ jobs:
278245
context: Check missing libs
279246
sha: ${{ github.sha }}
280247

281-
doc:
282-
name: Doc
248+
# Checks if there's no diff when regenerating bindings
249+
check-bindings:
250+
name: Check bindings
283251
runs-on: ubuntu-latest
284252
needs: install-vitasdk
285-
timeout-minutes: 30
286-
env:
287-
RUSTDOCFLAGS: -D warnings
253+
timeout-minutes: 10
288254
steps:
289255
- name: Set commit status as pending
290256
uses: myrotvorets/set-commit-status-action@v1.1.7
291257
with:
292258
token: ${{ secrets.GITHUB_TOKEN }}
293259
status: pending
294-
context: Doc
260+
context: Check bindings
295261
sha: ${{ github.sha }}
296262

297263
- uses: actions/checkout@v3
298264
with:
299265
submodules: true
300-
301266
- name: Restore vitasdk cache
302267
uses: actions/cache/restore@v3
303268
with:
@@ -320,6 +285,51 @@ jobs:
320285
directory: ${{ runner.temp }}/llvm
321286
cached: ${{ steps.cache-llvm.outputs.cache-hit }}
322287

288+
- uses: actions-rs/toolchain@v1
289+
with:
290+
toolchain: stable
291+
profile: minimal
292+
override: true
293+
294+
- name: Regenerate bindings
295+
env:
296+
VITASDK: /opt/vitasdk
297+
# From clang-sys
298+
LIBCLANG_PATH: ${{ runner.temp }}/llvm/lib
299+
LLVM_CONFIG_PATH: ${{ runner.temp }}/llvm/bin/llvm-config
300+
run: |
301+
cargo run --profile build-util -p vitasdk-sys-build-util -- bindgen
302+
303+
- name: Check diff
304+
run: |
305+
git add . && git diff --quiet && git diff --cached --quiet
306+
307+
- name: Set final commit status
308+
uses: myrotvorets/set-commit-status-action@v1.1.7
309+
if: always()
310+
with:
311+
token: ${{ secrets.GITHUB_TOKEN }}
312+
status: ${{ job.status }}
313+
context: Check bindings
314+
sha: ${{ github.sha }}
315+
316+
doc:
317+
name: Doc
318+
runs-on: ubuntu-latest
319+
timeout-minutes: 30
320+
env:
321+
RUSTDOCFLAGS: -D warnings
322+
steps:
323+
- name: Set commit status as pending
324+
uses: myrotvorets/set-commit-status-action@v1.1.7
325+
with:
326+
token: ${{ secrets.GITHUB_TOKEN }}
327+
status: pending
328+
context: Doc
329+
sha: ${{ github.sha }}
330+
331+
- uses: actions/checkout@v3
332+
323333
- uses: actions-rs/toolchain@v1
324334
with:
325335
toolchain: nightly
@@ -330,13 +340,6 @@ jobs:
330340
- name: Run cargo doc
331341
run: DOCS_RS=1 RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --target armv7-sony-vita-newlibeabihf -Z build-std
332342

333-
- name: Upload docs
334-
uses: actions/upload-artifact@v3
335-
with:
336-
name: docs
337-
path: target/armv7-sony-vita-newlibeabihf/doc
338-
if-no-files-found: error
339-
340343
- name: Set final commit status
341344
uses: myrotvorets/set-commit-status-action@v1.1.7
342345
if: always()

.github/workflows/update-bindings.yml

+51-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ on:
77

88
env:
99
PR_BRANCH: update-bindings
10+
# If you update LLVM_VERSION, remember to also update `build.yml` and
11+
# `README.md`
12+
LLVM_VERSION: "16"
1013

1114
jobs:
1215
install-vitasdk:
1316
uses: ./.github/workflows/setup-vitasdk.yml
1417
with:
1518
path: /opt/vitasdk
1619

17-
update:
18-
name: Update
20+
update-and-regenrate:
21+
name: Update and regenerate
1922
runs-on: ubuntu-latest
2023
needs: install-vitasdk
2124
steps:
@@ -30,21 +33,63 @@ jobs:
3033
key: ${{ runner.os }}-vitasdk
3134
fail-on-cache-miss: true
3235

36+
- name: Cache LLVM and Clang
37+
id: cache-llvm
38+
uses: actions/cache@v3
39+
with:
40+
path: |
41+
${{ runner.temp }}/llvm
42+
key: llvm
43+
44+
- name: Install LLVM and Clang
45+
uses: KyleMayes/install-llvm-action@v1
46+
with:
47+
version: ${{ env.LLVM_VERSION }}
48+
directory: ${{ runner.temp }}/llvm
49+
cached: ${{ steps.cache-llvm.outputs.cache-hit }}
50+
51+
- name: Cache build-util dependencies
52+
uses: actions/cache@v3
53+
with:
54+
path: |
55+
~/.cargo/bin/
56+
~/.cargo/registry/index/
57+
~/.cargo/registry/cache/
58+
~/.cargo/git/db/
59+
target/
60+
key: ${{ runner.os }}-cargo-build-util-${{ hashFiles('Cargo.lock') }}
61+
3362
- name: Update vita-headers
3463
run: |
35-
echo "VITA_HEADERS_HASH=$(git submodule status | grep vita-headers | cut -d ' ' -f 2)" >> $GITHUB_ENV
3664
git submodule update --recursive --remote vita-headers
65+
echo "VITA_HEADERS_HASH=$(git submodule status | grep vita-headers | cut -d ' ' -f 2)" >> $GITHUB_ENV
66+
67+
- uses: actions-rs/toolchain@v1
68+
with:
69+
toolchain: stable
70+
components: rustfmt
71+
profile: minimal
72+
override: true
73+
74+
- name: Regenerate bindings
75+
env:
76+
VITASDK: /opt/vitasdk
77+
# From clang-sys
78+
LIBCLANG_PATH: ${{ runner.temp }}/llvm/lib
79+
LLVM_CONFIG_PATH: ${{ runner.temp }}/llvm/bin/llvm-config
80+
run: |
81+
cargo run --profile build-util -p vitasdk-sys-build-util -- bindgen
3782
3883
- name: Commit and create pull request
3984
id: create-pull-request
4085
uses: peter-evans/create-pull-request@v5
4186
with:
42-
title: Update vita-headers
43-
body: Created by the action at [/.workflows/update-bindings.yml](../tree/main/.workflows/update-bindings.yml)
87+
title: Update vita-headers bindings
88+
body: Created by the action at [.github/workflows/update-bindings.yml](../tree/main/.github/workflows/update-bindings.yml)
4489
branch: ${{ env.PR_BRANCH }}
4590
delete-branch: true
4691
commit-message: Update vita-headers to ${{ env.VITA_HEADERS_HASH }}
47-
assignees: pheki
92+
assignees: pheki,ZetaNumbers
4893
committer: Aphek <bilkow@tutanota.com>
4994
author: Aphek <bilkow@tutanota.com>
5095

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
The format is based on [Common Changelog](https://common-changelog.org/) and [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
44

5+
## [0.3.3] - Unreleased
6+
7+
### Changed
8+
9+
- Bindings are now pre-generated by default, meaning that LLVM / Clang is no longer requried to be installed.
10+
- There's a new `bindgen` feature which makes the crate generate bindings at compile-time by using headers at `$VITASDK` instead of using pre-generated bindings.
11+
512
## [0.3.2] - 2023-10-06
613

714
### Fixed

0 commit comments

Comments
 (0)