-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
232 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: Test CBindgen Workflow | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' # Run daily at midnight | ||
workflow_dispatch: | ||
push: | ||
branches: [ master ] | ||
tags: | ||
- 'v1' | ||
paths: | ||
- 'action.yml' | ||
- '.github/workflows/test-cbindgen-workflow.yml' | ||
pull_request: | ||
branches: [ master ] | ||
paths: | ||
- 'action.yml' | ||
- '.github/workflows/test-cbindgen-workflow.yml' | ||
|
||
jobs: | ||
test-custom-parameters: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Test Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: Sewer56/prs-rs | ||
ref: d08599ed5473616f57d57a0966939e1a5dbda9b4 | ||
- name: Test Custom Parameters | ||
uses: Reloaded-Project/devops-rust-cbindgen@v1 | ||
with: | ||
rust-project-path: '.' | ||
config-file: cbindgen_cpp.toml | ||
output-header-file: bindings_cpp.hpp | ||
upload-artifact: false | ||
- name: Assert Generated Header File | ||
shell: bash | ||
run: | | ||
if [ ! -f bindings_cpp.hpp ]; then | ||
echo "Generated header file does not exist" | ||
exit 1 | ||
fi | ||
test-c-bindings: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Test Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: Sewer56/prs-rs | ||
ref: d08599ed5473616f57d57a0966939e1a5dbda9b4 | ||
- name: Test C Bindings | ||
uses: Reloaded-Project/devops-rust-cbindgen@v1 | ||
with: | ||
config-file: cbindgen_c.toml | ||
output-header-file: bindings_c.h | ||
upload-artifact: false | ||
- name: Assert Generated C Header File | ||
shell: bash | ||
run: | | ||
if [ ! -f bindings_c.h ]; then | ||
echo "Generated C header file does not exist" | ||
exit 1 | ||
fi | ||
test-artifact-creation: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Test Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: Sewer56/prs-rs | ||
ref: d08599ed5473616f57d57a0966939e1a5dbda9b4 | ||
- name: Generate Bindings and Create Artifact | ||
uses: Reloaded-Project/devops-rust-cbindgen@v1 | ||
with: | ||
config-file: cbindgen_c.toml | ||
output-header-file: bindings_c.h | ||
upload-artifact: true | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-updated-bindings: 'false' | ||
- name: Download Artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: C-Bindings-bindings_c.h | ||
path: artifacts | ||
- name: Assert Artifact Contents | ||
shell: bash | ||
run: | | ||
cat artifacts/bindings_c.h | ||
if [ ! -f artifacts/bindings_c.h ]; then | ||
echo "Extracted artifact does not contain the expected header file" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2023 Sewer56 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<div align="center"> | ||
<a href="https://github.com/Reloaded-Project/reloaded-templates-rust" target="_blank"> | ||
<img src="assets/reloaded-logo.png" alt="reloaded Logo" width="100"/> | ||
</a> | ||
|
||
<h1 align="center">Generate bindings with cbindgen</h1> | ||
|
||
<p> | ||
<a href="LICENSE"> | ||
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License"> | ||
</a> | ||
</p> | ||
</div> | ||
|
||
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 | | ||
|
||
## 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' | ||
``` | ||
## 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: | ||
|
||
``` | ||
C-Bindings-<output-header-file> | ||
``` | ||
|
||
For example, if the `output-header-file` input is set to `bindings_c.h`, the artifact name | ||
will be `C-Bindings-bindings_c.h`. | ||
|
||
If you are not uploading an artifact, the generated header can be found at `${{ inputs.rust-project-path }}/${{ inputs.output-header-file }}`. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# .github/actions/cbindgen-action/action.yml | ||
name: 'Generate bindings with cbindgen' | ||
description: 'Generates C bindings with cbindgen for a Rust project' | ||
branding: | ||
icon: 'hash' | ||
color: 'red' | ||
|
||
inputs: | ||
rust-project-path: | ||
description: 'Path to the Rust project' | ||
required: false | ||
default: '.' | ||
config-file: | ||
description: 'Configuration file for cbindgen' | ||
required: true | ||
default: 'cbindgen.toml' | ||
output-header-file: | ||
description: 'Path to the output header file generated by cbindgen' | ||
required: true | ||
default: 'bindings_c.h' | ||
upload-artifact: | ||
description: 'Whether to upload the generated header file as an artifact' | ||
required: false | ||
default: 'true' | ||
github-token: | ||
description: 'A GitHub token for pushing to the repo. Example: `secrets.GITHUB_TOKEN`' | ||
required: true | ||
commit-updated-bindings: | ||
description: 'Whether to commit the updated bindings' | ||
required: false | ||
default: 'false' | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
# Rust preinstalled on runner | ||
- name: Setup Rust Caching | ||
uses: Swatinem/rust-cache@v2 | ||
with: | ||
key: ${{ inputs.target }} | ||
cache-on-failure: true | ||
|
||
# Note: Cached by setup-rust-toolchain | ||
- name: Install cbindgen | ||
shell: bash | ||
working-directory: ${{ inputs.rust-project-path }} | ||
run: cargo install cbindgen | ||
|
||
- name: Generate bindings | ||
shell: bash | ||
working-directory: ${{ inputs.rust-project-path }} | ||
run: cbindgen --config ${{ inputs.config-file }} --output ${{ inputs.output-header-file }} | ||
|
||
- name: Upload header file | ||
if: ${{ inputs.upload-artifact == 'true' }} | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: C-Bindings-${{ inputs.output-header-file }} | ||
path: ${{ inputs.rust-project-path }}/${{ inputs.output-header-file }} | ||
|
||
- name: Commit updated bindings | ||
if: ${{ inputs.commit-updated-bindings == 'true' }} | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github-token }} | ||
with: | ||
commit_message: Update generated C bindings | ||
branch: ${{ github.ref_name }} | ||
commit_user_name: cbindgen-action | ||
commit_user_email: [email protected] | ||
commit_author: cbindgen-action <[email protected]> | ||
file_pattern: ${{ inputs.output-header-file }} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.