Skip to content

Commit

Permalink
feat(ffi): add cargo-c support
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Nov 19, 2024
1 parent 3b7375a commit 58fe327
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- features
- ffi
- ffi-header
- ffi-cargo-c
- doc
- check-external-types
- udeps
Expand Down Expand Up @@ -226,6 +227,38 @@ jobs:
- name: Ensure that hyper.h is up to date
run: ./capi/gen_header.sh --verify

ffi-cargo-c:
name: Test cargo-c support (FFI)
needs: [style]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2

- name: Install cargo-c
env:
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
CARGO_C_FILE: cargo-c-x86_64-unknown-linux-musl.tar.gz
run: |
curl -L $LINK/$CARGO_C_FILE | tar xz -C ~/.cargo/bin
- name: Build and test with cargo-c
env:
RUSTFLAGS: --cfg hyper_unstable_ffi
run: cargo ctest --features client,http1,http2,ffi

- name: Build FFI
env:
RUSTFLAGS: --cfg hyper_unstable_ffi
run: cargo rustc --features client,http1,http2,ffi --crate-type cdylib

- name: Make Examples
run: cd capi/examples && make client

doc:
name: Build docs
needs: [style, test]
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ server = ["dep:httpdate", "dep:pin-project-lite", "dep:smallvec"]

# C-API support (currently unstable (no semver))
ffi = ["dep:http-body-util", "futures-util?/alloc"]
capi = []

# Utilize tracing (currently unstable)
tracing = ["dep:tracing"]
Expand All @@ -106,6 +107,9 @@ rustdoc-args = ["--cfg", "hyper_unstable_ffi", "--cfg", "hyper_unstable_tracing"
[package.metadata.playground]
features = ["full"]

[package.metadata.capi.header]
generation = false

[profile.release]
codegen-units = 1
incremental = false
Expand Down
8 changes: 8 additions & 0 deletions capi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ The C API is part of the Rust library, but isn't compiled by default. Using `car
```
RUSTFLAGS="--cfg hyper_unstable_ffi" cargo rustc --features client,http1,http2,ffi --crate-type cdylib
```

### (Optional) With `cargo-c`

If using `cargo-c`, you can build and install a shared library with the following command:

```
RUSTFLAGS="--cfg hyper_unstable_ffi" cargo cbuild --features client,http1,http2,ffi --release
```

0 comments on commit 58fe327

Please sign in to comment.