From 2f8f0ea8451a772811f3dc4da275129c89a6a9df Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Thu, 30 Jan 2025 16:02:48 -0800 Subject: [PATCH] [Build] Added ws2_32 to address_sorting (#38648) Fix missing windows symbol linker errors found when adding gRPC to BCR (From https://github.com/bazelbuild/bazel-central-registry/pull/3671). ``` C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64\link.exe @bazel-out/x64_windows-fastbuild/bin/external/grpc+/third_party/address_sorting/address_sorting_6658ee4b.dll-0.params # Configuration: 5b453b61a931a5d60d186b4b1192045ad0e097a738f75edb2ec811e836145bd1 # Execution platform: @@platforms//host:host Creating library bazel-out/x64_windows-fastbuild/bin/external/grpc+/third_party/address_sorting/address_sorting.if.lib and object bazel-out/x64_windows-fastbuild/bin/external/grpc+/third_party/address_sorting/address_sorting.if.exp address_sorting.obj : error LNK2019: unresolved external symbol __imp_htonl referenced in function in6_is_addr_loopback address_sorting_windows.obj : error LNK2019: unresolved external symbol __imp_closesocket referenced in function address_sorting_create_source_addr_factory_for_current_platform address_sorting_windows.obj : error LNK2019: unresolved external symbol __imp_connect referenced in function address_sorting_create_source_addr_factory_for_current_platform address_sorting_windows.obj : error LNK2019: unresolved external symbol __imp_getsockname referenced in function address_sorting_create_source_addr_factory_for_current_platform address_sorting_windows.obj : error LNK2019: unresolved external symbol __imp_socket referenced in function address_sorting_create_source_addr_factory_for_current_platform bazel-out\x64_windows-fastbuild\bin\external\grpc+\third_party\address_sorting\address_sorting_6658ee4b.dll : fatal error LNK1120: 5 unresolved externals ``` This issue wasn't caught by out CI, likely due to BCR presubmit's use of stricter layering_check. Regardless, it's good as it correctly defines the `address_sorting` Bazel target's dependency. Closes #38648 PiperOrigin-RevId: 721549737 --- third_party/address_sorting/BUILD | 4 ++++ third_party/address_sorting/address_sorting.bzl | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/third_party/address_sorting/BUILD b/third_party/address_sorting/BUILD index c3f4922205510..2f4f6b7fd1a9c 100644 --- a/third_party/address_sorting/BUILD +++ b/third_party/address_sorting/BUILD @@ -57,4 +57,8 @@ address_sorting_cc_library( includes = [ "include", ], + linkopts = select({ + "@platforms//os:windows": ["-defaultlib:ws2_32.lib"], + "//conditions:default": [], + }), ) diff --git a/third_party/address_sorting/address_sorting.bzl b/third_party/address_sorting/address_sorting.bzl index 8010025ecd383..05b4c6d847bd7 100644 --- a/third_party/address_sorting/address_sorting.bzl +++ b/third_party/address_sorting/address_sorting.bzl @@ -28,11 +28,12 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. -def address_sorting_cc_library(name, srcs, hdrs, copts, includes): +def address_sorting_cc_library(name, srcs, hdrs, copts, includes, linkopts=[]): native.cc_library( name = name, srcs = srcs, hdrs = hdrs, copts = copts, includes = includes, + linkopts = linkopts, )