|
6 | 6 | set -e
|
7 | 7 |
|
8 | 8 | CAPI_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
9 |
| - |
10 |
| -WORK_DIR=$(mktemp -d) |
11 |
| - |
12 |
| -# check if tmp dir was created |
13 |
| -if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then |
14 |
| - echo "Could not create temp dir" |
15 |
| - exit 1 |
16 |
| -fi |
17 |
| - |
18 | 9 | header_file_backup="$CAPI_DIR/include/hyper.h.backup"
|
19 | 10 |
|
20 | 11 | function cleanup {
|
21 |
| - rm -rf "$WORK_DIR" |
| 12 | + rm -rf "$WORK_DIR" || true |
22 | 13 | rm "$header_file_backup" || true
|
23 | 14 | }
|
24 | 15 |
|
25 | 16 | trap cleanup EXIT
|
26 | 17 |
|
27 |
| -mkdir "$WORK_DIR/src" |
28 |
| - |
29 |
| -# Fake a library |
30 |
| -cat > "$WORK_DIR/src/lib.rs" << EOF |
31 |
| -#[path = "$CAPI_DIR/../src/ffi/mod.rs"] |
32 |
| -pub mod ffi; |
33 |
| -EOF |
34 |
| - |
35 |
| -# And its Cargo.toml |
36 |
| -cat > "$WORK_DIR/Cargo.toml" << EOF |
37 |
| -[package] |
38 |
| -name = "hyper" |
39 |
| -version = "0.0.0" |
40 |
| -edition = "2018" |
41 |
| -publish = false |
42 |
| -
|
43 |
| -[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 |
| -] |
| 18 | +WORK_DIR=$(mktemp -d) |
61 | 19 |
|
62 |
| -http1 = [] |
63 |
| -client = [] |
64 |
| -ffi = ["libc", "tokio/rt"] |
65 |
| -EOF |
| 20 | +# check if tmp dir was created |
| 21 | +if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then |
| 22 | + echo "Could not create temp dir" |
| 23 | + exit 1 |
| 24 | +fi |
66 | 25 |
|
67 | 26 | cp "$CAPI_DIR/include/hyper.h" "$header_file_backup"
|
68 | 27 |
|
69 |
| -#cargo metadata --no-default-features --features ffi --format-version 1 > "$WORK_DIR/metadata.json" |
70 |
| - |
71 |
| -cd "${WORK_DIR}" || exit 2 |
72 |
| - |
73 | 28 | # Expand just the ffi module
|
74 |
| -if ! output=$(RUSTFLAGS='--cfg hyper_unstable_ffi' cargo rustc -- -Z unpretty=expanded 2>&1 > expanded.rs); then |
75 |
| - # As of April 2021 the script above prints a lot of warnings/errors, and |
76 |
| - # exits with a nonzero return code, but hyper.h still gets generated. |
77 |
| - # |
78 |
| - # However, on Github Actions, this will result in automatic "annotations" |
79 |
| - # being added to files not related to a PR, so if this is `--verify` mode, |
80 |
| - # then don't show it. |
81 |
| - # |
82 |
| - # But yes show it when using it locally. |
83 |
| - if [[ "--verify" != "$1" ]]; then |
84 |
| - echo "$output" |
85 |
| - fi |
| 29 | +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 |
| 30 | + cat $WORK_DIR/expand_stderr.err |
86 | 31 | fi
|
87 | 32 |
|
88 |
| -# Replace the previous copy with the single expanded file |
89 |
| -rm -rf ./src |
90 |
| -mkdir src |
91 |
| -mv expanded.rs src/lib.rs |
92 |
| - |
93 |
| - |
94 | 33 | # Bindgen!
|
95 | 34 | if ! cbindgen \
|
96 | 35 | --config "$CAPI_DIR/cbindgen.toml" \
|
97 | 36 | --lockfile "$CAPI_DIR/../Cargo.lock" \
|
98 | 37 | --output "$CAPI_DIR/include/hyper.h" \
|
99 |
| - "${@}"; then |
| 38 | + "${@}"\ |
| 39 | + $WORK_DIR/expanded.rs 2> $WORK_DIR/cbindgen_stderr.err; then |
100 | 40 | bindgen_exit_code=$?
|
101 | 41 | if [[ "--verify" == "$1" ]]; then
|
102 |
| - echo "diff generated (<) vs backup (>)" |
103 |
| - diff "$CAPI_DIR/include/hyper.h" "$header_file_backup" |
| 42 | + echo "Changes from previous header (old < > new)" |
| 43 | + diff -u "$header_file_backup" "$CAPI_DIR/include/hyper.h" |
| 44 | + else |
| 45 | + echo "cbindgen failed:" |
| 46 | + cat $WORK_DIR/cbindgen_stderr.err |
104 | 47 | fi
|
105 | 48 | exit $bindgen_exit_code
|
106 | 49 | fi
|
|
0 commit comments