Selaa lähdekoodia

Align Bazel on Windows with CMake's MSVC flags (#4720)

* Align Bazel on Windows with CMake's MSVC flags
Loo Rong Jie 7 vuotta sitten
vanhempi
commit
0456e269ee
1 muutettua tiedostoa jossa 34 lisäystä ja 12 poistoa
  1. 34 12
      BUILD

+ 34 - 12
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"],
 )