Skip to content

Commit

Permalink
Merge pull request #238 from biscuit-auth/geal/merge-main-in-v5
Browse files Browse the repository at this point in the history
merge the CAPI changes in V5
  • Loading branch information
Geal authored Nov 19, 2024
2 parents ce61191 + ed7cb5b commit 796ba5d
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 358 deletions.
115 changes: 77 additions & 38 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
tags:
- '*'
- "*"

permissions:
contents: write
Expand All @@ -12,43 +12,82 @@ env:
CARGO_TERM_COLOR: always

jobs:

build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-13
target_arch: x86_64-apple-darwin
arch: x86_64-macos
- os: macos-latest
target_arch: aarch64-apple-darwin
arch: arm64-macos
- os: ubuntu-latest
target_arch: x86_64-unknown-linux-gnu
arch: x86_64-linux
- os: ubuntu-latest
target_arch: x86_64-unknown-linux-musl
arch: x86_64-linux-musl
use_musl: true

steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Cache
uses: actions/cache@v2
with:
path: |
~/.cargo
target/
key: ${{ runner.os }}-cargoc-${{ hashFiles('Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargoc-${{ hashFiles('Cargo.toml') }}
${{ runner.os }}-cargoc-
${{ runner.os }}-${{ hashFiles('Cargo.toml') }}
${{ runner.os }}-
- name: Install cargo-c
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-c
- name: Run cargo-c tests
uses: actions-rs/cargo@v1
with:
command: ctest
args: --release
- name: Build
uses: actions-rs/cargo@v1
with:
command: cinstall
args: --release --prefix=/usr --destdir=./build
- name: Compress
run: tar cvzf biscuit_c-${{github.ref_name}}-x86_64.tar.gz -C build/ .
- name: Release
uses: softprops/action-gh-release@v1
with:
files: biscuit_c-${{github.ref_name}}-x86_64.tar.gz
- name: Checkout sources
uses: actions/checkout@v4
- name: Install musl tools
if: matrix.use_musl
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ matrix.target_arch }}
- name: Install cargo-c (macOS)
if: startsWith(matrix.os, 'macos')
env:
LINK: https://github.com/lu-zero/cargo-c/releases/download
CARGO_C_FILE: cargo-c-macos.zip
CARGO_C_VERSION: v0.10.5
run: |
curl -L $LINK/$CARGO_C_VERSION/$CARGO_C_FILE -o cargo-c-macos.zip
unzip cargo-c-macos.zip -d ~/.cargo/bin
- name: Install cargo-c (Linux)
if: matrix.os == 'ubuntu-latest'
env:
LINK: https://github.com/lu-zero/cargo-c/releases/download
CARGO_C_FILE: cargo-c-x86_64-unknown-linux-musl.tar.gz
CARGO_C_VERSION: v0.10.5
run: |
curl -L $LINK/$CARGO_C_VERSION/$CARGO_C_FILE | tar xz -C ~/.cargo/bin
- name: Run cargo-c tests
run: cargo ctest --release --features="capi"
if: matrix.os == 'ubuntu-latest' && matrix.target_arch == 'x86_64-unknown-linux-gnu'

- name: Build C-API (Linux)
if: matrix.os == 'ubuntu-latest' && !matrix.use_musl
run: cargo cinstall --release --target ${{ matrix.target_arch }} --prefix=/usr --destdir=./build --features="capi"
- name: Build C-API (musl)
if: matrix.use_musl
run: |
cargo cinstall --target ${{ matrix.target_arch }} --release --prefix=/usr --destdir=./build --features="capi"
- name: Build C-API (macOS)
if: startsWith(matrix.os, 'macos')
run: |
cargo cinstall --target ${{ matrix.target_arch }} --release --prefix=/usr --destdir=./build --features="capi"
- name: Compress
run: tar cvzf biscuit-auth-${{github.ref_name}}-${{matrix.arch}}.tar.gz -C build/ .

- name: Generate checksum
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
sha256sum "biscuit-auth-${{github.ref_name}}-${{matrix.arch}}.tar.gz" > "biscuit-auth-${{github.ref_name}}-${{matrix.arch}}.tar.gz.sha256"
else
shasum -a 256 "biscuit-auth-${{github.ref_name}}-${{matrix.arch}}.tar.gz" > "biscuit-auth-${{github.ref_name}}-${{matrix.arch}}.tar.gz.sha256"
fi
- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
biscuit-auth-${{github.ref_name}}-${{matrix.arch}}.tar.gz
biscuit-auth-${{github.ref_name}}-${{matrix.arch}}.tar.gz.sha256
84 changes: 35 additions & 49 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,55 @@ name: Rust

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main, v5 ]
branches: [main, v5]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Cache
uses: actions/cache@v2
with:
path: |
~/.cargo
target/
key: ${{ runner.os }}-${{ hashFiles('Cargo.toml') }}
restore-keys: |
${{ runner.os }}-${{ hashFiles('Cargo.toml') }}
${{ runner.os }}-
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --features="serde-error,bwk" --verbose
- name: Check samples
run: |
cd biscuit-auth
cargo run --release --example testcases --features serde-error -- ./samples --json > ./samples/samples.json
git diff --exit-code
- uses: actions/checkout@v2
- name: Cache
uses: actions/cache@v2
with:
path: |
~/.cargo
target/
key: ${{ runner.os }}-${{ hashFiles('Cargo.toml') }}
restore-keys: |
${{ runner.os }}-${{ hashFiles('Cargo.toml') }}
${{ runner.os }}-
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --features="serde-error,bwk" --verbose
- name: Check samples
run: |
cd biscuit-auth
cargo run --release --example testcases --features serde-error -- ./samples --json > ./samples/samples.json
git diff --exit-code
capi:
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Cache
uses: actions/cache@v2
with:
path: |
~/.cargo
target/
key: ${{ runner.os }}-cargoc-${{ hashFiles('Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargoc-${{ hashFiles('Cargo.toml') }}
${{ runner.os }}-cargoc-
${{ runner.os }}-${{ hashFiles('Cargo.toml') }}
${{ runner.os }}-
- name: Install cargo-c
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-c --version 0.9.14+cargo-0.66
- name: Run cargo-c tests
uses: actions-rs/cargo@v1
with:
command: ctest
args: --release
- name: Checkout sources
uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install cargo-c
env:
LINK: https://github.com/lu-zero/cargo-c/releases/download
CARGO_C_FILE: cargo-c-x86_64-unknown-linux-musl.tar.gz
CARGO_C_VERSION: v0.10.5
run: |
curl -L $LINK/$CARGO_C_VERSION/$CARGO_C_FILE | tar xz -C ~/.cargo/bin
- name: Run cargo-c tests
run: cargo ctest --features="capi" --release

coverage:
name: Coverage
Expand Down Expand Up @@ -94,4 +80,4 @@ jobs:
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: biscuit-auth/biscuit-rust
slug: biscuit-auth/biscuit-rust
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
members = ["biscuit-auth", "biscuit-quote", "biscuit-parser"]
members = ["biscuit-auth", "biscuit-quote", "biscuit-parser", "biscuit-capi"]
14 changes: 1 addition & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,7 @@ biscuit implementations come with a default symbol table to avoid transmitting f

# C bindings

This project can generate C bindings with [cargo-c](https://crates.io/crates/cargo-c).

compile it with:

```
cargo cinstall --prefix=/usr --destdir=./build
```

Run C integration tests with:

```
cargo ctest
```
You can find the C bindings and documentation in the [`biscuit-capi`](./biscuit-capi/README.md) crate.

## License

Expand Down
29 changes: 5 additions & 24 deletions biscuit-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ repository = "https://github.com/biscuit-auth/biscuit-rust"

[features]
default = ["regex-full", "datalog-macro"]
regex-full = [ "regex/perf", "regex/unicode"]
# used by cargo-c to signal the compilation of C bindings
capi = ["inline-c"]
regex-full = ["regex/perf", "regex/unicode"]
wasm = ["wasm-bindgen", "getrandom/wasm-bindgen"]
# used by biscuit-wasm to serialize errors to JSON
serde-error = ["serde", "biscuit-parser/serde-error"]
Expand All @@ -33,12 +31,11 @@ sha2 = "^0.9"
prost = "0.10"
prost-types = "0.10"
regex = { version = "1.5", default-features = false, features = ["std"] }
nom = {version = "7", default-features = false, features = ["std"] }
nom = { version = "7", default-features = false, features = ["std"] }
hex = "0.4"
zeroize = { version = "1", default-features = false }
thiserror = "1"
rand = { version = "0.8" }
inline-c = { version = "0.1", optional = true }
wasm-bindgen = { version = "0.2", optional = true }
base64 = "0.13.0"
ed25519-dalek = { version = "2.0.0", features = ["rand_core", "zeroize"] }
Expand All @@ -48,10 +45,11 @@ time = { version = "0.3.7", features = ["formatting", "parsing"] }
uuid = { version = "1", optional = true }
biscuit-parser = { version = "0.1.2", path = "../biscuit-parser" }
biscuit-quote = { version = "0.2.2", optional = true, path = "../biscuit-quote" }
chrono = { version = "0.4.26", optional = true, default-features = false, features = ["serde"] }
chrono = { version = "0.4.26", optional = true, default-features = false, features = [
"serde",
] }
serde_json = "1.0.117"


[dev-dependencies]
bencher = "0.1.5"
rand = "0.8"
Expand All @@ -65,23 +63,6 @@ codspeed-bencher-compat = "2.6.0"
#[build-dependencies]
#prost-build = "0.10"

[package.metadata.capi.library]
# Used as the library name and defaults to the crate name. This might get
# prefixed with `lib` depending on the target platform.
name = "biscuit_auth"

include = [
"Cargo.toml",
"cbindgen.toml",
"build.rs",
"examples/*.rs",
"LICENSE",
"README.md",
"src/*.rs",
"src/*/*.rs",
"tests/*.rs"
]

[[example]]
name = "testcases"
required-features = ["serde-error"]
Expand Down
1 change: 1 addition & 0 deletions biscuit-auth/src/datalog/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl SymbolTable {
}
}
}

pub fn print_fact(&self, f: &Fact) -> String {
self.print_predicate(&f.predicate)
}
Expand Down
6 changes: 0 additions & 6 deletions biscuit-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,6 @@ pub use token::Biscuit;
pub use token::RootKeyProvider;
pub use token::{ThirdPartyBlock, ThirdPartyRequest};

#[cfg(cargo_c)]
mod capi;

#[cfg(cargo_c)]
pub use capi::*;

#[cfg(feature = "bwk")]
mod bwk;
#[cfg(feature = "bwk")]
Expand Down
30 changes: 30 additions & 0 deletions biscuit-capi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "biscuit-capi"
version = "5.0.0" # Should keep the same version as biscuit-auth
description = "C API for Biscuit"
authors = ["Geoffroy Couprie <contact@geoffroycouprie.com>"]
edition = "2018"
license = "Apache-2.0"
documentation = "https://docs.rs/biscuit-auth"
homepage = "https://github.com/biscuit-auth/biscuit"
repository = "https://github.com/biscuit-auth/biscuit-rust"

[dependencies]
biscuit-auth = { version = "5.0.0", path = "../biscuit-auth", features = [
"datalog-macro",
"serde-error",
] }
inline-c = { version = "0.1", optional = true }
rand = "0.8"

[features]
default = []
capi = ["inline-c"]

[package.metadata.capi.library]
# Used as the library name and defaults to the crate name. This might get
# prefixed with `lib` depending on the target platform.
name = "biscuit_auth"

[package.metadata.capi.header]
name = "biscuit_auth"
Loading

0 comments on commit 796ba5d

Please sign in to comment.