From ed2fdb7b6a2963cea7577df05ddc41c56fee7246 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Wed, 7 Apr 2021 16:12:02 -0700 Subject: [PATCH] chore(ffi): fix compile errors and warnings (#2492) As I understand it, "cargo rustc" in gen_header.sh generates a ton of errors, but still manages to generate an object that can be used by cbindgen to generate hyper.h. However, I tried to make a separate change to add more fields to hyper.h, and learned that "cargo rustc" stops if it reaches 50 errors, which I reached. I was able to buy some headroom and fix a number of the compilation errors by adding imports to the fake Cargo.toml we generate in gen_header.sh. I wasn't sure how to resolve imports like "crate::Result" which appear to reference the top-level src/error.rs, and print an error when they are compiled in gen_header.sh. But I only need to buy headroom under the 50 error count for now, which I was able to do by adding the imports. It is possible that someone more familiar with Rust than me could look at this and know what to change to get the total number of errors to zero. --- capi/gen_header.sh | 23 ++++++++++++++++++++++- src/ffi/mod.rs | 3 --- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/capi/gen_header.sh b/capi/gen_header.sh index a3a02e1c60..9319857d97 100755 --- a/capi/gen_header.sh +++ b/capi/gen_header.sh @@ -41,6 +41,27 @@ edition = "2018" publish = false [dependencies] +# Determined which dependencies we need by running the "cargo rustc" command +# below and watching the compile error output for references to unknown imports, +# until we didn't get any errors. +bytes = "1" +futures-channel = "0.3" +futures-util = { version = "0.3", default-features = false, features = ["alloc"] } +libc = { version = "0.2", optional = true } +http = "0.2" +http-body = "0.4" +tokio = { version = "1", features = ["rt"] } + +[features] +default = [ + "client", + "ffi", + "http1", +] + +http1 = [] +client = [] +ffi = ["libc", "tokio/rt"] EOF cp "$CAPI_DIR/include/hyper.h" "$header_file_backup" @@ -50,7 +71,7 @@ cp "$CAPI_DIR/include/hyper.h" "$header_file_backup" cd "${WORK_DIR}" || exit 2 # Expand just the ffi module -if ! output=$(cargo rustc -- -Z unstable-options --pretty=expanded 2>&1 > expanded.rs); then +if ! output=$(RUSTFLAGS='--cfg hyper_unstable_ffi' cargo rustc -- -Z unstable-options --pretty=expanded 2>&1 > expanded.rs); then # As of April 2021 the script above prints a lot of warnings/errors, and # exits with a nonzero return code, but hyper.h still gets generated. echo "$output" diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index 3d2c7a8df4..83011ff0fc 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -61,9 +61,6 @@ pub use self::http_types::*; pub use self::io::*; pub use self::task::*; -pub(crate) use self::body::UserBody; -pub(crate) use self::http_types::{HeaderCaseMap, ReasonPhrase}; - /// Return in iter functions to continue iterating. pub const HYPER_ITER_CONTINUE: libc::c_int = 0; /// Return in iter functions to stop iterating.