Skip to content

Commit

Permalink
Merge pull request #10025 from haberman/fix-windows-protoc
Browse files Browse the repository at this point in the history
Fixed the Windows build of protoc by statically linking deps.
  • Loading branch information
haberman authored May 23, 2022
2 parents 6d2827b + 2dc7679 commit 0b2cee6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@rules_python//python:defs.bzl", "py_library")
load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS")
load(
":protobuf.bzl",
"adapt_proto_library",
Expand Down Expand Up @@ -442,7 +442,7 @@ cc_library(
cc_binary(
name = "protoc",
srcs = ["src/google/protobuf/compiler/main.cc"],
linkopts = LINK_OPTS,
linkopts = LINK_OPTS + PROTOC_LINK_OPTS,
visibility = ["//visibility:public"],
deps = [":protoc_lib"],
)
Expand Down
14 changes: 14 additions & 0 deletions build_defs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ config_setting(
},
)

config_setting(
name = "config_win32",
values = {
"cpu": "win32",
},
)

config_setting(
name = "config_win64",
values = {
"cpu": "win64",
},
)

# Internal testing:

starlark_cc_proto_library(
Expand Down
7 changes: 7 additions & 0 deletions build_defs/cpp_opts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ LINK_OPTS = select({
"-lm",
],
})

# When cross-compiling for Windows we need to statically link pthread and the C++ library.
PROTOC_LINK_OPTS = select({
"//build_defs:config_win32": ["-static"],
"//build_defs:config_win64": ["-static"],
"//conditions:default": [],
})

0 comments on commit 0b2cee6

Please sign in to comment.