Skip to content

Commit

Permalink
feat(ffi): Initial C API for hyper
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jan 8, 2021
1 parent 8861f9a commit 3ae1581
Show file tree
Hide file tree
Showing 22 changed files with 2,910 additions and 14 deletions.
49 changes: 48 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- style
- test
- features
- ffi
- doc
steps:
- run: exit 0
Expand Down Expand Up @@ -111,7 +112,53 @@ jobs:
run: cargo install cargo-hack

- name: check --each-feature
run: cargo hack check --each-feature -Z avoid-dev-deps
run: cargo hack check --each-feature --skip ffi -Z avoid-dev-deps

ffi:
name: Test C API (FFI)
needs: [style]

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Install cbindgen
uses: actions-rs/cargo@v1
with:
command: install
args: cbindgen

- name: Build FFI
uses: actions-rs/cargo@v1
env:
RUSTFLAGS: --cfg hyper_unstable_ffi
with:
command: build
args: --features client,http1,http2,ffi

# TODO: re-enable check once figuring out how to get it working in CI
# - name: Verify cbindgen
# run: ./capi/gen_header.sh --verify

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

- name: Run FFI unit tests
uses: actions-rs/cargo@v1
env:
RUSTFLAGS: --cfg hyper_unstable_ffi
with:
command: test
args: --features full,ffi --lib

doc:
name: Build docs

This comment has been minimized.

Copy link
@aUsABuisnessman

aUsABuisnessman Feb 8, 2023

src/programs/tokenManager/utils.ts

Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target
/Cargo.lock
target
Cargo.lock
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ include = [
#"build.rs",
]

[lib]
crate-type = ["lib", "staticlib", "cdylib"]

[dependencies]
bytes = "1"
futures-core = { version = "0.3", default-features = false }
Expand All @@ -38,6 +41,7 @@ want = "0.3"

# Optional

libc = { version = "0.2", optional = true }
socket2 = { version = "0.3.16", optional = true }

[dev-dependencies]
Expand Down Expand Up @@ -94,7 +98,6 @@ server = []
stream = []

# Tokio support

runtime = [
"tcp",
"tokio/rt",
Expand All @@ -106,6 +109,9 @@ tcp = [
"tokio/time",
]

# C-API support (currently unstable (no semver))
ffi = ["libc"]

# internal features used in CI
nightly = []
__internal_happy_eyeballs_tests = []
Expand Down
17 changes: 17 additions & 0 deletions capi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# C API for hyper

This provides auxiliary pieces for a C API to use the hyper library.

## Unstable

The C API of hyper is currently **unstable**, which means it's not part of the semver contract as the rest of the Rust API is.

Because of that, it's only accessible if `--cfg hyper_unstable_ffi` is passed to `rustc` when compiling. The easiest way to do that is setting the `RUSTFLAGS` environment variable.

## Building

The C API is part of the Rust library, but isn't compiled by default. Using `cargo`, it can be compiled with the following command:

```
RUSTFLAGS="--cfg hyper_unstable_ffi" cargo build --features client,http1,http2,ffi
```
14 changes: 14 additions & 0 deletions capi/cbindgen.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language = "C"
include_guard = "_HYPER_H"
no_includes = true
sys_includes = ["stdint.h", "stddef.h"]
cpp_compat = true
documentation_style = "c"

[parse.expand]
crates = ["hyper-capi"]

[export.rename]
"Exec" = "hyper_executor"
"Io" = "hyper_io"
"Task" = "hyper_task"
22 changes: 22 additions & 0 deletions capi/examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Build the example client
#

TARGET = client

OBJS = client.o

RPATH=$(PWD)/../../target/debug
CFLAGS = -I../include
LDFLAGS = -L$(RPATH) -Wl,-rpath,$(RPATH)
LIBS = -lhyper

$(TARGET): $(OBJS)
$(CC) -o $(TARGET) $(OBJS) $(LDFLAGS) $(LIBS)

upload: upload.o
$(CC) -o upload upload.o $(LDFLAGS) $(LIBS)

clean:
rm -f $(OBJS) $(TARGET)
rm -f upload upload.o
Loading

0 comments on commit 3ae1581

Please sign in to comment.