Skip to content

Commit

Permalink
chore(ffi): only backup hyper.h when passing --verify (#3800)
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai authored Nov 29, 2024
1 parent 8cf1121 commit 12717d1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions capi/gen_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
set -e

CAPI_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
header_file="$CAPI_DIR/include/hyper.h"
header_file_backup="$CAPI_DIR/include/hyper.h.backup"

verify_flag=$1
function cleanup {
rm -rf "$WORK_DIR" || true
rm "$header_file_backup" || true
if [[ "--verify" == "$verify_flag" ]]; then
rm "$header_file_backup" || true
fi
}

trap cleanup EXIT
Expand All @@ -28,7 +31,10 @@ if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
exit 1
fi

cp "$CAPI_DIR/include/hyper.h" "$header_file_backup"
# backup hyper.h
if [[ "--verify" == "$verify_flag" ]]; then
cp "$header_file" "$header_file_backup"
fi

# Expand just the ffi module
if ! RUSTFLAGS='--cfg hyper_unstable_ffi' cargo expand --features client,http1,http2,ffi ::ffi 2> $WORK_DIR/expand_stderr.err > $WORK_DIR/expanded.rs; then
Expand All @@ -39,13 +45,13 @@ fi
if ! cbindgen \
--config "$CAPI_DIR/cbindgen.toml" \
--lockfile "$CAPI_DIR/../Cargo.lock" \
--output "$CAPI_DIR/include/hyper.h" \
--output "$header_file" \
"${@}"\
$WORK_DIR/expanded.rs 2> $WORK_DIR/cbindgen_stderr.err; then
bindgen_exit_code=$?
if [[ "--verify" == "$1" ]]; then
if [[ "--verify" == "$verify_flag" ]]; then
echo "Changes from previous header (old < > new)"
diff -u "$header_file_backup" "$CAPI_DIR/include/hyper.h"
diff -u "$header_file_backup" "$header_file"
else
echo "cbindgen failed:"
cat $WORK_DIR/cbindgen_stderr.err
Expand Down

0 comments on commit 12717d1

Please sign in to comment.