Skip to content

Commit

Permalink
Upgrade gRPC C library (digital-asset#8693)
Browse files Browse the repository at this point in the history
We can’t upgrade to the latest version 1.35.0 since it depends on a
newer version of Bazel but we can at least go to 1.34.1. We also have
to patch absl and grpc itself to fix mingw support and some undeclared
inclusions on Windows. Both patches are taken from upstream PRs (the
mingw one has not been merged yet).

There is also a small patch to grpc-haskell-core. I’ve started working
on upstreaming that but the nix build system is a mess and I haven’t
quite managed to get it working there.

changelog_begin
changelog_end
  • Loading branch information
cocreature authored Feb 1, 2021
1 parent 7cf1914 commit afb2006
Show file tree
Hide file tree
Showing 7 changed files with 509 additions and 83 deletions.
15 changes: 9 additions & 6 deletions bazel-haskell-deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ JS_DGTABLE_VERSION = "0.5.2"
JS_FLOT_VERSION = "0.8.3"
SHAKE_VERSION = "0.18.5"
ZIP_VERSION = "1.5.0"
GRPC_HASKELL_REV = "641f0bab046f2f03e5350a7c5f2044af1e19a5b1"
GRPC_HASKELL_SHA256 = "d850d804d7af779bb8717ebe4ea2ac74903a30adeb5262477a2e7a1536f4ca81"

def daml_haskell_deps():
"""Load all Haskell dependencies of the DAML repository."""
Expand Down Expand Up @@ -174,10 +176,11 @@ cc_library(
patch_args = ["-p1"],
patches = [
"@com_github_digital_asset_daml//bazel_tools:grpc-haskell-core-cpp-options.patch",
"@com_github_digital_asset_daml//bazel_tools:grpc-haskell-core-upgrade.patch",
],
sha256 = "531bbd4df2eca160be436074ade336a70cad3a6477df8d00d479440edfe9896b",
strip_prefix = "gRPC-haskell-0cb7999e9e89d0c17c5e1d917e97cc6e450b9346/core",
urls = ["https://github.com/awakesecurity/gRPC-haskell/archive/0cb7999e9e89d0c17c5e1d917e97cc6e450b9346.tar.gz"],
sha256 = GRPC_HASKELL_SHA256,
strip_prefix = "gRPC-haskell-{}/core".format(GRPC_HASKELL_REV),
urls = ["https://github.com/awakesecurity/gRPC-haskell/archive/{}.tar.gz".format(GRPC_HASKELL_REV)],
)

http_archive(
Expand All @@ -192,9 +195,9 @@ haskell_library(
visibility = ["//visibility:public"],
)
""",
sha256 = "531bbd4df2eca160be436074ade336a70cad3a6477df8d00d479440edfe9896b",
strip_prefix = "gRPC-haskell-0cb7999e9e89d0c17c5e1d917e97cc6e450b9346",
urls = ["https://github.com/awakesecurity/gRPC-haskell/archive/0cb7999e9e89d0c17c5e1d917e97cc6e450b9346.tar.gz"],
sha256 = GRPC_HASKELL_SHA256,
strip_prefix = "gRPC-haskell-{}".format(GRPC_HASKELL_REV),
urls = ["https://github.com/awakesecurity/gRPC-haskell/archive/{}.tar.gz".format(GRPC_HASKELL_REV)],
)

http_archive(
Expand Down
183 changes: 183 additions & 0 deletions bazel_tools/absl-mingw.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
Taken from https://github.com/abseil/abseil-cpp/pull/884

From 8ef49c10f419ff8e6e3865c06ea6dfe36be642ff Mon Sep 17 00:00:00 2001
From: Pascal Muetschard <pmuetschard@google.com>
Date: Mon, 11 Jan 2021 15:17:06 -0800
Subject: [PATCH] Don't assume Windows means MSVC in the bazel BUILD files.

When selecting the compiler flags, use the compiler setting, rather than
the platform setting, to detect if MSVC flags are required.
---
absl/BUILD.bazel | 24 ++++++++++++++++++++++++
absl/base/BUILD.bazel | 4 ++--
absl/copts/configure_copts.bzl | 6 +++---
absl/debugging/BUILD.bazel | 8 ++++----
absl/random/internal/BUILD.bazel | 6 +++---
absl/synchronization/BUILD.bazel | 2 +-
6 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/absl/BUILD.bazel b/absl/BUILD.bazel
index 0b772df..651b3f4 100644
--- a/absl/BUILD.bazel
+++ b/absl/BUILD.bazel
@@ -28,6 +28,30 @@ create_llvm_config(
visibility = [":__subpackages__"],
)

+config_setting(
+ name = "msvc_compiler",
+ flag_values = {
+ "@bazel_tools//tools/cpp:compiler": "msvc-cl",
+ },
+ visibility = [":__subpackages__"],
+)
+
+config_setting(
+ name = "clang_cl_compiler",
+ flag_values = {
+ "@bazel_tools//tools/cpp:compiler": "clang-cl",
+ },
+ visibility = [":__subpackages__"],
+)
+
+alias(
+ name = "msvc_compat_compiler",
+ actual = select({
+ ":clang_cl_compiler": ":clang_cl_compiler",
+ "//conditions:default": ":msvc_compiler",
+ })
+)
+
config_setting(
name = "osx",
constraint_values = [
diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel
index 9d96abe..817c06a 100644
--- a/absl/base/BUILD.bazel
+++ b/absl/base/BUILD.bazel
@@ -160,7 +160,7 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
- "//absl:windows": [],
+ "//absl:msvc_compat_compiler": [],
"//absl:wasm": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
@@ -220,7 +220,7 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
- "//absl:windows": [
+ "//absl:msvc_compat_compiler": [
"-DEFAULTLIB:advapi32.lib",
],
"//absl:wasm": [],
diff --git a/absl/copts/configure_copts.bzl b/absl/copts/configure_copts.bzl
index ff9a5ea..5d00332 100644
--- a/absl/copts/configure_copts.bzl
+++ b/absl/copts/configure_copts.bzl
@@ -22,7 +22,7 @@ load(
)

ABSL_DEFAULT_COPTS = select({
- "//absl:windows": ABSL_MSVC_FLAGS,
+ "//absl:msvc_compat_compiler": ABSL_MSVC_FLAGS,
"//absl:llvm_compiler": ABSL_LLVM_FLAGS,
"//conditions:default": ABSL_GCC_FLAGS,
})
@@ -30,13 +30,13 @@ ABSL_DEFAULT_COPTS = select({
# in absence of modules (--compiler=gcc or -c opt), cc_tests leak their copts
# to their (included header) dependencies and fail to build outside absl
ABSL_TEST_COPTS = ABSL_DEFAULT_COPTS + select({
- "//absl:windows": ABSL_MSVC_TEST_FLAGS,
+ "//absl:msvc_compat_compiler": ABSL_MSVC_TEST_FLAGS,
"//absl:llvm_compiler": ABSL_LLVM_TEST_FLAGS,
"//conditions:default": ABSL_GCC_TEST_FLAGS,
})

ABSL_DEFAULT_LINKOPTS = select({
- "//absl:windows": ABSL_MSVC_LINKOPTS,
+ "//absl:msvc_compat_compiler": ABSL_MSVC_LINKOPTS,
"//conditions:default": [],
})

diff --git a/absl/debugging/BUILD.bazel b/absl/debugging/BUILD.bazel
index 86faac9..d0984b9 100644
--- a/absl/debugging/BUILD.bazel
+++ b/absl/debugging/BUILD.bazel
@@ -66,7 +66,7 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS + select({
- "//absl:windows": ["-DEFAULTLIB:dbghelp.lib"],
+ "//absl:msvc_compat_compiler": ["-DEFAULTLIB:dbghelp.lib"],
"//conditions:default": [],
}),
deps = [
@@ -86,11 +86,11 @@ cc_test(
name = "symbolize_test",
srcs = ["symbolize_test.cc"],
copts = ABSL_TEST_COPTS + select({
- "//absl:windows": ["/Z7"],
+ "//absl:msvc_compat_compiler": ["/Z7"],
"//conditions:default": [],
}),
linkopts = ABSL_DEFAULT_LINKOPTS + select({
- "//absl:windows": ["/DEBUG"],
+ "//absl:msvc_compat_compiler": ["/DEBUG"],
"//conditions:default": [],
}),
deps = [
@@ -148,7 +148,7 @@ cc_test(
srcs = ["failure_signal_handler_test.cc"],
copts = ABSL_TEST_COPTS,
linkopts = select({
- "//absl:windows": [],
+ "//absl:msvc_compat_compiler": [],
"//absl:wasm": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
diff --git a/absl/random/internal/BUILD.bazel b/absl/random/internal/BUILD.bazel
index 8485e28..944f512 100644
--- a/absl/random/internal/BUILD.bazel
+++ b/absl/random/internal/BUILD.bazel
@@ -75,7 +75,7 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS + select({
- "//absl:windows": ["-DEFAULTLIB:bcrypt.lib"],
+ "//absl:msvc_compat_compiler": ["-DEFAULTLIB:bcrypt.lib"],
"//conditions:default": [],
}),
deps = [
@@ -98,7 +98,7 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
- "//absl:windows": [],
+ "//absl:msvc_compat_compiler": [],
"//absl:wasm": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
@@ -320,7 +320,7 @@ cc_library(
"randen_hwaes.h",
],
copts = ABSL_DEFAULT_COPTS + ABSL_RANDOM_RANDEN_COPTS + select({
- "//absl:windows": [],
+ "//absl:msvc_compat_compiler": [],
"//conditions:default": ["-Wno-pass-failed"],
}),
linkopts = ABSL_DEFAULT_LINKOPTS,
diff --git a/absl/synchronization/BUILD.bazel b/absl/synchronization/BUILD.bazel
index 4d4d680..b75bb42 100644
--- a/absl/synchronization/BUILD.bazel
+++ b/absl/synchronization/BUILD.bazel
@@ -89,7 +89,7 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
- "//absl:windows": [],
+ "//absl:msvc_compat_compiler": [],
"//absl:wasm": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
12 changes: 6 additions & 6 deletions bazel_tools/grpc-bazel-mingw.patch
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h
index 0349e31bb3..d2e7408dbf 100644
index c1bada11df..ab2888f82d 100644
--- a/include/grpc/impl/codegen/port_platform.h
+++ b/include/grpc/impl/codegen/port_platform.h
@@ -39,15 +39,9 @@
#define NOMINMAX
#endif /* NOMINMAX */
@@ -53,15 +53,9 @@

#include <windows.h>

-#ifndef _WIN32_WINNT
-#error \
Expand All @@ -19,5 +19,5 @@ index 0349e31bb3..d2e7408dbf 100644
+#define WINVER 0x0A00
+#define _WIN32_WINNT 0x0A00

#include <windows.h>

#ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
#undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED
66 changes: 0 additions & 66 deletions bazel_tools/grpc-gettid.patch

This file was deleted.

70 changes: 70 additions & 0 deletions bazel_tools/grpc-haskell-core-upgrade.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
diff --git a/cbits/grpc_haskell.c b/cbits/grpc_haskell.c
index ebbcbb1..236c73e 100644
--- a/cbits/grpc_haskell.c
+++ b/cbits/grpc_haskell.c
@@ -504,8 +504,7 @@ grpc_auth_metadata_processor* mk_auth_metadata_processor(

grpc_call_credentials* grpc_metadata_credentials_create_from_plugin_(
grpc_metadata_credentials_plugin* plugin){
-
- return grpc_metadata_credentials_create_from_plugin(*plugin, NULL);
+ return grpc_metadata_credentials_create_from_plugin(*plugin, GRPC_PRIVACY_AND_INTEGRITY, NULL);
}

//This is a hack to work around GHC being unable to deal with raw struct params.
diff --git a/src/Network/GRPC/Unsafe.chs b/src/Network/GRPC/Unsafe.chs
index d11f533..6eb08b8 100644
--- a/src/Network/GRPC/Unsafe.chs
+++ b/src/Network/GRPC/Unsafe.chs
@@ -219,9 +219,6 @@ castPeek p = do
unTag `Tag'}
-> `()'#}

-{#fun grpc_channel_ping as ^
- {`Channel', `CompletionQueue', unTag `Tag',unReserved `Reserved'} -> `()' #}
-
{#fun grpc_channel_destroy as ^ {`Channel'} -> `()'#}

-- | Starts executing a batch of ops in the given 'OpArray'. Does not block.
diff --git a/tests/LowLevelTests/Op.hs b/tests/LowLevelTests/Op.hs
index 52b6d55..ff0751a 100644
--- a/tests/LowLevelTests/Op.hs
+++ b/tests/LowLevelTests/Op.hs
@@ -4,6 +4,9 @@

module LowLevelTests.Op where

+import Control.Concurrent
+import Control.Exception
+import Control.Monad
import Data.ByteString (ByteString)
import Test.Tasty
import Test.Tasty.HUnit as HU (testCase, (@?=))
@@ -47,14 +50,20 @@ withClientServerUnaryCall :: GRPC
withClientServerUnaryCall grpc f = do
withClient grpc clientConf $ \c -> do
crm <- clientRegisterMethodNormal c "/foo"
- withServer grpc serverConf $ \s ->
- withClientCall c crm 10 $ \cc -> do
+ withServer grpc serverConf $ \s -> do
+ ccVar <- newEmptyMVar
+ bracket newEmptyMVar (\v -> putMVar v ()) $ \finished -> do
+ _ <- forkIO $ void $ withClientCall c crm 10 $ \cc -> do
+ putMVar ccVar cc
+ -- NOTE: We need to send client ops here or else `withServerCall` hangs,
+ -- because registered methods try to do recv ops immediately when
+ -- created. If later we want to send payloads or metadata, we'll need
+ -- to tweak this.
+ _clientRes <- runOps (unsafeCC cc) (clientCQ c) clientEmptySendOps
+ takeMVar finished
+ pure (Right ())
let srm = head (normalMethods s)
- -- NOTE: We need to send client ops here or else `withServerCall` hangs,
- -- because registered methods try to do recv ops immediately when
- -- created. If later we want to send payloads or metadata, we'll need
- -- to tweak this.
- _clientRes <- runOps (unsafeCC cc) (clientCQ c) clientEmptySendOps
+ cc <- takeMVar ccVar
withServerCall s srm $ \sc ->
f (c, s, cc, sc)

Loading

0 comments on commit afb2006

Please sign in to comment.