Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address review comments for Bazel/Win32 build #499

Merged
merged 3 commits into from
Nov 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions bazel/glog.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
# This file is inspired by the following sample BUILD files:
# https://github.com/google/glog/issues/61
# https://github.com/google/glog/files/393474/BUILD.txt
#
# Known issue: the namespace parameter is not supported on Win32.

def glog_library(namespace = "google", with_gflags = 1, **kwargs):
if native.repository_name() != "@":
gendir = "$(GENDIR)/external/" + native.repository_name().lstrip("@")
repo_name = native.repository_name().lstrip("@")
gendir = "$(GENDIR)/external/" + repo_name
src_windows = "external/%s/src/windows" % repo_name
else:
gendir = "$(GENDIR)"
src_windows = "src/windows"

common_copts = [
"-DGLOG_BAZEL_BUILD",
Expand Down Expand Up @@ -50,6 +55,14 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):

windows_only_copts = [
"-DHAVE_SNPRINTF",
"-I" + src_windows,
]

windows_only_srcs = [
"src/glog/log_severity.h",
"src/windows/config.h",
"src/windows/port.cc",
"src/windows/port.h",
]

gflags_deps = ["@com_github_gflags_gflags//:gflags"] if with_gflags else []
Expand Down Expand Up @@ -79,7 +92,7 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
"src/utilities.h",
"src/vlog_is_on.cc",
] + select({
"@bazel_tools//src/conditions:windows": ["src/windows/port.cc", "src/windows/port.h"],
"@bazel_tools//src/conditions:windows": windows_only_srcs,
"//conditions:default": [":config_h"],
}),
copts =
Expand All @@ -105,16 +118,19 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):

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)",
],
hdrs = native.glob(["src/windows/glog/*.h"]),
strip_include_prefix = "src/windows",
# We need to override the default GOOGLE_GLOG_DLL_DECL from
# src/windows/glog/*.h to match src/windows/config.h.
defines = ["GOOGLE_GLOG_DLL_DECL=__declspec(dllexport)"],
deps = [":strip_include_prefix_hack"],
)

# Workaround https://github.com/bazelbuild/bazel/issues/6337 by declaring
# the dependencies without strip_include_prefix.
native.cc_library(
name = "strip_include_prefix_hack",
hdrs = native.glob(["src/windows/*.h"]),
)

native.cc_library(
Expand Down