Skip to content

Commit 7f4a682

Browse files
authored
feat(ffi): add cargo-c support (#3787)
Closes #3786
1 parent 3b7375a commit 7f4a682

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

.github/workflows/CI.yml

+26
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- features
2424
- ffi
2525
- ffi-header
26+
- ffi-cargo-c
2627
- doc
2728
- check-external-types
2829
- udeps
@@ -226,6 +227,31 @@ jobs:
226227
- name: Ensure that hyper.h is up to date
227228
run: ./capi/gen_header.sh --verify
228229

230+
ffi-cargo-c:
231+
name: Test cargo-c support (FFI)
232+
needs: [style]
233+
runs-on: ubuntu-latest
234+
steps:
235+
- name: Checkout
236+
uses: actions/checkout@v4
237+
238+
- name: Install Rust
239+
uses: dtolnay/rust-toolchain@stable
240+
241+
- uses: Swatinem/rust-cache@v2
242+
243+
- name: Install cargo-c
244+
env:
245+
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
246+
CARGO_C_FILE: cargo-c-x86_64-unknown-linux-musl.tar.gz
247+
run: |
248+
curl -L $LINK/$CARGO_C_FILE | tar xz -C ~/.cargo/bin
249+
250+
- name: Build with cargo-c
251+
env:
252+
RUSTFLAGS: --cfg hyper_unstable_ffi
253+
run: cargo cbuild --features client,http1,http2,ffi
254+
229255
doc:
230256
name: Build docs
231257
needs: [style, test]

Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ server = ["dep:httpdate", "dep:pin-project-lite", "dep:smallvec"]
8585

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

8990
# Utilize tracing (currently unstable)
9091
tracing = ["dep:tracing"]
@@ -106,6 +107,13 @@ rustdoc-args = ["--cfg", "hyper_unstable_ffi", "--cfg", "hyper_unstable_tracing"
106107
[package.metadata.playground]
107108
features = ["full"]
108109

110+
[package.metadata.capi.header]
111+
generation = false
112+
subdirectory = false
113+
114+
[package.metadata.capi.install.include]
115+
asset = [{ from="capi/include/hyper.h" }]
116+
109117
[profile.release]
110118
codegen-units = 1
111119
incremental = false

capi/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ The C API is part of the Rust library, but isn't compiled by default. Using `car
1515
```
1616
RUSTFLAGS="--cfg hyper_unstable_ffi" cargo rustc --features client,http1,http2,ffi --crate-type cdylib
1717
```
18+
19+
### (Optional) With `cargo-c`
20+
21+
If using `cargo-c`, you can build and install a shared library with the following command:
22+
23+
```
24+
RUSTFLAGS="--cfg hyper_unstable_ffi" cargo cbuild --features client,http1,http2,ffi --release
25+
```

0 commit comments

Comments
 (0)