From 6d1c363dde8a4277f7f363446a82b2188fd94608 Mon Sep 17 00:00:00 2001 From: Rob Earhart Date: Fri, 5 Jan 2018 11:31:31 -0800 Subject: Add Bazel-on-Windows support --- BUILD | 6 ++++++ bazel/gflags.bzl | 31 +++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/BUILD b/BUILD index aa61563..0e7ccdd 100644 --- a/BUILD +++ b/BUILD @@ -6,7 +6,13 @@ licenses(["notice"]) exports_files(["src/gflags_completions.sh", "COPYING.txt"]) +config_setting( + name = "x64_windows", + values = {"cpu": "x64_windows"}, +) + load(":bazel/gflags.bzl", "gflags_sources", "gflags_library") + (hdrs, srcs) = gflags_sources(namespace=["gflags", "google"]) gflags_library(hdrs=hdrs, srcs=srcs, threads=0) gflags_library(hdrs=hdrs, srcs=srcs, threads=1) diff --git a/bazel/gflags.bzl b/bazel/gflags.bzl index 7bf91cd..6d1ef6c 100644 --- a/bazel/gflags.bzl +++ b/bazel/gflags.bzl @@ -47,8 +47,14 @@ def gflags_sources(namespace=["google", "gflags"]): "src/gflags_completions.cc", "src/gflags_reporting.cc", "src/mutex.h", - "src/util.h" - ] + "src/util.h", + ] + select({ + "//:x64_windows": [ + "src/windows_port.cc", + "src/windows_port.h", + ], + "//conditions:default": [], + }) return [hdrs, srcs] # ------------------------------------------------------------------------------ @@ -64,19 +70,28 @@ def gflags_library(hdrs=[], srcs=[], threads=1): "-DHAVE_SYS_TYPES_H", "-DHAVE_INTTYPES_H", "-DHAVE_SYS_STAT_H", - "-DHAVE_UNISTD_H", - "-DHAVE_FNMATCH_H", "-DHAVE_STRTOLL", "-DHAVE_STRTOQ", - "-DHAVE_PTHREAD", "-DHAVE_RWLOCK", - ] + ] + select({ + "//:x64_windows": [ + "-DOS_WINDOWS", + ], + "//conditions:default": [ + "-DHAVE_UNISTD_H", + "-DHAVE_FNMATCH_H", + "-DHAVE_PTHREAD", + ], + }) linkopts = [] if threads: - linkopts.append("-lpthread") + linkopts = linkopts + select({ + "//:x64_windows": [], + "//conditions:default": ["-lpthread"], + }) else: name += "_nothreads" - copts.append("-DNO_THREADS") + copts = copts + ["-DNO_THREADS"] native.cc_library( name = name, hdrs = hdrs, -- cgit v1.2.3