Skip to content

Commit

Permalink
[Build] Added ws2_32 to address_sorting (grpc#38648)
Browse files Browse the repository at this point in the history
Fix missing windows symbol linker errors found when adding gRPC to BCR (From bazelbuild/bazel-central-registry#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 grpc#38648

PiperOrigin-RevId: 721549737
  • Loading branch information
veblush committed Jan 31, 2025
1 parent 14f7f8c commit 2f8f0ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions third_party/address_sorting/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ address_sorting_cc_library(
includes = [
"include",
],
linkopts = select({
"@platforms//os:windows": ["-defaultlib:ws2_32.lib"],
"//conditions:default": [],
}),
)
3 changes: 2 additions & 1 deletion third_party/address_sorting/address_sorting.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit 2f8f0ea

Please sign in to comment.