aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoo Rong Jie <loorongjie@gmail.com>2018-06-06 10:03:25 +0800
committerFeng Xiao <xfxyjwf@gmail.com>2018-06-05 19:03:24 -0700
commit0456e269ee6505766474aa8d7b8bba7ac047f457 (patch)
tree50c470c72262b77cec8cd3aa404a282d987df267
parent6933e2f499b8c2b3a318cc4dbceb83b88ab39b0e (diff)
downloadprotobuf-0456e269ee6505766474aa8d7b8bba7ac047f457.tar.gz
protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457.tar.bz2
protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457.zip
Align Bazel on Windows with CMake's MSVC flags (#4720)
* Align Bazel on Windows with CMake's MSVC flags
-rw-r--r--BUILD46
1 files changed, 34 insertions, 12 deletions
diff --git a/BUILD b/BUILD
index c4b517cf..de87df4a 100644
--- a/BUILD
+++ b/BUILD
@@ -22,7 +22,20 @@ config_setting(
MSVC_COPTS = [
"/DHAVE_PTHREAD",
"/wd4018", # -Wno-sign-compare
+ "/wd4065", # switch statement contains 'default' but no 'case' labels
+ "/wd4146", # unary minus operator applied to unsigned type, result still unsigned
+ "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
+ "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
+ "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data
+ "/wd4305", # 'identifier' : truncation from 'type1' to 'type2'
+ "/wd4307", # 'operator' : integral constant overflow
+ "/wd4309", # 'conversion' : truncation of constant value
+ "/wd4334", # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
+ "/wd4355", # 'this' : used in base member initializer list
+ "/wd4506", # no definition for inline function 'function'
"/wd4514", # -Wno-unused-function
+ "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning)
+ "/wd4996", # The compiler encountered a deprecated declaration.
]
COPTS = select({
@@ -55,17 +68,8 @@ config_setting(
LINK_OPTS = select({
":android": [],
":msvc": [
- # Linking to setargv.obj makes the default command line argument
- # parser expand wildcards, so the main method's argv will contain the
- # expanded list instead of the wildcards.
- # Using -WHOLEARCHIVE, because:
- # - Microsoft ships this object file next to default libraries
- # - but this file is not a library, just a precompiled object
- # - just listing the name here without "-WHOLEARCHIVE:" would make Bazel
- # believe that "setargv.obj" is a source or rule output in this
- # package, which it is not.
- # See https://msdn.microsoft.com/en-us/library/8bch7bkk.aspx
- "-WHOLEARCHIVE:setargv.obj",
+ # Suppress linker warnings about files with no symbols defined.
+ "-ignore:4221",
],
"//conditions:default": ["-lpthread", "-lm"],
})
@@ -359,7 +363,25 @@ cc_library(
],
copts = COPTS,
includes = ["src/"],
- linkopts = LINK_OPTS,
+ linkopts = LINK_OPTS + select({
+ ":msvc": [
+ # Linking to setargv.obj makes the default command line argument
+ # parser expand wildcards, so the main method's argv will contain the
+ # expanded list instead of the wildcards.
+ #
+ # Adding dummy "-DEFAULTLIB:kernel32.lib", because:
+ # - Microsoft ships this object file next to default libraries
+ # - but this file is not a library, just a precompiled object
+ # - "-WHOLEARCHIVE" and "-DEFAULTLIB" only accept library,
+ # not precompiled object.
+ # - Bazel would assume linkopt that does not start with "-" or "$"
+ # as a label to a target, so we add a harmless "-DEFAULTLIB:kernel32.lib"
+ # before "setargv.obj".
+ # See https://msdn.microsoft.com/en-us/library/8bch7bkk.aspx
+ "-DEFAULTLIB:kernel32.lib setargv.obj",
+ ],
+ "//conditions:default": [],
+ }),
visibility = ["//visibility:public"],
deps = [":protobuf"],
)