An open API service indexing awesome lists of open source software.

https://github.com/reloaded-project/devops-rust-cbindgen

A GitHub Actions wrapper around running `cbindgen` to generate C/C++ bindings from Rust code.
https://github.com/reloaded-project/devops-rust-cbindgen

Last synced: 3 months ago
JSON representation

A GitHub Actions wrapper around running `cbindgen` to generate C/C++ bindings from Rust code.

Awesome Lists containing this project

README

          



reloaded Logo

Generate bindings with cbindgen



License


This GitHub Action generates C bindings with cbindgen for a Rust project.

## Inputs

| 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 |

## Example Usage

```yaml
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-'
```

## Caching

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.

### Example: Multiple Calls with Cache Control

```yaml
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
```

## Getting Artifacts

If the `upload-artifact` input is set to `true`, the generated header file will be uploaded as
an artifact with the following name format:

```

```

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:

```yaml
- 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 }}`.

## Purpose

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.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.