Skip to content

Commit

Permalink
chore(ffi): fix compile errors and warnings (#2492)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevinburke committed Apr 7, 2021
1 parent aa4a2ea commit ed2fdb7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
23 changes: 22 additions & 1 deletion capi/gen_header.sh
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions src/ffi/mod.rs
Expand Up @@ -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.
Expand Down

0 comments on commit ed2fdb7

Please sign in to comment.