From f157b52993481387c20c8ec0b85f21ee15a64738 Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 8 Nov 2023 20:28:20 +0900 Subject: [PATCH 1/8] chore(ci): update to actions/checkout@v4 --- .github/workflows/CI.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 415e59ed57..382710b8fd 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -30,7 +30,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Install Rust uses: actions-rs/toolchain@v1 @@ -75,7 +75,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Install Rust (${{ matrix.rust }}) uses: actions-rs/toolchain@v1 @@ -112,7 +112,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Install Rust (${{ matrix.rust }}) uses: actions-rs/toolchain@v1 @@ -134,7 +134,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Install Rust uses: actions-rs/toolchain@v1 @@ -154,7 +154,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Install Rust uses: actions-rs/toolchain@v1 @@ -182,7 +182,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Install Rust (${{ matrix.rust }}) uses: actions-rs/toolchain@v1 @@ -203,7 +203,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Install Rust uses: actions-rs/toolchain@v1 @@ -242,7 +242,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Install Rust uses: actions-rs/toolchain@v1 @@ -276,7 +276,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Install Rust uses: actions-rs/toolchain@v1 From 2880f6c8b91a10333e188faa1d77c6ad5e3207e7 Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 8 Nov 2023 20:47:44 +0900 Subject: [PATCH 2/8] chore(ci): replace actions-rs/toolchain with dtolnay/rust-toolchain --- .github/workflows/CI.yml | 48 ++++++++-------------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 382710b8fd..0302cf63ef 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -33,11 +33,8 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - profile: minimal - toolchain: stable - override: true components: rustfmt - name: cargo fmt --check @@ -78,11 +75,9 @@ jobs: uses: actions/checkout@v4 - name: Install Rust (${{ matrix.rust }}) - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - profile: minimal toolchain: ${{ matrix.rust }} - override: true - name: Test uses: actions-rs/cargo@v1 @@ -115,11 +110,9 @@ jobs: uses: actions/checkout@v4 - name: Install Rust (${{ matrix.rust }}) - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - profile: minimal toolchain: ${{ matrix.rust }} - override: true - name: Check uses: actions-rs/cargo@v1 @@ -137,12 +130,9 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@nightly with: - profile: minimal - toolchain: nightly components: miri - override: true - name: Test # Can't enable tcp feature since Miri does not support the tokio runtime @@ -157,11 +147,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true + uses: dtolnay/rust-toolchain@nightly - name: Install cargo-hack run: cargo install cargo-hack @@ -185,11 +171,9 @@ jobs: uses: actions/checkout@v4 - name: Install Rust (${{ matrix.rust }}) - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - profile: minimal toolchain: ${{ matrix.rust }} - override: true - name: Check uses: actions-rs/cargo@v1 @@ -206,11 +190,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true + uses: dtolnay/rust-toolchain@nightly - name: Install cbindgen uses: actions-rs/cargo@v1 @@ -245,13 +225,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - default: true - override: true - components: cargo + uses: dtolnay/rust-toolchain@nightly - name: Install cbindgen uses: actions-rs/cargo@v1 @@ -279,11 +253,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true + uses: dtolnay/rust-toolchain@nightly - name: cargo doc uses: actions-rs/cargo@v1 From c4022800551a6a1541fc5c834cb8678f2d49597f Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 8 Nov 2023 20:52:02 +0900 Subject: [PATCH 3/8] chore(ci): use cargo-hack --no-dev-deps option to check without dev-dependencies --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0302cf63ef..12dc314aac 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -147,13 +147,13 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: dtolnay/rust-toolchain@nightly + uses: dtolnay/rust-toolchain@stable - name: Install cargo-hack run: cargo install cargo-hack - name: check --feature-powerset - run: cargo hack check --feature-powerset --depth 2 --skip ffi -Z avoid-dev-deps + run: cargo hack --no-dev-deps check --feature-powerset --depth 2 --skip ffi deprecated: name: Check deprecated on ${{ matrix.rust }} From ff1d7f9d610df4ea0c1e53493cd1c48c6365476a Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 8 Nov 2023 21:53:25 +0900 Subject: [PATCH 4/8] chore(ci): replace actions-rs with run and use taiki-e/install-action or taiki-e/cache-cargo-install-action --- .github/workflows/CI.yml | 52 ++++++++++------------------------------ 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 12dc314aac..599dcb4bd7 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -80,17 +80,11 @@ jobs: toolchain: ${{ matrix.rust }} - name: Test - uses: actions-rs/cargo@v1 - with: - command: test - args: ${{ matrix.features }} + run: cargo test ${{ matrix.features }} - name: Test all benches if: matrix.benches - uses: actions-rs/cargo@v1 - with: - command: test - args: --benches ${{ matrix.features }} + run: cargo test --benches ${{ matrix.features }} msrv: name: Check MSRV (${{ matrix.rust }}) @@ -115,10 +109,7 @@ jobs: toolchain: ${{ matrix.rust }} - name: Check - uses: actions-rs/cargo@v1 - with: - command: check - args: --features full + run: cargo check --features full miri: name: Test with Miri @@ -150,7 +141,7 @@ jobs: uses: dtolnay/rust-toolchain@stable - name: Install cargo-hack - run: cargo install cargo-hack + uses: taiki-e/install-action@cargo-hack - name: check --feature-powerset run: cargo hack --no-dev-deps check --feature-powerset --depth 2 --skip ffi @@ -176,10 +167,7 @@ jobs: toolchain: ${{ matrix.rust }} - name: Check - uses: actions-rs/cargo@v1 - with: - command: check - args: --features full,backports,deprecated + run: cargo check --features full,backports,deprecated ffi: name: Test C API (FFI) @@ -193,29 +181,22 @@ jobs: uses: dtolnay/rust-toolchain@nightly - name: Install cbindgen - uses: actions-rs/cargo@v1 + uses: taiki-e/cache-cargo-install-action@v1 with: - command: install - args: cbindgen + tool: cbindgen - name: Build FFI - uses: actions-rs/cargo@v1 + run: cargo rustc --features client,http1,http2,ffi --crate-type cdylib env: RUSTFLAGS: --cfg hyper_unstable_ffi - with: - command: rustc - args: --features client,http1,http2,ffi -Z unstable-options --crate-type cdylib - name: Make Examples run: cd capi/examples && make client - name: Run FFI unit tests - uses: actions-rs/cargo@v1 + run: cargo test --features full,ffi --lib env: RUSTFLAGS: --cfg hyper_unstable_ffi - with: - command: test - args: --features full,ffi --lib ffi-header: name: Verify hyper.h is up to date @@ -228,18 +209,14 @@ jobs: uses: dtolnay/rust-toolchain@nightly - name: Install cbindgen - uses: actions-rs/cargo@v1 + uses: taiki-e/cache-cargo-install-action@v1 with: - command: install - args: cbindgen + tool: cbindgen - name: Build FFI - uses: actions-rs/cargo@v1 + run: cargo build --features client,http1,http2,ffi env: RUSTFLAGS: --cfg hyper_unstable_ffi - with: - command: build - args: --features client,http1,http2,ffi - name: Ensure that hyper.h is up to date run: ./capi/gen_header.sh --verify @@ -256,7 +233,4 @@ jobs: uses: dtolnay/rust-toolchain@nightly - name: cargo doc - uses: actions-rs/cargo@v1 - with: - command: rustdoc - args: --features full,ffi -- --cfg docsrs --cfg hyper_unstable_ffi -D broken-intra-doc-links + run: cargo rustdoc --features full,ffi -- --cfg docsrs --cfg hyper_unstable_ffi -D broken-intra-doc-links From a0f4e34a3cda997a597d656206f36852659ec329 Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 8 Nov 2023 20:57:00 +0900 Subject: [PATCH 5/8] chore(ci): use stable rust for building C API --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 599dcb4bd7..a7a38bf641 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -178,7 +178,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: dtolnay/rust-toolchain@nightly + uses: dtolnay/rust-toolchain@stable - name: Install cbindgen uses: taiki-e/cache-cargo-install-action@v1 From c357ecc1fc707d460f5ccf321d985540bb92c655 Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 8 Nov 2023 22:09:36 +0900 Subject: [PATCH 6/8] chore(ci): check C header file with stable rust --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a7a38bf641..c4db2f5f63 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -206,7 +206,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: dtolnay/rust-toolchain@nightly + uses: dtolnay/rust-toolchain@stable - name: Install cbindgen uses: taiki-e/cache-cargo-install-action@v1 From 68b2722f7a2d444a24b84f589e7597139b39cc56 Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 8 Nov 2023 22:25:08 +0900 Subject: [PATCH 7/8] chore(ffi): revamp gen_header using cargo-expand --- .github/workflows/CI.yml | 7 ++++ capi/gen_header.sh | 89 ++++++++-------------------------------- 2 files changed, 23 insertions(+), 73 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c4db2f5f63..ca53326735 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -213,6 +213,13 @@ jobs: with: tool: cbindgen + - name: Install cargo-expand + uses: taiki-e/cache-cargo-install-action@v1 + with: + tool: cargo-expand + + - uses: Swatinem/rust-cache@v2 + - name: Build FFI run: cargo build --features client,http1,http2,ffi env: diff --git a/capi/gen_header.sh b/capi/gen_header.sh index d0b9c13a32..7a08d3e6ff 100755 --- a/capi/gen_header.sh +++ b/capi/gen_header.sh @@ -6,101 +6,44 @@ set -e CAPI_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -WORK_DIR=$(mktemp -d) - -# check if tmp dir was created -if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then - echo "Could not create temp dir" - exit 1 -fi - header_file_backup="$CAPI_DIR/include/hyper.h.backup" function cleanup { - rm -rf "$WORK_DIR" + rm -rf "$WORK_DIR" || true rm "$header_file_backup" || true } trap cleanup EXIT -mkdir "$WORK_DIR/src" - -# Fake a library -cat > "$WORK_DIR/src/lib.rs" << EOF -#[path = "$CAPI_DIR/../src/ffi/mod.rs"] -pub mod ffi; -EOF - -# And its Cargo.toml -cat > "$WORK_DIR/Cargo.toml" << EOF -[package] -name = "hyper" -version = "0.0.0" -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", -] +WORK_DIR=$(mktemp -d) -http1 = [] -client = [] -ffi = ["libc", "tokio/rt"] -EOF +# check if tmp dir was created +if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then + echo "Could not create temp dir" + exit 1 +fi 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}" || exit 2 - # Expand just the ffi module -if ! output=$(RUSTFLAGS='--cfg hyper_unstable_ffi' cargo rustc -- -Z unpretty=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. - # - # However, on Github Actions, this will result in automatic "annotations" - # being added to files not related to a PR, so if this is `--verify` mode, - # then don't show it. - # - # But yes show it when using it locally. - if [[ "--verify" != "$1" ]]; then - echo "$output" - fi +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 + cat $WORK_DIR/expand_stderr.err fi -# Replace the previous copy with the single expanded file -rm -rf ./src -mkdir src -mv expanded.rs src/lib.rs - - # Bindgen! if ! cbindgen \ --config "$CAPI_DIR/cbindgen.toml" \ --lockfile "$CAPI_DIR/../Cargo.lock" \ --output "$CAPI_DIR/include/hyper.h" \ - "${@}"; then + "${@}"\ + $WORK_DIR/expanded.rs 2> $WORK_DIR/cbindgen_stderr.err; then bindgen_exit_code=$? if [[ "--verify" == "$1" ]]; then - echo "diff generated (<) vs backup (>)" - diff "$CAPI_DIR/include/hyper.h" "$header_file_backup" + echo "Changes from previous header (old < > new)" + diff -u "$header_file_backup" "$CAPI_DIR/include/hyper.h" + else + echo "cbindgen failed:" + cat $WORK_DIR/cbindgen_stderr.err fi exit $bindgen_exit_code fi From b24cc506d8d26ae632fb6d8b3a695bc320bd49e3 Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 8 Nov 2023 22:07:15 +0900 Subject: [PATCH 8/8] chore(ci): cache rust dependency --- .github/workflows/CI.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ca53326735..91bdd675c2 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -79,6 +79,8 @@ jobs: with: toolchain: ${{ matrix.rust }} + - uses: Swatinem/rust-cache@v2 + - name: Test run: cargo test ${{ matrix.features }} @@ -108,6 +110,8 @@ jobs: with: toolchain: ${{ matrix.rust }} + - uses: Swatinem/rust-cache@v2 + - name: Check run: cargo check --features full @@ -143,6 +147,8 @@ jobs: - name: Install cargo-hack uses: taiki-e/install-action@cargo-hack + - uses: Swatinem/rust-cache@v2 + - name: check --feature-powerset run: cargo hack --no-dev-deps check --feature-powerset --depth 2 --skip ffi @@ -166,6 +172,8 @@ jobs: with: toolchain: ${{ matrix.rust }} + - uses: Swatinem/rust-cache@v2 + - name: Check run: cargo check --features full,backports,deprecated @@ -185,6 +193,8 @@ jobs: with: tool: cbindgen + - uses: Swatinem/rust-cache@v2 + - name: Build FFI run: cargo rustc --features client,http1,http2,ffi --crate-type cdylib env: