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 20, 2024
1 parent 3b7375a commit 9a11cf3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
26 changes: 26 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,31 @@ 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 with cargo-c
env:
RUSTFLAGS: --cfg hyper_unstable_ffi
run: cargo cbuild --features client,http1,http2,ffi

doc:
name: Build docs
needs: [style, test]
Expand Down
8 changes: 8 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,13 @@ rustdoc-args = ["--cfg", "hyper_unstable_ffi", "--cfg", "hyper_unstable_tracing"
[package.metadata.playground]
features = ["full"]

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

[package.metadata.capi.install.include]
asset = [{ from="capi/include/hyper.h" }]

[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 9a11cf3

Please sign in to comment.