Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ffi): add cargo-c support #3787

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably would be nice to add here the required features client,http1,http2,ffi

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, the reason I haven't added them there automatically is because it's possible to choose to only enable http1 or http2, and there's a separate PR here as some people are working on the server portion of the C API.


# 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
```