chore(ffi): run gen_header.sh in CI environment (#2488)

Clean up the script so that any unexpected error terminates the
script, and stop suppressing errors that may contain useful
information (for example, that you are using the stable version but
need to use the nightly).

This is useful because if hyper.h is not up to date going forward the
CI should flag it. As is, there are a bunch of changes to hyper.h that
have not been checked in (or were generated by a newer version of the
cbindgen script.)

Fixes #2483.
This commit is contained in:
Kevin Burke
2021-04-06 14:46:14 -07:00
committed by GitHub
parent c7ab1aace1
commit a5464f761a
4 changed files with 241 additions and 98 deletions

View File

@@ -1,9 +1,13 @@
#!/usr/bin/env bash
# This script regenerates hyper.h. As of April 2021, it only works with the
# nightly build of Rust.
set -e
CAPI_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
WORK_DIR=`mktemp -d`
WORK_DIR=$(mktemp -d)
# check if tmp dir was created
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
@@ -14,9 +18,8 @@ fi
header_file_backup="$CAPI_DIR/include/hyper.h.backup"
function cleanup {
#echo "$WORK_DIR"
rm -rf "$WORK_DIR"
rm "$header_file_backup"
rm "$header_file_backup" || true
}
trap cleanup EXIT
@@ -44,10 +47,14 @@ cp "$CAPI_DIR/include/hyper.h" "$header_file_backup"
#cargo metadata --no-default-features --features ffi --format-version 1 > "$WORK_DIR/metadata.json"
cd $WORK_DIR
cd "${WORK_DIR}" || exit 2
# Expand just the ffi module
cargo rustc -- -Z unstable-options --pretty=expanded > expanded.rs 2>/dev/null
if ! output=$(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"
fi
# Replace the previous copy with the single expanded file
rm -rf ./src
@@ -56,17 +63,17 @@ mv expanded.rs src/lib.rs
# Bindgen!
cbindgen\
-c "$CAPI_DIR/cbindgen.toml"\
--lockfile "$CAPI_DIR/../Cargo.lock"\
-o "$CAPI_DIR/include/hyper.h"\
$1
bindgen_exit_code=$?
if [[ "--verify" == "$1" && "$bindgen_exit_code" != 0 ]]; then
echo "diff generated (<) vs backup (>)"
diff "$CAPI_DIR/include/hyper.h" "$header_file_backup"
if ! cbindgen \
--config "$CAPI_DIR/cbindgen.toml" \
--lockfile "$CAPI_DIR/../Cargo.lock" \
--output "$CAPI_DIR/include/hyper.h" \
"${@}"; then
bindgen_exit_code=$?
if [[ "--verify" == "$1" ]]; then
echo "diff generated (<) vs backup (>)"
diff "$CAPI_DIR/include/hyper.h" "$header_file_backup"
fi
exit $bindgen_exit_code
fi
exit $bindgen_exit_code
exit 0