Skip to content

Commit ed2fdb7

Browse files
authored
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.
1 parent aa4a2ea commit ed2fdb7

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

capi/gen_header.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ edition = "2018"
4141
publish = false
4242
4343
[dependencies]
44+
# Determined which dependencies we need by running the "cargo rustc" command
45+
# below and watching the compile error output for references to unknown imports,
46+
# until we didn't get any errors.
47+
bytes = "1"
48+
futures-channel = "0.3"
49+
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
50+
libc = { version = "0.2", optional = true }
51+
http = "0.2"
52+
http-body = "0.4"
53+
tokio = { version = "1", features = ["rt"] }
54+
55+
[features]
56+
default = [
57+
"client",
58+
"ffi",
59+
"http1",
60+
]
61+
62+
http1 = []
63+
client = []
64+
ffi = ["libc", "tokio/rt"]
4465
EOF
4566

4667
cp "$CAPI_DIR/include/hyper.h" "$header_file_backup"
@@ -50,7 +71,7 @@ cp "$CAPI_DIR/include/hyper.h" "$header_file_backup"
5071
cd "${WORK_DIR}" || exit 2
5172

5273
# Expand just the ffi module
53-
if ! output=$(cargo rustc -- -Z unstable-options --pretty=expanded 2>&1 > expanded.rs); then
74+
if ! output=$(RUSTFLAGS='--cfg hyper_unstable_ffi' cargo rustc -- -Z unstable-options --pretty=expanded 2>&1 > expanded.rs); then
5475
# As of April 2021 the script above prints a lot of warnings/errors, and
5576
# exits with a nonzero return code, but hyper.h still gets generated.
5677
echo "$output"

src/ffi/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ pub use self::http_types::*;
6161
pub use self::io::*;
6262
pub use self::task::*;
6363

64-
pub(crate) use self::body::UserBody;
65-
pub(crate) use self::http_types::{HeaderCaseMap, ReasonPhrase};
66-
6764
/// Return in iter functions to continue iterating.
6865
pub const HYPER_ITER_CONTINUE: libc::c_int = 0;
6966
/// Return in iter functions to stop iterating.

0 commit comments

Comments
 (0)