From c9f9edf6d75bb065fa47468bf035e051a57bec7c Mon Sep 17 00:00:00 2001 From: Richard O'Grady Date: Fri, 14 Apr 2023 16:49:56 -0700 Subject: [PATCH] Fixes for Windows bazel build. Don't pass -Wno-sign-compare on Windows. Add a #define HAVE_WINDOWS_H if _WIN32 is defined. Don't assume sys/uio.h is available on Windows. PiperOrigin-RevId: 524416809 --- opensource/.bazelrc => .bazelrc | 0 opensource/BUILD.bazel => BUILD.bazel | 19 +++++++++++++++---- opensource/WORKSPACE => WORKSPACE | 0 3 files changed, 15 insertions(+), 4 deletions(-) rename opensource/.bazelrc => .bazelrc (100%) rename opensource/BUILD.bazel => BUILD.bazel (93%) rename opensource/WORKSPACE => WORKSPACE (100%) diff --git a/opensource/.bazelrc b/.bazelrc similarity index 100% rename from opensource/.bazelrc rename to .bazelrc diff --git a/opensource/BUILD.bazel b/BUILD.bazel similarity index 93% rename from opensource/BUILD.bazel rename to BUILD.bazel index 1c60d28..97c9f3a 100644 --- a/opensource/BUILD.bazel +++ b/BUILD.bazel @@ -32,6 +32,11 @@ licenses(["notice"]) SNAPPY_VERSION = (1, 1, 10) +config_setting( + name = "windows", + constraint_values = ["@platforms//os:windows"], +) + cc_library( name = "config", hdrs = ["config.h"], @@ -64,9 +69,11 @@ cc_library( "snappy.h", "snappy-sinksource.h", ], - copts = [ + copts = select({ + ":windows": [], + "//conditions:default": [ "-Wno-sign-compare", - ], + ]}), deps = [ ":config", ":snappy-stubs-internal", @@ -153,6 +160,10 @@ genrule( # endif #endif +#if defined(_WIN32) && !defined(HAVE_WINDOWS_H) +#define HAVE_WINDOWS_H 1 +#endif + #ifdef __has_include # if !defined(HAVE_BYTESWAP_H) && __has_include() # define HAVE_BYTESWAP_H 1 @@ -189,9 +200,9 @@ genrule( name = "snappy_stubs_public_h", srcs = ["snappy-stubs-public.h.in"], outs = ["snappy-stubs-public.h"], - # Define HAVE_SYS_UIO_H_01 to 1; we just assume it's available. + # Assume sys/uio.h is available on non-Windows. # Set the version numbers. - cmd = ("""sed -e 's/$${\\(.*\\)_01}/1/g' \ + cmd = ("""sed -e 's/$${HAVE_SYS_UIO_H_01}/!_WIN32/g' \ -e 's/$${PROJECT_VERSION_MAJOR}/%d/g' \ -e 's/$${PROJECT_VERSION_MINOR}/%d/g' \ -e 's/$${PROJECT_VERSION_PATCH}/%d/g' \ diff --git a/opensource/WORKSPACE b/WORKSPACE similarity index 100% rename from opensource/WORKSPACE rename to WORKSPACE