diff --git a/cbindgen.yaml b/cbindgen.yaml new file mode 100644 index 00000000000..f552d919332 --- /dev/null +++ b/cbindgen.yaml @@ -0,0 +1,50 @@ +package: + name: cbindgen + version: 0.26.0 + epoch: 0 + description: Tool to generate C bindings from Rust code + copyright: + - license: MPL-2.0 + +environment: + contents: + packages: + - build-base + - busybox + - rust + +pipeline: + - uses: git-checkout + with: + repository: https://github.com/mozilla/cbindgen + tag: v${{package.version}} + expected-commit: 703b53c06f9fe2dbc0193d67626558cfa84a0f62 + + - runs: | + cargo build --release + mkdir -p ${{targets.destdir}}/usr/bin + cp target/release/cbindgen ${{targets.destdir}}/usr/bin/ + +test: + environment: + contents: + packages: + - wolfi-base + - rustup + pipeline: + - runs: | + # We need to install nightly rust because cbindgen uses a nightly + # feature (-Zunpretty=expanded). + rustup install nightly + ARCH=$(uname -m) + export PATH="$HOME/.rustup/toolchains/nightly-${ARCH}-unknown-linux-gnu/bin:$PATH" + cbindgen --version + cbindgen --help + cbindgen --config cbindgen.toml --crate bitfield --output my_header.h --lang c + cat my_header.h + +update: + enabled: true + github: + identifier: mozilla/cbindgen + strip-prefix: v diff --git a/cbindgen/Cargo.lock b/cbindgen/Cargo.lock new file mode 100644 index 00000000000..6594121cec4 --- /dev/null +++ b/cbindgen/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "bitfield" +version = "0.1.0" diff --git a/cbindgen/Cargo.toml b/cbindgen/Cargo.toml new file mode 100644 index 00000000000..18a11a1f1c2 --- /dev/null +++ b/cbindgen/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bitfield" +version = "0.1.0" +authors = ["cbindgen"] + +[features] +cbindgen = [] diff --git a/cbindgen/cbindgen.toml b/cbindgen/cbindgen.toml new file mode 100644 index 00000000000..27c92c865d4 --- /dev/null +++ b/cbindgen/cbindgen.toml @@ -0,0 +1,3 @@ +[parse.expand] +crates = ["bitfield"] +features = ["cbindgen"] diff --git a/cbindgen/src/lib.rs b/cbindgen/src/lib.rs new file mode 100644 index 00000000000..23692134cdf --- /dev/null +++ b/cbindgen/src/lib.rs @@ -0,0 +1,15 @@ +#[repr(C)] +pub struct HasBitfields { + #[cfg(not(feature = "cbindgen"))] + foo_and_bar: u64, + + #[cfg(feature = "cbindgen")] + /// cbindgen:bitfield=8 + foo: u64, + #[cfg(feature = "cbindgen")] + /// cbindgen:bitfield=56 + bar: u64, +} + +#[no_mangle] +pub extern "C" fn root(_: &HasBitfields) {}