diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:44:09 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:44:09 +0000 |
commit | 4aba1fc520d3106fdd829c7f2433dc85e0999311 (patch) | |
tree | a54e24d149f00ad487d9da00d4ded4043d6d1787 | |
parent | 0b3aad9ad65413280b281da574c33a3a95ca0c7f (diff) | |
parent | c21902fbbc8837708a21f071a48ba962fdf0267c (diff) | |
download | grpcio-aml_tz3_314012010.tar.gz |
Snap for 8730993 from c21902fbbc8837708a21f071a48ba962fdf0267c to mainline-tzdata3-releaseaml_tz3_314012070aml_tz3_314012050aml_tz3_314012010aml_tz3_313110000aml_tz3_312511020aml_tz3_312511010aml_tz3_312410020aml_tz3_312410010android12-mainline-tzdata3-releaseaml_tz3_314012010
Change-Id: Ia63f6daf412112ee1aea54a51b7d0c1b31b2f433
-rw-r--r-- | .cargo/config | 2 | ||||
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .clang-format | 1 | ||||
-rw-r--r-- | .clang-tidy | 97 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 72 | ||||
-rw-r--r-- | .gitmodules | 4 | ||||
-rw-r--r-- | .travis.yml | 59 | ||||
-rw-r--r-- | Android.bp | 48 | ||||
-rw-r--r-- | CHANGELOG.md | 16 | ||||
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | Cargo.toml.orig | 21 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.android | 2 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | cargo2android.json | 10 | ||||
-rwxr-xr-x | scripts/format-grpc-sys | 2 | ||||
-rwxr-xr-x | scripts/generate-bindings.sh | 15 | ||||
-rwxr-xr-x | scripts/lint-grpc-sys.sh | 2 | ||||
-rwxr-xr-x | scripts/reset-submodule.cmd | 9 | ||||
-rw-r--r-- | src/call/client.rs | 4 | ||||
-rw-r--r-- | src/call/mod.rs | 129 | ||||
-rw-r--r-- | src/call/server.rs | 31 | ||||
-rw-r--r-- | src/channel.rs | 3 | ||||
-rw-r--r-- | src/codec.rs | 55 | ||||
-rw-r--r-- | src/error.rs | 24 | ||||
-rw-r--r-- | src/lib.rs | 23 | ||||
-rw-r--r-- | src/metadata.rs | 19 | ||||
-rw-r--r-- | src/server.rs | 5 | ||||
-rw-r--r-- | src/task/promise.rs | 4 |
29 files changed, 264 insertions, 413 deletions
diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index d8c2032..0000000 --- a/.cargo/config +++ /dev/null @@ -1,2 +0,0 @@ -[alias] -xtask = "run --manifest-path ./xtask/Cargo.toml --" diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 4f6a222..05823ce 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "61a60923255fe618589bf03ece46fff097b8cb43" + "sha1": "b35467b1bfe58eedf4e77025432074d361be591f" } } diff --git a/.clang-format b/.clang-format index 7460950..b641a64 100644 --- a/.clang-format +++ b/.clang-format @@ -3,7 +3,6 @@ Language: Cpp BasedOnStyle: Google DerivePointerAlignment: false PointerAlignment: Left -IncludeBlocks: Preserve --- Language: ObjC BasedOnStyle: Google diff --git a/.clang-tidy b/.clang-tidy index 8714bad..752b25e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,122 +1,37 @@ --- -# Note on checks are disabled on purpose -# -# - abseil-no-namespace -# https://bugs.llvm.org/show_bug.cgi?id=47947 -# -# - bugprone-reserved-identifier -# Some macros need to be defined for portability purpose; e.g. _BSD_SOURCE. -# -# - google-upgrade-googletest-case -# This requires googletest 1.10 which is higher than ones installed on many linux distributions. -# -# - modernize-redundant-void-arg -# Some source should be strictly C99 and func(void) should be used. -# -# Note on checks which will be enabled in future. These are good to have but -# it's not activated yet due to the existing issues with the checks. -# Once those issues are clear, these checks can be enabled later. -# -# - bugprone-branch-clone -# - bugprone-infinite-loop -# - bugprone-narrowing-conversions -# - bugprone-not-null-terminated-result -# - bugprone-signed-char-misuse -# - bugprone-sizeof-expression -# - bugprone-too-small-loop-variable -# - clang-diagnostic-deprecated-declarations -# - clang-diagnostic-unused-function -# - google-readability-avoid-underscore-in-googletest-name -# - google-runtime-int -# - google-runtime-references -# - modernize-avoid-bind -# - modernize-deprecated-headers -# - modernize-loop-convert -# - modernize-pass-by-value -# - modernize-raw-string-literal -# - modernize-return-braced-init-list -# - modernize-use-auto -# - modernize-use-default-member-init -# - modernize-use-emplace -# - modernize-use-equals-default -# - modernize-use-equals-delete -# - modernize-use-using -# - performance-no-automatic-move -# - performance-unnecessary-copy-initialization -# - performance-unnecessary-value-param -# - readability-else-after-return -# - readability-implicit-bool-conversion -# - readability-redundant-declaration -# - readability-static-definition-in-anonymous-namespace -# +# Disable abseil-no-namespace: https://bugs.llvm.org/show_bug.cgi?id=47947 Checks: '-*, abseil-*, -abseil-no-namespace, bugprone-*, - -bugprone-branch-clone, - -bugprone-infinite-loop, -bugprone-narrowing-conversions, - -bugprone-not-null-terminated-result, - -bugprone-reserved-identifier, - -bugprone-signed-char-misuse, - -bugprone-sizeof-expression, -bugprone-too-small-loop-variable, - google-*, - -google-readability-avoid-underscore-in-googletest-name, - -google-runtime-int, - -google-runtime-references, - -google-upgrade-googletest-case, performance-*, - -performance-no-automatic-move, -performance-unnecessary-copy-initialization, -performance-unnecessary-value-param, - clang-diagnostic-deprecated-register, - clang-diagnostic-expansion-to-defined, - clang-diagnostic-ignored-attributes, - clang-diagnostic-non-pod-varargs, - clang-diagnostic-shadow-field, - clang-diagnostic-shift-sign-overflow, - clang-diagnostic-tautological-undefined-compare, - clang-diagnostic-thread-safety*, - clang-diagnostic-undefined-bool-conversion, - clang-diagnostic-unreachable-code, - clang-diagnostic-unreachable-code-loop-increment, - clang-diagnostic-unused-const-variable, - clang-diagnostic-unused-lambda-capture, - clang-diagnostic-unused-local-typedef, - clang-diagnostic-unused-private-field, - clang-diagnostic-user-defined-warnings, + google-*, + -google-runtime-int, + -google-runtime-references, misc-definitions-in-headers, misc-static-assert, misc-unconventional-assign-operator, misc-uniqueptr-reset-release, misc-unused-alias-decls, misc-unused-using-decls, - modernize-make-shared, modernize-make-unique, + -modernize-redundant-void-arg, modernize-replace-auto-ptr, - modernize-replace-random-shuffle, modernize-shrink-to-fit, - modernize-unary-static-assert, modernize-use-bool-literals, - modernize-use-noexcept, modernize-use-nullptr, modernize-use-override, - modernize-use-transparent-functors, - readability-const-return-type, readability-container-size-empty, - readability-delete-null-pointer, readability-deleted-default, readability-function-size, readability-inconsistent-declaration-parameter-name, - readability-misleading-indentation, - readability-misplaced-array-index, readability-redundant-control-flow, - readability-redundant-function-ptr-dereference, readability-redundant-smartptr-get, - readability-simplify-boolean-expr, - readability-string-compare, - readability-uniqueptr-delete-release' + readability-string-compare' WarningsAsErrors: '*' CheckOptions: - key: readability-function-size.StatementThreshold diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f25093f..3731f9e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,8 +10,7 @@ on: env: RUST_BACKTRACE: 1 - # Some of the bindgen tests generate "deref-nullptr" warnings, see https://github.com/rust-lang/rust-bindgen/issues/1651 - RUSTFLAGS: "--deny=warnings --allow deref-nullptr" + RUSTFLAGS: "--deny=warnings" TEST_BIND: 1 jobs: @@ -22,58 +21,38 @@ jobs: - uses: actions/checkout@v2 - run: sudo apt-get install -y clang-tidy-9 - run: sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-9 100 - - run: which cargo && cargo version && clang --version && openssl version && which cmake && cmake --version - - run: cargo xtask submodule + - run: which go && go version && which cargo && cargo version && clang --version && openssl version && which cmake && cmake --version + - run: scripts/reset-submodule.cmd - run: cargo fmt --all -- --check - run: cargo clippy --all -- -D clippy::all && cargo clippy --all --no-default-features --features prost-codec -- -D clippy::all - - run: cargo xtask clang-lint && git diff-index --quiet HEAD + - run: scripts/lint-grpc-sys.sh && git diff-index --quiet HEAD Linux-Stable: - strategy: - matrix: - include: - - host: ubuntu-latest - profile: - suffix: - - host: ARM64 - profile: --release - suffix: -Arm64 - name: Linux-Stable${{ matrix.suffix }} - runs-on: ${{ matrix.host }} + name: Linux-Stable + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: sudo apt install -y protobuf-compiler - - run: which cargo && cargo version && clang --version && openssl version - - run: cargo xtask submodule - - run: env TEST_BIND=0 cargo xtask bindgen && git diff --exit-code HEAD - - run: cargo xtask codegen && git diff --exit-code HEAD; - - run: cargo xtask bindgen + - run: which go && go version && which cargo && cargo version && clang --version && openssl version + - run: scripts/reset-submodule.cmd + - run: env TEST_BIND=0 scripts/generate-bindings.sh && git diff --exit-code HEAD + - run: scripts/generate-bindings.sh - run: cargo build --no-default-features - run: cargo build --no-default-features --features protobuf-codec - run: cargo build --no-default-features --features prost-codec - run: cd proto && cargo build --no-default-features --features prost-codec - run: cargo build - - run: cargo test --all ${{ matrix.profile }} + - run: cargo test --all Linux-Stable-openssl: - strategy: - matrix: - include: - - host: ubuntu-latest - profile: - suffix: - - host: ARM64 - profile: --release - suffix: -Arm64 - name: Linux-Stable-openssl${{ matrix.suffix }} - runs-on: ${{ matrix.host }} + name: Linux-Stable-openssl + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: which cargo && cargo version && clang --version && openssl version - - run: cargo xtask submodule - - run: cargo test --features "openssl-vendored" --all ${{ matrix.profile }} + - run: which go && go version && which cargo && cargo version && clang --version && openssl version + - run: scripts/reset-submodule.cmd + - run: cargo test --features "openssl-vendored" --all - run: cargo clean - - run: cargo test --features "openssl" --all ${{ matrix.profile }} + - run: cargo test --features "openssl" --all Linux-Nightly: name: Linux-Nightly @@ -81,8 +60,8 @@ jobs: steps: - uses: actions/checkout@v2 - run: rustup default nightly - - run: which cargo && cargo version && clang --version && openssl version - - run: cargo xtask submodule + - run: which go && go version && which cargo && cargo version && clang --version && openssl version + - run: scripts/reset-submodule.cmd - run: cargo build --no-default-features - run: cargo build --no-default-features --features protobuf-codec - run: cargo build --no-default-features --features prost-codec @@ -95,8 +74,8 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v2 - - run: which cargo && cargo version && clang --version && openssl version - - run: cargo xtask submodule + - run: which go && go version && which cargo && cargo version && clang --version && openssl version + - run: scripts/reset-submodule.cmd - run: cargo build --no-default-features --features use-bindgen - run: cargo build --no-default-features --features "protobuf-codec use-bindgen" - run: cargo build --no-default-features --features "prost-codec use-bindgen" @@ -109,8 +88,8 @@ jobs: steps: - uses: actions/checkout@v2 - run: brew update && brew upgrade openssl@1.1 - - run: which cargo && cargo version && clang --version && openssl version - - run: cargo xtask submodule + - run: which go && go version && which cargo && cargo version && clang --version && openssl version + - run: scripts/reset-submodule.cmd - run: OPENSSL_ROOT_DIR="/usr/local/opt/openssl@1.1/" cargo test --features "openssl" --all - run: cargo test --features "openssl-vendored" --all @@ -119,13 +98,12 @@ jobs: runs-on: windows-latest env: LIBCLANG_PATH: 'C:\Program Files\LLVM\bin' - RUSTFLAGS: "" steps: - uses: actions/checkout@v2 - run: choco install -y llvm - run: refreshenv - run: go version ; cargo version ; cmake --version - - run: cargo xtask submodule + - run: scripts/reset-submodule.cmd - run: cargo build - run: cargo test --all @@ -134,7 +112,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: cargo xtask submodule + - run: scripts/reset-submodule.cmd - run: cd grpc-sys && cargo publish --dry-run - name: Check generated package size run: | diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3ed0061 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "grpc-sys/grpc"] + path = grpc-sys/grpc + url = https://github.com/pingcap/grpc.git + branch = rs-release diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9cc0821 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,59 @@ +# Travis is only used to test ARM64 Linux + +dist: focal +sudo: true +language: rust +git: + submodules: false + +rust: stable + +env: + global: + - RUST_BACKTRACE=1 + # absl deadlock detection performs poorly on arm, so we build it release + # mode to skip the check. Enabling debug-assertions to get safer test + # results. + - RUSTFLAGS="--deny=warnings -C debug-assertions" + - TEST_BIND=1 + +addons: + apt: + update: true + packages: + - libunwind-dev + +jobs: + include: + - os: linux + arch: arm64-graviton2 + vm: virt + before_script: + - scripts/reset-submodule.cmd + - export GRPC_VERSION=1.35.0 + - export PATH="$PATH:$HOME/.cache/bin:$HOME/.cargo/bin" + - which cmake && cmake --version && openssl version + - eval "$(gimme stable)" + script: + - if [[ $TRAVIS_OS_NAME == "linux" ]] && [[ $TRAVIS_RUST_VERSION == "stable" ]]; then + rustup component add rustfmt && cargo fmt --all -- --check; + env TEST_BIND=0 scripts/generate-bindings.sh && git diff --exit-code HEAD; + fi + - ./scripts/generate-bindings.sh + - cargo build --no-default-features + - cargo build --no-default-features --features protobuf-codec + - cargo build --no-default-features --features prost-codec + - cargo build + - travis_wait 40 cargo test --release --all + - os: linux + arch: arm64-graviton2 + vm: virt + before_script: + - scripts/reset-submodule.cmd + - export GRPC_VERSION=1.35.0 + - export PATH="$PATH:$HOME/.cache/bin:$HOME/.cargo/bin" + - sudo apt-get update && sudo apt-get -y install libssl-dev + - which cmake && cmake --version && openssl version + - eval "$(gimme stable)" + script: + - travis_wait 40 cargo test --release --features "openssl-vendored" --all @@ -1,4 +1,4 @@ -// This file is generated by cargo2android.py --config cargo2android.json. +// This file is generated by cargo2android.py --run --device --dependencies --features=protobuf,protobuf-codec. // Do not modify this file as changes will be overridden on upgrade. package { @@ -22,8 +22,6 @@ rust_library { name: "libgrpcio", host_supported: true, crate_name: "grpcio", - cargo_env_compat: true, - cargo_pkg_version: "0.9.1", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -38,9 +36,43 @@ rust_library { "libparking_lot", "libprotobuf", ], - apex_available: [ - "//apex_available:platform", - "com.android.bluetooth", - ], - min_sdk_version: "29", } + +// dependent_library ["feature_list"] +// boringssl-src-0.2.0 +// cc-1.0.67 +// cfg-if-1.0.0 +// cmake-0.1.45 +// futures-0.3.13 "alloc,async-await,default,executor,futures-executor,std" +// futures-channel-0.3.13 "alloc,futures-sink,sink,std" +// futures-core-0.3.13 "alloc,std" +// futures-executor-0.3.13 "std" +// futures-io-0.3.13 "std" +// futures-macro-0.3.13 +// futures-sink-0.3.13 "alloc,std" +// futures-task-0.3.13 "alloc,std" +// futures-util-0.3.13 "alloc,async-await,async-await-macro,channel,futures-channel,futures-io,futures-macro,futures-sink,io,memchr,proc-macro-hack,proc-macro-nested,sink,slab,std" +// grpcio-sys-0.8.1 +// instant-0.1.9 +// libc-0.2.92 "default,std" +// libz-sys-1.1.2 "default,libc,static,stock-zlib" +// lock_api-0.4.2 +// log-0.4.14 +// memchr-2.3.4 "default,std" +// parking_lot-0.11.1 "default" +// parking_lot_core-0.8.3 +// pin-project-lite-0.2.6 +// pin-utils-0.1.0 +// pkg-config-0.3.19 +// proc-macro-hack-0.5.19 +// proc-macro-nested-0.1.7 +// proc-macro2-1.0.26 "default,proc-macro" +// protobuf-2.22.1 +// quote-1.0.9 "default,proc-macro" +// same-file-1.0.6 +// scopeguard-1.1.0 +// slab-0.4.2 +// smallvec-1.6.1 +// syn-1.0.68 "clone-impls,default,derive,full,parsing,printing,proc-macro,quote" +// unicode-xid-0.2.1 "default" +// walkdir-2.3.2 diff --git a/CHANGELOG.md b/CHANGELOG.md index aa28773..f928b24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,6 @@ -# 0.9.1 - 2021-09-18 - -- Make boringssl-src optional (#537) -- codec: avoid overflowing error (#495) - -# 0.9.0 - 2021-05-24 - -- Support rich error (#514) -- Provide default service implementations (#521) -- Support abstract UDS (#523) -- Use default-features=false on libz-sys to allow for zlib-ng (#525) -- Update grpc to 1.38.0 (#526) - -# 0.8.2 - 2021-03-10 +# 0.8.2 - 2012-03-10 - Fix send requirement in connectivity APIs (#516) -- Add default health service implemetations (#518) # 0.8.1 - 2021-03-05 @@ -13,7 +13,7 @@ [package] edition = "2018" name = "grpcio" -version = "0.9.1" +version = "0.8.2" authors = ["The TiKV Project Developers"] autoexamples = false description = "The rust language implementation of gRPC, base on the gRPC c core library." @@ -26,6 +26,8 @@ license = "Apache-2.0" repository = "https://github.com/tikv/grpc-rs" [package.metadata.docs.rs] all-features = true +[profile.release] +debug = true [dependencies.bytes] version = "1.0" optional = true @@ -34,7 +36,7 @@ optional = true version = "0.3" [dependencies.grpcio-sys] -version = "0.9" +version = "0.8" default-features = false [dependencies.libc] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 9755697..8938f97 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "grpcio" -version = "0.9.1" +version = "0.8.2" edition = "2018" authors = ["The TiKV Project Developers"] license = "Apache-2.0" @@ -17,7 +17,7 @@ autoexamples = false all-features = true [dependencies] -grpcio-sys = { path = "grpc-sys", version = "0.9", default-features = false } +grpcio-sys = { path = "grpc-sys", version = "0.8", default-features = false } libc = "0.2" futures = "0.3" protobuf = { version = "2.0", optional = true } @@ -27,17 +27,7 @@ log = "0.4" parking_lot = "0.11" [workspace] -members = [ - "proto", - "benchmark", - "compiler", - "health", - "interop", - "tests-and-examples", -] -# Don't include it in workspace to make it possible to use different version of -# rust-protobuf. -exclude = ["xtask"] +members = ["proto", "benchmark", "compiler", "interop", "tests-and-examples"] [features] default = ["protobuf-codec", "secure", "use-bindgen"] @@ -49,8 +39,11 @@ openssl-vendored = ["secure", "grpcio-sys/openssl-vendored"] no-omit-frame-pointer = ["grpcio-sys/no-omit-frame-pointer"] use-bindgen = ["grpcio-sys/use-bindgen"] +[profile.release] +debug = true + [badges] travis-ci = { repository = "tikv/grpc-rs" } [patch.crates-io] -grpcio-compiler = { path = "compiler", version = "0.9.0", default-features = false } +grpcio-compiler = { path = "compiler", version = "0.8.0", default-features = false } @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/grpcio/grpcio-0.9.1.crate" + value: "https://static.crates.io/crates/grpcio/grpcio-0.8.2.crate" } - version: "0.9.1" + version: "0.8.2" license_type: NOTICE last_upgrade_date { year: 2021 - month: 9 - day: 22 + month: 4 + day: 1 } } diff --git a/README.android b/README.android new file mode 100644 index 0000000..ef72ffa --- /dev/null +++ b/README.android @@ -0,0 +1,2 @@ +The patch in patches/env.diff needs to be updated with crate version update to match +the new crate version. @@ -44,7 +44,7 @@ For Windows, you also need to install following software: ## Build ``` -$ cargo xtask submodule # if you just cloned the repository +$ ./scripts/reset-submodule.cmd # if you just cloned the repository $ cargo build ``` @@ -142,5 +142,5 @@ Make sure to format and test the code before sending a PR. If the content in grpc-sys/grpc is updated, you may need to regenerate bindings: ``` -$ cargo xtask bindgen +$ ./scripts/generate-bindings.sh ``` diff --git a/cargo2android.json b/cargo2android.json deleted file mode 100644 index 001bc3e..0000000 --- a/cargo2android.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "apex-available": [ - "//apex_available:platform", - "com.android.bluetooth" - ], - "device": true, - "features": "protobuf,protobuf-codec", - "min-sdk-version": "29", - "run": true -} diff --git a/scripts/format-grpc-sys b/scripts/format-grpc-sys new file mode 100755 index 0000000..d97445a --- /dev/null +++ b/scripts/format-grpc-sys @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +clang-format-5.0 -i grpc-sys/grpc_wrap.cc diff --git a/scripts/generate-bindings.sh b/scripts/generate-bindings.sh new file mode 100755 index 0000000..81a043e --- /dev/null +++ b/scripts/generate-bindings.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# NOTE: +# This script is only used when you want to generate bindings yourself. +# The generated bindings will overwrite grpc-sys/bindings/* + +if [ "$ARCH" == "" ]; then + ARCH=`uname -p` +fi +export UPDATE_BIND=1 +cargo build -p grpcio-sys --target ${ARCH}-unknown-linux-gnu +rustfmt grpc-sys/bindings/* +if [ "$(uname -s)" == "Linux" ]; then + sed -i '/^pub type .*= ::std::os::raw::.*/d' grpc-sys/bindings/* +fi diff --git a/scripts/lint-grpc-sys.sh b/scripts/lint-grpc-sys.sh new file mode 100755 index 0000000..a3fc7e0 --- /dev/null +++ b/scripts/lint-grpc-sys.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +clang-tidy grpc-sys/grpc_wrap.cc -- -Igrpc-sys/grpc/include -x c++ -std=c++11 diff --git a/scripts/reset-submodule.cmd b/scripts/reset-submodule.cmd new file mode 100755 index 0000000..bac6a35 --- /dev/null +++ b/scripts/reset-submodule.cmd @@ -0,0 +1,9 @@ +git submodule update --init grpc-sys/grpc +cd grpc-sys/grpc +git submodule update --init third_party/cares/cares +git submodule update --init third_party/abseil-cpp +git submodule update --init third_party/re2 +rm -rf third_party/boringssl-with-bazel/* +cd third_party/zlib +git clean -df +git reset --hard diff --git a/src/call/client.rs b/src/call/client.rs index e89862a..d1047bf 100644 --- a/src/call/client.rs +++ b/src/call/client.rs @@ -110,7 +110,7 @@ impl Call { ) -> Result<ClientUnaryReceiver<Resp>> { let call = channel.create_call(method, &opt)?; let mut payload = GrpcSlice::default(); - (method.req_ser())(req, &mut payload)?; + (method.req_ser())(req, &mut payload); let cq_f = check_run(BatchType::CheckRead, |ctx, tag| unsafe { grpc_sys::grpcwrap_call_start_unary( call.call, @@ -163,7 +163,7 @@ impl Call { ) -> Result<ClientSStreamReceiver<Resp>> { let call = channel.create_call(method, &opt)?; let mut payload = GrpcSlice::default(); - (method.req_ser())(req, &mut payload)?; + (method.req_ser())(req, &mut payload); let cq_f = check_run(BatchType::Finish, |ctx, tag| unsafe { grpc_sys::grpcwrap_call_start_server_streaming( call.call, diff --git a/src/call/mod.rs b/src/call/mod.rs index 25174ea..7f1582f 100644 --- a/src/call/mod.rs +++ b/src/call/mod.rs @@ -8,8 +8,8 @@ use std::pin::Pin; use std::sync::Arc; use std::{ptr, slice}; +use crate::cq::CompletionQueue; use crate::grpc_sys::{self, grpc_call, grpc_call_error, grpcwrap_batch_context}; -use crate::{cq::CompletionQueue, Metadata, MetadataBuilder}; use futures::future::Future; use futures::ready; use futures::task::{Context, Poll}; @@ -156,15 +156,10 @@ impl<Req, Resp> Method<Req, Resp> { #[derive(Debug, Clone)] pub struct RpcStatus { /// gRPC status code. `Ok` indicates success, all other values indicate an error. - code: RpcStatusCode, + pub status: RpcStatusCode, - /// error message. - message: String, - - /// Additional details for rich error model. - /// - /// See also https://grpc.io/docs/guides/error/#richer-error-model. - details: Vec<u8>, + /// Optional detail string. + pub details: Option<String>, } impl Display for RpcStatus { @@ -175,54 +170,16 @@ impl Display for RpcStatus { impl RpcStatus { /// Create a new [`RpcStatus`]. - pub fn new<T: Into<RpcStatusCode>>(code: T) -> RpcStatus { - RpcStatus::with_message(code, String::new()) - } - - /// Create a new [`RpcStatus`] with given message. - pub fn with_message<T: Into<RpcStatusCode>>(code: T, message: String) -> RpcStatus { - RpcStatus::with_details(code, message, vec![]) - } - - /// Create a new [`RpcStats`] with code, message and details. - /// - /// If using rich error model, `details` should be binary message that sets `code` and - /// `message` to the same value. Or you can use `into` method to do automatical - /// transformation if using `grpcio_proto::google::rpc::Status`. - pub fn with_details<T: Into<RpcStatusCode>>( - code: T, - message: String, - details: Vec<u8>, - ) -> RpcStatus { + pub fn new<T: Into<RpcStatusCode>>(code: T, details: Option<String>) -> RpcStatus { RpcStatus { - code: code.into(), - message, + status: code.into(), details, } } /// Create a new [`RpcStatus`] that status code is Ok. pub fn ok() -> RpcStatus { - RpcStatus::new(RpcStatusCode::OK) - } - - /// Return the instance's error code. - #[inline] - pub fn code(&self) -> RpcStatusCode { - self.code - } - - /// Return the instance's error message. - #[inline] - pub fn message(&self) -> &str { - &self.message - } - - /// Return the (binary) error details. - /// - /// Usually it contains a serialized `google.rpc.Status` proto. - pub fn details(&self) -> &[u8] { - &self.details + RpcStatus::new(RpcStatusCode::OK, None) } } @@ -259,26 +216,21 @@ impl BatchContext { grpc_sys::grpcwrap_batch_context_recv_status_on_client_status(self.ctx) }); - if status == RpcStatusCode::OK { - RpcStatus::ok() + let details = if status == RpcStatusCode::OK { + None } else { unsafe { - let mut msg_len = 0; + let mut details_len = 0; let details_ptr = grpc_sys::grpcwrap_batch_context_recv_status_on_client_details( self.ctx, - &mut msg_len, + &mut details_len, ); - let msg_slice = slice::from_raw_parts(details_ptr as *const _, msg_len); - let message = String::from_utf8_lossy(msg_slice).into_owned(); - let m_ptr = - grpc_sys::grpcwrap_batch_context_recv_status_on_client_trailing_metadata( - self.ctx, - ); - let metadata = &*(m_ptr as *const Metadata); - let details = metadata.search_binary_error_details().to_vec(); - RpcStatus::with_details(status, message, details) + let details_slice = slice::from_raw_parts(details_ptr as *const _, details_len); + Some(String::from_utf8_lossy(details_slice).into_owned()) } - } + }; + + RpcStatus::new(status, details) } /// Fetch the response bytes of the rpc call. @@ -400,31 +352,22 @@ impl Call { let _cq_ref = self.cq.borrow()?; let send_empty_metadata = if send_empty_metadata { 1 } else { 0 }; let f = check_run(BatchType::Finish, |ctx, tag| unsafe { - let (msg_ptr, msg_len) = if status.code() == RpcStatusCode::OK { - (ptr::null(), 0) - } else { - (status.message.as_ptr(), status.message.len()) - }; + let details_ptr = status + .details + .as_ref() + .map_or_else(ptr::null, |s| s.as_ptr() as _); + let details_len = status.details.as_ref().map_or(0, String::len); let payload_p = match payload { Some(p) => p.as_mut_ptr(), None => ptr::null_mut(), }; - let mut trailing_metadata = if status.details.is_empty() { - None - } else { - let mut builder = MetadataBuilder::new(); - builder.set_binary_error_details(&status.details); - Some(builder.build()) - }; grpc_sys::grpcwrap_call_send_status_from_server( self.call, ctx, - status.code().into(), - msg_ptr as _, - msg_len, - trailing_metadata - .as_mut() - .map_or_else(ptr::null_mut, |m| m as *mut _ as _), + status.status.into(), + details_ptr, + details_len, + ptr::null_mut(), send_empty_metadata, payload_p, write_flags, @@ -447,17 +390,17 @@ impl Call { let (batch_ptr, tag_ptr) = box_batch_tag(tag); let code = unsafe { - let (msg_ptr, msg_len) = if status.code() == RpcStatusCode::OK { - (ptr::null(), 0) - } else { - (status.message.as_ptr(), status.message.len()) - }; + let details_ptr = status + .details + .as_ref() + .map_or_else(ptr::null, |s| s.as_ptr() as _); + let details_len = status.details.as_ref().map_or(0, String::len); grpc_sys::grpcwrap_call_send_status_from_server( call_ptr, batch_ptr, - status.code().into(), - msg_ptr as _, - msg_len, + status.status.into(), + details_ptr, + details_len, ptr::null_mut(), 1, ptr::null_mut(), @@ -717,7 +660,7 @@ impl SinkBase { // temporary fix: buffer hint with send meta will not send out any metadata. // note: only the first message can enter this code block. if self.send_metadata { - ser(t, &mut self.buffer)?; + ser(t, &mut self.buffer); self.buf_flags = Some(flags); self.start_send_buffer_message(false, call)?; self.send_metadata = false; @@ -730,7 +673,7 @@ impl SinkBase { self.start_send_buffer_message(true, call)?; } - ser(t, &mut self.buffer)?; + ser(t, &mut self.buffer); let hint = flags.get_buffer_hint(); self.last_buf_hint &= hint; self.buf_flags = Some(flags); @@ -781,7 +724,7 @@ impl SinkBase { // `start_send` is supposed to be called after `poll_ready` returns ready. assert!(self.batch_f.is_none()); - let mut flags = self.buf_flags.unwrap(); + let mut flags = self.buf_flags.clone().unwrap(); flags = flags.buffer_hint(buffer_hint); let write_f = call.call(|c| { c.call diff --git a/src/call/server.rs b/src/call/server.rs index e762889..0fed656 100644 --- a/src/call/server.rs +++ b/src/call/server.rs @@ -252,7 +252,7 @@ impl UnaryRequestContext { return execute(self.request, cq, reader, handler, checker); } - let status = RpcStatus::with_message(RpcStatusCode::INTERNAL, "No payload".to_owned()); + let status = RpcStatus::new(RpcStatusCode::INTERNAL, Some("No payload".to_owned())); self.request.call(cq.clone()).abort(&status) } } @@ -358,20 +358,11 @@ macro_rules! impl_unary_sink { } fn complete(mut self, status: RpcStatus, t: Option<T>) -> $rt { - let mut data = match t { - Some(t) => { - let mut buf = GrpcSlice::default(); - if let Err(e) = (self.ser)(&t, &mut buf) { - return $rt { - call: self.call.take().unwrap(), - cq_f: None, - err: Some(e), - }; - } - Some(buf) - } - None => None, - }; + let mut data = t.as_ref().map(|t| { + let mut buf = GrpcSlice::default(); + (self.ser)(t, &mut buf); + buf + }); let write_flags = self.write_flags; let res = self.call.as_mut().unwrap().call(|c| { @@ -712,9 +703,9 @@ pub fn execute_unary<P, Q, F>( let request = match de(payload) { Ok(f) => f, Err(e) => { - let status = RpcStatus::with_message( + let status = RpcStatus::new( RpcStatusCode::INTERNAL, - format!("Failed to deserialize response message: {:?}", e), + Some(format!("Failed to deserialize response message: {:?}", e)), ); call.abort(&status); return; @@ -758,9 +749,9 @@ pub fn execute_server_streaming<P, Q, F>( let request = match de(payload) { Ok(t) => t, Err(e) => { - let status = RpcStatus::with_message( + let status = RpcStatus::new( RpcStatusCode::INTERNAL, - format!("Failed to deserialize response message: {:?}", e), + Some(format!("Failed to deserialize response message: {:?}", e)), ); call.abort(&status); return; @@ -795,7 +786,7 @@ pub fn execute_unimplemented(ctx: RequestContext, cq: CompletionQueue) { let ctx = ctx; let mut call = ctx.call(cq); accept_call!(call); - call.abort(&RpcStatus::new(RpcStatusCode::UNIMPLEMENTED)) + call.abort(&RpcStatus::new(RpcStatusCode::UNIMPLEMENTED, None)) } // Helper function to call handler. diff --git a/src/channel.rs b/src/channel.rs index c017f13..c8c67b1 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -31,7 +31,7 @@ pub use crate::grpc_sys::{ /// Ref: http://www.grpc.io/docs/guides/wire.html#user-agents fn format_user_agent_string(agent: &str) -> CString { - let version = "0.9.1"; + let version = "0.8.2"; let trimed_agent = agent.trim(); let val = if trimed_agent.is_empty() { format!("grpc-rust/{}", version) @@ -395,7 +395,6 @@ impl ChannelBuilder { /// Build `ChannelArgs` from the current configuration. #[allow(clippy::useless_conversion)] - #[allow(clippy::cmp_owned)] pub fn build_args(&self) -> ChannelArgs { let args = unsafe { grpc_sys::grpcwrap_channel_args_create(self.options.len()) }; for (i, (k, v)) in self.options.iter().enumerate() { diff --git a/src/codec.rs b/src/codec.rs index 35dfb2e..e0214b7 100644 --- a/src/codec.rs +++ b/src/codec.rs @@ -5,11 +5,7 @@ use crate::call::MessageReader; use crate::error::Result; pub type DeserializeFn<T> = fn(MessageReader) -> Result<T>; -pub type SerializeFn<T> = fn(&T, &mut GrpcSlice) -> Result<()>; - -/// According to https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md, grpc uses -/// a four bytes to describe the length of a message, so it should not exceed u32::MAX. -pub const MAX_MESSAGE_SIZE: usize = std::u32::MAX as usize; +pub type SerializeFn<T> = fn(&T, &mut GrpcSlice); /// Defines how to serialize and deserialize between the specialized type and byte slice. pub struct Marshaller<T> { @@ -33,25 +29,18 @@ pub struct Marshaller<T> { pub mod pb_codec { use protobuf::{CodedInputStream, CodedOutputStream, Message}; - use super::{MessageReader, MAX_MESSAGE_SIZE}; + use super::MessageReader; use crate::buf::GrpcSlice; - use crate::error::{Error, Result}; + use crate::error::Result; #[inline] - pub fn ser<T: Message>(t: &T, buf: &mut GrpcSlice) -> Result<()> { - let cap = t.compute_size() as usize; - // FIXME: This is not a practical fix until stepancheg/rust-protobuf#530 is fixed. - if cap <= MAX_MESSAGE_SIZE { - unsafe { - let bytes = buf.realloc(cap); - let raw_bytes = &mut *(bytes as *mut [std::mem::MaybeUninit<u8>] as *mut [u8]); - let mut s = CodedOutputStream::bytes(raw_bytes); - t.write_to_with_cached_sizes(&mut s).map_err(Into::into) - } - } else { - Err(Error::Codec( - format!("message is too large: {} > {}", cap, MAX_MESSAGE_SIZE).into(), - )) + pub fn ser<T: Message>(t: &T, buf: &mut GrpcSlice) { + let cap = t.compute_size(); + unsafe { + let bytes = buf.realloc(cap as usize); + let raw_bytes = &mut *(bytes as *mut [std::mem::MaybeUninit<u8>] as *mut [u8]); + let mut s = CodedOutputStream::bytes(raw_bytes); + t.write_to_with_cached_sizes(&mut s).unwrap(); } } @@ -68,25 +57,19 @@ pub mod pb_codec { pub mod pr_codec { use prost::Message; - use super::{MessageReader, MAX_MESSAGE_SIZE}; + use super::MessageReader; use crate::buf::GrpcSlice; - use crate::error::{Error, Result}; + use crate::error::Result; #[inline] - pub fn ser<M: Message>(msg: &M, buf: &mut GrpcSlice) -> Result<()> { + pub fn ser<M: Message>(msg: &M, buf: &mut GrpcSlice) { let size = msg.encoded_len(); - if size <= MAX_MESSAGE_SIZE { - unsafe { - let bytes = buf.realloc(size); - let mut b = &mut *(bytes as *mut [std::mem::MaybeUninit<u8>] as *mut [u8]); - msg.encode(&mut b)?; - debug_assert!(b.is_empty()); - } - Ok(()) - } else { - Err(Error::Codec( - format!("message is too large: {} > {}", size, MAX_MESSAGE_SIZE).into(), - )) + unsafe { + let bytes = buf.realloc(size); + let mut b = &mut *(bytes as *mut [std::mem::MaybeUninit<u8>] as *mut [u8]); + msg.encode(&mut b) + .expect("Writing message to buffer failed"); + debug_assert!(b.is_empty()); } } diff --git a/src/error.rs b/src/error.rs index 2d65eb2..f12ffa4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,6 +5,8 @@ use std::{error, fmt, result}; use crate::call::RpcStatus; use crate::grpc_sys::grpc_call_error; +#[cfg(feature = "prost-codec")] +use prost::DecodeError; #[cfg(feature = "protobuf-codec")] use protobuf::ProtobufError; @@ -36,13 +38,10 @@ pub enum Error { impl fmt::Display for Error { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Error::RpcFailure(s) => { - if s.message().is_empty() { - write!(fmt, "RpcFailure: {}", s.code()) - } else { - write!(fmt, "RpcFailure: {} {}", s.code(), s.message()) - } - } + Error::RpcFailure(RpcStatus { status, details }) => match details { + Some(details) => write!(fmt, "RpcFailure: {} {}", status, details), + None => write!(fmt, "RpcFailure: {}", status), + }, other_error => write!(fmt, "{:?}", other_error), } } @@ -65,15 +64,8 @@ impl From<ProtobufError> for Error { } #[cfg(feature = "prost-codec")] -impl From<prost::DecodeError> for Error { - fn from(e: prost::DecodeError) -> Error { - Error::Codec(Box::new(e)) - } -} - -#[cfg(feature = "prost-codec")] -impl From<prost::EncodeError> for Error { - fn from(e: prost::EncodeError) -> Error { +impl From<DecodeError> for Error { + fn from(e: DecodeError) -> Error { Error::Codec(Box::new(e)) } } @@ -66,7 +66,7 @@ pub use crate::codec::pb_codec::{de as pb_de, ser as pb_ser}; pub use crate::codec::pr_codec::{de as pr_de, ser as pr_ser}; pub use crate::auth_context::{AuthContext, AuthProperty, AuthPropertyIter}; -pub use crate::codec::{Marshaller, MAX_MESSAGE_SIZE}; +pub use crate::codec::Marshaller; pub use crate::env::{EnvBuilder, Environment}; pub use crate::error::{Error, Result}; pub use crate::log_util::redirect_log; @@ -80,24 +80,3 @@ pub use crate::security::{ pub use crate::server::{ CheckResult, Server, ServerBuilder, ServerChecker, Service, ServiceBuilder, ShutdownFuture, }; - -/// A shortcut for implementing a service method by returning `UNIMPLEMENTED` status code. -/// -/// Compiler will provide a default implementations for all methods to invoke this macro, so -/// you usually won't call it directly. If you really need to, just call it like: -/// ```ignored -/// fn method(&self, ctx: grpcio::RpcContext, req: Request, resp: UnarySink<Response>) { -/// unimplemented_call!(ctx, resp); -/// } -/// ``` -#[macro_export] -macro_rules! unimplemented_call { - ($ctx:ident, $sink:ident) => {{ - let f = async move { - let _ = $sink - .fail($crate::RpcStatus::new($crate::RpcStatusCode::UNIMPLEMENTED)) - .await; - }; - $ctx.spawn(f) - }}; -} diff --git a/src/metadata.rs b/src/metadata.rs index caaebc8..893f6e2 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -7,8 +7,6 @@ use std::{mem, slice, str}; use crate::error::{Error, Result}; -const BINARY_ERROR_DETAILS_KEY: &str = "grpc-status-details-bin"; - fn normalize_key(key: &str, binary: bool) -> Result<Cow<'_, str>> { if key.is_empty() { return Err(Error::InvalidMetadata( @@ -109,13 +107,6 @@ impl MetadataBuilder { Ok(self.add_metadata(&key, value)) } - /// Set binary error details to support rich error model. - /// - /// See also https://grpc.io/docs/guides/error/#richer-error-model. - pub(crate) fn set_binary_error_details(&mut self, value: &[u8]) -> &mut MetadataBuilder { - self.add_metadata(BINARY_ERROR_DETAILS_KEY, value) - } - /// Create `Metadata` with configured entries. pub fn build(mut self) -> Metadata { unsafe { @@ -223,16 +214,6 @@ impl Metadata { metadata: p, }) } - - /// Search for binary error details. - pub(crate) fn search_binary_error_details(&self) -> &[u8] { - for (k, v) in self.iter() { - if k == BINARY_ERROR_DETAILS_KEY { - return v; - } - } - &[] - } } impl Clone for Metadata { diff --git a/src/server.rs b/src/server.rs index f2150a0..a612b13 100644 --- a/src/server.rs +++ b/src/server.rs @@ -68,7 +68,7 @@ where /// Given a host and port, creates a string of the form "host:port" or /// "[host]:port", depending on whether the host is an IPv6 literal. fn join_host_port(host: &str, port: u16) -> String { - if host.starts_with("unix:") | host.starts_with("unix-abstract:") { + if host.starts_with("unix:") { format!("{}\0", host) } else if let Ok(ip) = host.parse::<IpAddr>() { format!("{}\0", SocketAddr::new(ip, port)) @@ -88,8 +88,6 @@ mod imp { pub host: String, pub port: u16, cred: Option<ServerCredentials>, - // Double allocation to get around C call. - #[allow(clippy::redundant_allocation)] _fetcher: Option<Box<Box<dyn ServerCredentialsFetcher + Send + Sync>>>, } @@ -104,7 +102,6 @@ mod imp { } } - #[allow(clippy::redundant_allocation)] pub fn with_cred( host: String, port: u16, diff --git a/src/task/promise.rs b/src/task/promise.rs index 2d826d4..50add06 100644 --- a/src/task/promise.rs +++ b/src/task/promise.rs @@ -57,7 +57,7 @@ impl Batch { let mut guard = self.inner.lock(); if succeed { let status = self.ctx.rpc_status(); - if status.code() == RpcStatusCode::OK { + if status.status == RpcStatusCode::OK { guard.set_result(Ok(None)) } else { guard.set_result(Err(Error::RpcFailure(status))) @@ -73,7 +73,7 @@ impl Batch { let task = { let mut guard = self.inner.lock(); let status = self.ctx.rpc_status(); - if status.code() == RpcStatusCode::OK { + if status.status == RpcStatusCode::OK { guard.set_result(Ok(self.ctx.recv_message())) } else { guard.set_result(Err(Error::RpcFailure(status))) |