From 09d6862015f1564d04bf9143c1f922f0fb8cb63d Mon Sep 17 00:00:00 2001
From: Marius van Niekerk <marius.v.niekerk@gmail.com>
Date: Mon, 13 Jun 2022 17:13:07 -0400
Subject: [PATCH 3/6] Link against grpc

---
 setup.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/setup.py b/setup.py
index f5aa42ffe1..63847a7781 100644
--- a/setup.py
+++ b/setup.py
@@ -170,6 +170,8 @@ BUILD_WITH_SYSTEM_ABSL = os.environ.get('GRPC_PYTHON_BUILD_SYSTEM_ABSL', False)
 BUILD_WITH_STATIC_LIBSTDCXX = _env_bool_value(
     'GRPC_PYTHON_BUILD_WITH_STATIC_LIBSTDCXX', 'False')
 
+BUILD_WITH_SYSTEM_GRPC_CORE = _env_bool_value('GRPC_PYTHON_BUILD_SYSTEM_GRPC_CORE', 'False')
+
 # For local development use only: This skips building gRPC Core and its
 # dependencies, including protobuf and boringssl. This allows "incremental"
 # compilation by first building gRPC Core using make, then building only the
@@ -340,6 +342,11 @@ if BUILD_WITH_SYSTEM_RE2:
 if BUILD_WITH_SYSTEM_ABSL:
     EXTENSION_LIBRARIES += tuple(
         lib.stem[3:] for lib in pathlib.Path('/usr').glob('lib*/libabsl_*.so'))
+if BUILD_WITH_SYSTEM_GRPC_CORE:
+    EXTENSION_LIBRARIES += ('gpr', 'grpc', )
+    if "win32" in sys.platform:
+        EXTENSION_LIBRARIES += ('libprotoc', 'libprotobuf', 'libprotobuf-lite', 'upb', 'address_sorting', )
+        EXTENSION_LIBRARIES += tuple(lib.stem for lib in pathlib.Path(os.environ['LIBRARY_LIB']).glob('absl_*.lib'))
 
 DEFINE_MACROS = (('_WIN32_WINNT', 0x600),)
 asm_files = []
@@ -446,6 +453,9 @@ def cython_extensions_and_necessity():
             prefix + 'libgpr.a', prefix + 'libgrpc.a'
         ]
         core_c_files = []
+    elif BUILD_WITH_SYSTEM_GRPC_CORE:
+        core_c_files = []
+        extra_objects = []
     else:
         core_c_files = list(CORE_C_FILES)
         extra_objects = []
-- 
2.38.1.windows.1

