From 4ded40e46872f114db446fdb32d3a7c8fce0d9e5 Mon Sep 17 00:00:00 2001 From: Cerek Hillen Date: Mon, 7 Jun 2021 21:05:35 -0400 Subject: [PATCH] python: hide symbols except for PyInit on macOS (#1506) Description: This PR modifies the build recipe for `envoy_engine.so` to hide all symbols except for `_PyInit_envoy_engine` by default on maOS, so that envoy_engine can be loaded alongside a [protobuf](http://pypi.org/project/protobuf) wheel without breaking. Loading in protobuf alongside `envoy_engine.so` would register two sets of the same symbols and, on macOS, the runtime linker chooses the first symbol it finds causing problems. See the [similar protobuf change](https://github.com/protocolbuffers/protobuf/pull/8346) and its [sister change in grpc](https://github.com/grpc/grpc/pull/24992) for more information on what's going on. Risk Level: Low Testing: See the now-closed #1504 for how I've been testing this. Docs Changes: N/A Release Notes: N/A Signed-off-by: Cerek Hillen --- library/python/BUILD | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/python/BUILD b/library/python/BUILD index 1459e2c1f5..c3dc79c74c 100644 --- a/library/python/BUILD +++ b/library/python/BUILD @@ -31,6 +31,10 @@ pybind_extension( srcs = [ "module_definition.cc", ], + linkopts = select({ + "//bazel:darwin": ["-Wl,-exported_symbol,_PyInit_envoy_engine"], + "//conditions:default": [], + }), visibility = ["//visibility:public"], deps = [ ":envoy_engine_lib",