diff --git a/Cargo.toml b/Cargo.toml index 954c5c692b..d26479d953 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,6 @@ http-body-util = { version = "0.1", optional = true } httparse = { version = "1.8", optional = true } httpdate = { version = "1.0", optional = true } itoa = { version = "1", optional = true } -libc = { version = "0.2", optional = true } tracing = { version = "0.1", default-features = false, features = ["std"], optional = true } want = { version = "0.3", optional = true } @@ -82,7 +81,7 @@ client = ["dep:want"] server = ["dep:httpdate"] # C-API support (currently unstable (no semver)) -ffi = ["dep:libc", "dep:http-body-util"] +ffi = ["dep:http-body-util"] # Utilize tracing (currently unstable) tracing = ["dep:tracing"] diff --git a/src/ffi/body.rs b/src/ffi/body.rs index dfbcfd7242..a7fe84b9eb 100644 --- a/src/ffi/body.rs +++ b/src/ffi/body.rs @@ -1,14 +1,14 @@ -use std::ffi::c_void; +use std::ffi::{c_int, c_void}; use std::mem::ManuallyDrop; use std::ptr; use std::task::{Context, Poll}; use http_body_util::BodyExt as _; -use libc::{c_int, size_t}; use super::task::{hyper_context, hyper_task, hyper_task_return_type, AsTaskType}; use super::{UserDataPointer, HYPER_ITER_CONTINUE}; use crate::body::{Bytes, Frame, Incoming as IncomingBody}; +use crate::ffi::size_t; /// A streaming HTTP body. /// diff --git a/src/ffi/client.rs b/src/ffi/client.rs index 975314b9be..63b03d874a 100644 --- a/src/ffi/client.rs +++ b/src/ffi/client.rs @@ -1,8 +1,7 @@ +use std::ffi::c_int; use std::ptr; use std::sync::Arc; -use libc::c_int; - use crate::client::conn; use crate::rt::Executor as _; diff --git a/src/ffi/error.rs b/src/ffi/error.rs index b103b2f053..cc289ed7b7 100644 --- a/src/ffi/error.rs +++ b/src/ffi/error.rs @@ -1,4 +1,4 @@ -use libc::size_t; +use crate::ffi::size_t; /// A more detailed error object returned by some hyper functions. /// diff --git a/src/ffi/http_types.rs b/src/ffi/http_types.rs index 2779cb191f..8807e29481 100644 --- a/src/ffi/http_types.rs +++ b/src/ffi/http_types.rs @@ -1,6 +1,6 @@ +use std::ffi::{c_int, c_void}; + use bytes::Bytes; -use libc::{c_int, size_t}; -use std::ffi::c_void; use super::body::hyper_body; use super::error::hyper_code; @@ -8,6 +8,7 @@ use super::task::{hyper_task_return_type, AsTaskType}; use super::{UserDataPointer, HYPER_ITER_CONTINUE}; use crate::body::Incoming as IncomingBody; use crate::ext::{HeaderCaseMap, OriginalHeaderOrder, ReasonPhrase}; +use crate::ffi::size_t; use crate::header::{HeaderName, HeaderValue}; use crate::{HeaderMap, Method, Request, Response, Uri}; diff --git a/src/ffi/io.rs b/src/ffi/io.rs index 1bf9aa7a97..89978b9e57 100644 --- a/src/ffi/io.rs +++ b/src/ffi/io.rs @@ -2,10 +2,9 @@ use std::ffi::c_void; use std::pin::Pin; use std::task::{Context, Poll}; -use crate::rt::{Read, Write}; -use libc::size_t; - use super::task::hyper_context; +use crate::ffi::size_t; +use crate::rt::{Read, Write}; /// Sentinel value to return from a read or write callback that the operation /// is pending. diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index 664b6439d6..cdcbc4822d 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -62,19 +62,19 @@ pub use self::io::*; pub use self::task::*; /// Return in iter functions to continue iterating. -pub const HYPER_ITER_CONTINUE: libc::c_int = 0; +pub const HYPER_ITER_CONTINUE: std::ffi::c_int = 0; /// Return in iter functions to stop iterating. #[allow(unused)] -pub const HYPER_ITER_BREAK: libc::c_int = 1; +pub const HYPER_ITER_BREAK: std::ffi::c_int = 1; /// An HTTP Version that is unspecified. -pub const HYPER_HTTP_VERSION_NONE: libc::c_int = 0; +pub const HYPER_HTTP_VERSION_NONE: std::ffi::c_int = 0; /// The HTTP/1.0 version. -pub const HYPER_HTTP_VERSION_1_0: libc::c_int = 10; +pub const HYPER_HTTP_VERSION_1_0: std::ffi::c_int = 10; /// The HTTP/1.1 version. -pub const HYPER_HTTP_VERSION_1_1: libc::c_int = 11; +pub const HYPER_HTTP_VERSION_1_1: std::ffi::c_int = 11; /// The HTTP/2 version. -pub const HYPER_HTTP_VERSION_2: libc::c_int = 20; +pub const HYPER_HTTP_VERSION_2: std::ffi::c_int = 20; #[derive(Clone)] struct UserDataPointer(*mut std::ffi::c_void); @@ -87,9 +87,13 @@ unsafe impl Sync for UserDataPointer {} /// cbindgen:ignore static VERSION_CSTR: &str = concat!(env!("CARGO_PKG_VERSION"), "\0"); +// `core::ffi::c_size_t` is a nightly-only experimental API. +// https://github.com/rust-lang/rust/issues/88345 +type size_t = usize; + ffi_fn! { /// Returns a static ASCII (null terminated) string of the hyper version. - fn hyper_version() -> *const libc::c_char { + fn hyper_version() -> *const std::ffi::c_char { VERSION_CSTR.as_ptr() as _ } ?= std::ptr::null() } diff --git a/src/ffi/task.rs b/src/ffi/task.rs index f53a7b1f5a..5b33d42b93 100644 --- a/src/ffi/task.rs +++ b/src/ffi/task.rs @@ -1,4 +1,4 @@ -use std::ffi::c_void; +use std::ffi::{c_int, c_void}; use std::future::Future; use std::pin::Pin; use std::ptr; @@ -9,7 +9,6 @@ use std::sync::{ use std::task::{Context, Poll}; use futures_util::stream::{FuturesUnordered, Stream}; -use libc::c_int; use super::error::hyper_code; use super::UserDataPointer;