Skip to content

Commit

Permalink
Change to pre-generated bindings, add feature for generating at compi…
Browse files Browse the repository at this point in the history
…le-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 <[email protected]>
  • Loading branch information
pheki and zetanumbers authored Feb 14, 2024
1 parent 4c737c0 commit e357f6e
Show file tree
Hide file tree
Showing 20 changed files with 21,172 additions and 564 deletions.
101 changes: 52 additions & 49 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
workflow_dispatch:

env:
# If you update LLVM_VERSION, remember to also update `update-bindings.yml`
# and `README.md`
LLVM_VERSION: "16"

jobs:
Expand All @@ -31,8 +33,6 @@ jobs:
sha: ${{ github.sha }}

- uses: actions/checkout@v3
with:
submodules: true

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

- name: Cache LLVM and Clang
id: cache-llvm
uses: actions/cache@v3
with:
path: |
${{ runner.temp }}/llvm
key: llvm

- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1
with:
version: ${{ env.LLVM_VERSION }}
directory: ${{ runner.temp }}/llvm
cached: ${{ steps.cache-llvm.outputs.cache-hit }}

- name: Cache dependencies
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -134,8 +119,6 @@ jobs:
sha: ${{ github.sha }}

- uses: actions/checkout@v3
with:
submodules: true

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

- name: Cache LLVM and Clang
id: cache-llvm
uses: actions/cache@v3
with:
path: |
${{ runner.temp }}/llvm
key: llvm

- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1
with:
version: ${{ env.LLVM_VERSION }}
directory: ${{ runner.temp }}/llvm
cached: ${{ steps.cache-llvm.outputs.cache-hit }}

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down Expand Up @@ -234,7 +202,6 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: true

- name: Restore vitasdk cache
uses: actions/cache/restore@v3
with:
Expand Down Expand Up @@ -278,26 +245,24 @@ jobs:
context: Check missing libs
sha: ${{ github.sha }}

doc:
name: Doc
# Checks if there's no diff when regenerating bindings
check-bindings:
name: Check bindings
runs-on: ubuntu-latest
needs: install-vitasdk
timeout-minutes: 30
env:
RUSTDOCFLAGS: -D warnings
timeout-minutes: 10
steps:
- name: Set commit status as pending
uses: myrotvorets/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
context: Doc
context: Check bindings
sha: ${{ github.sha }}

- uses: actions/checkout@v3
with:
submodules: true

- name: Restore vitasdk cache
uses: actions/cache/restore@v3
with:
Expand All @@ -320,6 +285,51 @@ jobs:
directory: ${{ runner.temp }}/llvm
cached: ${{ steps.cache-llvm.outputs.cache-hit }}

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Regenerate bindings
env:
VITASDK: /opt/vitasdk
# From clang-sys
LIBCLANG_PATH: ${{ runner.temp }}/llvm/lib
LLVM_CONFIG_PATH: ${{ runner.temp }}/llvm/bin/llvm-config
run: |
cargo run --profile build-util -p vitasdk-sys-build-util -- bindgen
- name: Check diff
run: |
git add . && git diff --quiet && git diff --cached --quiet
- name: Set final commit status
uses: myrotvorets/[email protected]
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
context: Check bindings
sha: ${{ github.sha }}

doc:
name: Doc
runs-on: ubuntu-latest
timeout-minutes: 30
env:
RUSTDOCFLAGS: -D warnings
steps:
- name: Set commit status as pending
uses: myrotvorets/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
context: Doc
sha: ${{ github.sha }}

- uses: actions/checkout@v3

- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
Expand All @@ -330,13 +340,6 @@ jobs:
- name: Run cargo doc
run: DOCS_RS=1 RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --target armv7-sony-vita-newlibeabihf -Z build-std

- name: Upload docs
uses: actions/upload-artifact@v3
with:
name: docs
path: target/armv7-sony-vita-newlibeabihf/doc
if-no-files-found: error

- name: Set final commit status
uses: myrotvorets/[email protected]
if: always()
Expand Down
57 changes: 51 additions & 6 deletions .github/workflows/update-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ on:

env:
PR_BRANCH: update-bindings
# If you update LLVM_VERSION, remember to also update `build.yml` and
# `README.md`
LLVM_VERSION: "16"

jobs:
install-vitasdk:
uses: ./.github/workflows/setup-vitasdk.yml
with:
path: /opt/vitasdk

update:
name: Update
update-and-regenrate:
name: Update and regenerate
runs-on: ubuntu-latest
needs: install-vitasdk
steps:
Expand All @@ -30,21 +33,63 @@ jobs:
key: ${{ runner.os }}-vitasdk
fail-on-cache-miss: true

- name: Cache LLVM and Clang
id: cache-llvm
uses: actions/cache@v3
with:
path: |
${{ runner.temp }}/llvm
key: llvm

- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1
with:
version: ${{ env.LLVM_VERSION }}
directory: ${{ runner.temp }}/llvm
cached: ${{ steps.cache-llvm.outputs.cache-hit }}

- name: Cache build-util dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-build-util-${{ hashFiles('Cargo.lock') }}

- name: Update vita-headers
run: |
echo "VITA_HEADERS_HASH=$(git submodule status | grep vita-headers | cut -d ' ' -f 2)" >> $GITHUB_ENV
git submodule update --recursive --remote vita-headers
echo "VITA_HEADERS_HASH=$(git submodule status | grep vita-headers | cut -d ' ' -f 2)" >> $GITHUB_ENV
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
profile: minimal
override: true

- name: Regenerate bindings
env:
VITASDK: /opt/vitasdk
# From clang-sys
LIBCLANG_PATH: ${{ runner.temp }}/llvm/lib
LLVM_CONFIG_PATH: ${{ runner.temp }}/llvm/bin/llvm-config
run: |
cargo run --profile build-util -p vitasdk-sys-build-util -- bindgen
- name: Commit and create pull request
id: create-pull-request
uses: peter-evans/create-pull-request@v5
with:
title: Update vita-headers
body: Created by the action at [/.workflows/update-bindings.yml](../tree/main/.workflows/update-bindings.yml)
title: Update vita-headers bindings
body: Created by the action at [.github/workflows/update-bindings.yml](../tree/main/.github/workflows/update-bindings.yml)
branch: ${{ env.PR_BRANCH }}
delete-branch: true
commit-message: Update vita-headers to ${{ env.VITA_HEADERS_HASH }}
assignees: pheki
assignees: pheki,ZetaNumbers
committer: Aphek <[email protected]>
author: Aphek <[email protected]>

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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

## [0.3.3] - Unreleased

### Changed

- Bindings are now pre-generated by default, meaning that LLVM / Clang is no longer requried to be installed.
- 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.

## [0.3.2] - 2023-10-06

### Fixed
Expand Down
Loading

0 comments on commit e357f6e

Please sign in to comment.