This GitHub Action generates C bindings with cbindgen for a Rust project.
Input | Required | Default | Description |
---|---|---|---|
rust-project-path |
No | . |
Path to the Rust project |
config-file |
Yes | cbindgen.toml |
Configuration file for cbindgen |
output-header-file |
Yes | bindings_c.h |
Path to the output header file generated by cbindgen |
upload-artifact |
No | true |
Whether to upload the generated header file as an artifact |
github-token |
No | A GitHub token for pushing to the repo. Example: ${{ secrets.GITHUB_TOKEN }} |
|
commit-updated-bindings |
No | false |
Whether to commit the updated bindings |
use-cache |
No | true |
Whether to use Rust caching. |
artifact-prefix |
No | C-Bindings- |
Prefix for the uploaded artifact (header) name |
steps:
- uses: actions/checkout@v4
- uses: Reloaded-Project/cbindgen-action@v1
with:
rust-project-path: '.'
config-file: 'cbindgen.toml'
output-header-file: 'bindings_c.h'
upload-artifact: 'true'
github-token: ${{ secrets.GITHUB_TOKEN }}
commit-updated-bindings: 'true'
use-cache: 'true'
artifact-prefix: 'C-Bindings-'
By default, this action uses Rust caching to speed up builds. However, you should disable caching on subsequent calls if you're running this action multiple times in the same workflow.
This is because the cache will make a copy of everything after all the steps finish,
so a single cache will contain everything you need from all runs.
steps:
- uses: actions/checkout@v4
# First call - use cache to speed up initial build
- name: Generate bindings for release
uses: Reloaded-Project/cbindgen-action@v1
with:
rust-project-path: '.'
config-file: 'cbindgen.toml'
output-header-file: 'bindings_release.h'
use-cache: 'true' # Use cache for first call
# Second call - disable cache as it's not necessary
- name: Generate bindings for debug
uses: Reloaded-Project/cbindgen-action@v1
with:
rust-project-path: '.'
config-file: 'cbindgen_debug.toml'
output-header-file: 'bindings_debug.h'
use-cache: 'false' # Disable cache for second call
If the upload-artifact
input is set to true
, the generated header file will be uploaded as
an artifact with the following name format:
<artifact-prefix><output-header-file>
For example, if the artifact-prefix
input is set to C-Bindings-
(default) and the
output-header-file
input is set to bindings_c.h
, the artifact name will be
C-Bindings-bindings_c.h
.
You can customize the prefix by setting the artifact-prefix
input:
- uses: Reloaded-Project/cbindgen-action@v1
with:
artifact-prefix: 'MyProject-Headers-'
output-header-file: 'bindings.h'
# This will create an artifact named: MyProject-Headers-bindings.h
If you are not uploading an artifact, the generated header can be found at
${{ inputs.rust-project-path }}/${{ inputs.output-header-file }}
.
This is part of the release pipeline for Reloaded3 libraries and components.
To make things more maintainable, and better for everyone, the code has been wrapped into an efficient GitHub Action.
This project is licensed under the MIT License. See the LICENSE file for details.