From a9159b30f6e5c4960330aacff3ecf0702a40b83e Mon Sep 17 00:00:00 2001 From: Luc Bertrand Date: Mon, 4 Nov 2019 11:19:09 +0100 Subject: [PATCH 1/3] apply buildifier on glog.bzl --- bazel/glog.bzl | 150 +++++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 74 deletions(-) diff --git a/bazel/glog.bzl b/bazel/glog.bzl index 4a1bc6c53..2d8682b6b 100644 --- a/bazel/glog.bzl +++ b/bazel/glog.bzl @@ -7,95 +7,95 @@ # https://github.com/google/glog/issues/61 # https://github.com/google/glog/files/393474/BUILD.txt -def glog_library(namespace='google', with_gflags=1, **kwargs): - if native.repository_name() != '@': - gendir = '$(GENDIR)/external/' + native.repository_name().lstrip('@') +def glog_library(namespace = "google", with_gflags = 1, **kwargs): + if native.repository_name() != "@": + gendir = "$(GENDIR)/external/" + native.repository_name().lstrip("@") else: - gendir = '$(GENDIR)' + gendir = "$(GENDIR)" native.cc_library( - name = 'glog', - visibility = [ '//visibility:public' ], + name = "glog", + visibility = ["//visibility:public"], srcs = [ - ':config_h', - 'src/base/commandlineflags.h', - 'src/base/googleinit.h', - 'src/base/mutex.h', - 'src/demangle.cc', - 'src/demangle.h', - 'src/logging.cc', - 'src/raw_logging.cc', - 'src/signalhandler.cc', - 'src/stacktrace.h', - 'src/stacktrace_generic-inl.h', - 'src/stacktrace_libunwind-inl.h', - 'src/stacktrace_powerpc-inl.h', - 'src/stacktrace_windows-inl.h', - 'src/stacktrace_x86-inl.h', - 'src/stacktrace_x86_64-inl.h', - 'src/symbolize.cc', - 'src/symbolize.h', - 'src/utilities.cc', - 'src/utilities.h', - 'src/vlog_is_on.cc', + ":config_h", + "src/base/commandlineflags.h", + "src/base/googleinit.h", + "src/base/mutex.h", + "src/demangle.cc", + "src/demangle.h", + "src/logging.cc", + "src/raw_logging.cc", + "src/signalhandler.cc", + "src/stacktrace.h", + "src/stacktrace_generic-inl.h", + "src/stacktrace_libunwind-inl.h", + "src/stacktrace_powerpc-inl.h", + "src/stacktrace_windows-inl.h", + "src/stacktrace_x86-inl.h", + "src/stacktrace_x86_64-inl.h", + "src/symbolize.cc", + "src/symbolize.h", + "src/utilities.cc", + "src/utilities.h", + "src/vlog_is_on.cc", ], hdrs = [ - ':logging_h', - ':raw_logging_h', - ':stl_logging_h', - ':vlog_is_on_h', - 'src/glog/log_severity.h', + ":logging_h", + ":raw_logging_h", + ":stl_logging_h", + ":vlog_is_on_h", + "src/glog/log_severity.h", ], - strip_include_prefix = 'src', + strip_include_prefix = "src", copts = [ # Disable warnings that exists in glog. - '-Wno-sign-compare', - '-Wno-unused-function', - '-Wno-unused-local-typedefs', - '-Wno-unused-variable', + "-Wno-sign-compare", + "-Wno-unused-function", + "-Wno-unused-local-typedefs", + "-Wno-unused-variable", "-DGLOG_BAZEL_BUILD", # Inject a C++ namespace. "-DGOOGLE_NAMESPACE='%s'" % namespace, # Allows src/base/mutex.h to include pthread.h. - '-DHAVE_PTHREAD', + "-DHAVE_PTHREAD", # Allows src/logging.cc to determine the host name. - '-DHAVE_SYS_UTSNAME_H', + "-DHAVE_SYS_UTSNAME_H", # For src/utilities.cc. - '-DHAVE_SYS_SYSCALL_H', - '-DHAVE_SYS_TIME_H', - '-DHAVE_STDINT_H', - '-DHAVE_STRING_H', + "-DHAVE_SYS_SYSCALL_H", + "-DHAVE_SYS_TIME_H", + "-DHAVE_STDINT_H", + "-DHAVE_STRING_H", # Enable dumping stacktrace upon sigaction. - '-DHAVE_SIGACTION', + "-DHAVE_SIGACTION", # For logging.cc. - '-DHAVE_PREAD', - '-DHAVE___ATTRIBUTE__', + "-DHAVE_PREAD", + "-DHAVE___ATTRIBUTE__", # Include generated header files. - '-I%s/glog_internal' % gendir, + "-I%s/glog_internal" % gendir, ] + select({ # For stacktrace. - '@bazel_tools//src/conditions:darwin': [ - '-DHAVE_UNWIND_H', - '-DHAVE_DLADDR', + "@bazel_tools//src/conditions:darwin": [ + "-DHAVE_UNWIND_H", + "-DHAVE_DLADDR", ], - '//conditions:default': [ - '-DHAVE_UNWIND_H', + "//conditions:default": [ + "-DHAVE_UNWIND_H", ], }) + ([ # Use gflags to parse CLI arguments. - '-DHAVE_LIB_GFLAGS', + "-DHAVE_LIB_GFLAGS", ] if with_gflags else []), deps = [ - '@com_github_gflags_gflags//:gflags', + "@com_github_gflags_gflags//:gflags", ] if with_gflags else [], **kwargs ) native.genrule( - name = 'gen_sh', + name = "gen_sh", outs = [ - 'gen.sh', + "gen.sh", ], cmd = r'''\ #!/bin/sh @@ -119,30 +119,32 @@ EOF ) native.genrule( - name = 'config_h', + name = "config_h", srcs = [ - 'src/config.h.cmake.in', + "src/config.h.cmake.in", ], outs = [ - 'glog_internal/config.h', + "glog_internal/config.h", ], cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $< > $@", ) - [native.genrule( - name = '%s_h' % f, - srcs = [ - 'src/glog/%s.h.in' % f, - ], - outs = [ - 'src/glog/%s.h' % f, - ], - cmd = '$(location :gen_sh) < $< > $@', - tools = [':gen_sh'], - ) for f in [ - 'vlog_is_on', - 'stl_logging', - 'raw_logging', - 'logging', + [ + native.genrule( + name = "%s_h" % f, + srcs = [ + "src/glog/%s.h.in" % f, + ], + outs = [ + "src/glog/%s.h" % f, + ], + cmd = "$(location :gen_sh) < $< > $@", + tools = [":gen_sh"], + ) + for f in [ + "vlog_is_on", + "stl_logging", + "raw_logging", + "logging", ] ] From 375b97b964e201c1f2df52e57235e4ea58383053 Mon Sep 17 00:00:00 2001 From: Luc Bertrand Date: Mon, 4 Nov 2019 11:19:35 +0100 Subject: [PATCH 2/3] add windows support for bazel bazed build --- bazel/glog.bzl | 150 ++++++++++++++++++++++++++++++------------------- 1 file changed, 93 insertions(+), 57 deletions(-) diff --git a/bazel/glog.bzl b/bazel/glog.bzl index 2d8682b6b..4c11f1200 100644 --- a/bazel/glog.bzl +++ b/bazel/glog.bzl @@ -13,11 +13,51 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs): else: gendir = "$(GENDIR)" + common_copts = [ + "-DGLOG_BAZEL_BUILD", + "-DHAVE_STDINT_H", + "-DHAVE_STRING_H", + "-DHAVE_UNWIND_H", + ] + (["-DHAVE_LIB_GFLAGS"] if with_gflags else []) + + linux_or_darwin_copts = [ + # Disable warnings that exists in glog. + "-Wno-sign-compare", + "-Wno-unused-function", + "-Wno-unused-local-typedefs", + "-Wno-unused-variable", + # Inject a C++ namespace. + "-DGOOGLE_NAMESPACE='%s'" % namespace, + # Allows src/base/mutex.h to include pthread.h. + "-DHAVE_PTHREAD", + # Allows src/logging.cc to determine the host name. + "-DHAVE_SYS_UTSNAME_H", + # For src/utilities.cc. + "-DHAVE_SYS_SYSCALL_H", + "-DHAVE_SYS_TIME_H", + # Enable dumping stacktrace upon sigaction. + "-DHAVE_SIGACTION", + # For logging.cc. + "-DHAVE_PREAD", + "-DHAVE___ATTRIBUTE__", + "-I%s/glog_internal" % gendir, + ] + + darwin_only_copts = [ + # For stacktrace. + "-DHAVE_DLADDR", + ] + + windows_only_copts = [ + "-DHAVE_SNPRINTF", + ] + + gflags_deps = ["@com_github_gflags_gflags//:gflags"] if with_gflags else [] + native.cc_library( name = "glog", visibility = ["//visibility:public"], srcs = [ - ":config_h", "src/base/commandlineflags.h", "src/base/googleinit.h", "src/base/mutex.h", @@ -38,58 +78,65 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs): "src/utilities.cc", "src/utilities.h", "src/vlog_is_on.cc", + ] + select({ + "@bazel_tools//src/conditions:windows": ["src/windows/port.cc", "src/windows/port.h"], + "//conditions:default": [":config_h"], + }), + copts = + select({ + "@bazel_tools//src/conditions:windows": common_copts + windows_only_copts, + "@bazel_tools//src/conditions:darwin": common_copts + linux_or_darwin_copts + darwin_only_copts, + "//conditions:default": common_copts + linux_or_darwin_copts, + }), + deps = [ + ":glog_headers", + ] + gflags_deps, + **kwargs + ) + + # glog headers vary depending on the os. + native.cc_library( + name = "glog_headers", + deps = select({ + "@bazel_tools//src/conditions:windows": [":windows_glog_headers"], + "//conditions:default": [":default_glog_headers"], + }), + ) + + native.cc_library( + name = "windows_glog_headers", + hdrs = ["src/glog/log_severity.h", "src/windows/config.h",] + native.glob(["src/windows/glog/*.h"]), + includes = ["src/windows"], + # config.h for windows seem hardcoded that way, + # and we need to propagate those defines to binaries/libraries linking + # against glog. + defines = [ + "GOOGLE_GLOG_IS_A_DLL=1", + "GOOGLE_GLOG_DLL_DECL=__declspec(dllexport)", + "GOOGLE_GLOG_DLL_DECL_FOR_UNITTEST=__declspec(dllimport)", ], + ) + + native.cc_library( + name = "default_glog_headers", + strip_include_prefix = "src", hdrs = [ + "src/glog/log_severity.h", ":logging_h", ":raw_logging_h", ":stl_logging_h", ":vlog_is_on_h", - "src/glog/log_severity.h", ], - strip_include_prefix = "src", - copts = [ - # Disable warnings that exists in glog. - "-Wno-sign-compare", - "-Wno-unused-function", - "-Wno-unused-local-typedefs", - "-Wno-unused-variable", - "-DGLOG_BAZEL_BUILD", - # Inject a C++ namespace. - "-DGOOGLE_NAMESPACE='%s'" % namespace, - # Allows src/base/mutex.h to include pthread.h. - "-DHAVE_PTHREAD", - # Allows src/logging.cc to determine the host name. - "-DHAVE_SYS_UTSNAME_H", - # For src/utilities.cc. - "-DHAVE_SYS_SYSCALL_H", - "-DHAVE_SYS_TIME_H", - "-DHAVE_STDINT_H", - "-DHAVE_STRING_H", - # Enable dumping stacktrace upon sigaction. - "-DHAVE_SIGACTION", - # For logging.cc. - "-DHAVE_PREAD", - "-DHAVE___ATTRIBUTE__", - - # Include generated header files. - "-I%s/glog_internal" % gendir, - ] + select({ - # For stacktrace. - "@bazel_tools//src/conditions:darwin": [ - "-DHAVE_UNWIND_H", - "-DHAVE_DLADDR", - ], - "//conditions:default": [ - "-DHAVE_UNWIND_H", - ], - }) + ([ - # Use gflags to parse CLI arguments. - "-DHAVE_LIB_GFLAGS", - ] if with_gflags else []), - deps = [ - "@com_github_gflags_gflags//:gflags", - ] if with_gflags else [], - **kwargs + ) + native.genrule( + name = "config_h", + srcs = [ + "src/config.h.cmake.in", + ], + outs = [ + "glog_internal/config.h", + ], + cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $< > $@", ) native.genrule( @@ -118,17 +165,6 @@ EOF '''.format(int(with_gflags)), ) - native.genrule( - name = "config_h", - srcs = [ - "src/config.h.cmake.in", - ], - outs = [ - "glog_internal/config.h", - ], - cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $< > $@", - ) - [ native.genrule( name = "%s_h" % f, From 43b8f5ced182d6ce43f27fa409181dfbcf31f58d Mon Sep 17 00:00:00 2001 From: Luc Bertrand Date: Mon, 4 Nov 2019 11:22:11 +0100 Subject: [PATCH 3/3] add windows target to bazel CI --- .bazelci/presubmit.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 4a6248dd1..38e8515e9 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -15,3 +15,11 @@ platforms: - "..." test_targets: - "..." + windows: + # Optional: use VS 2017 instead of 2015. + environment: + BAZEL_VC: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC" + build_targets: + - "..." + test_targets: + - "..."