From d78757623df968ef62e12070e29e609cee470de5 Mon Sep 17 00:00:00 2001 From: mehrdadn Date: Fri, 5 Jun 2020 05:36:10 -0700 Subject: [PATCH] bazel build --compilation_mode=debug (#6457) --- .bazelrc | 9 +++++++++ BUILD.bazel | 8 +++++--- bazel/ray.bzl | 16 ++++++++++++++++ src/ray/util/logging.h | 10 ++++++++++ src/shims/windows/python-nondebug.h | 18 ++++++++++++++++++ 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/shims/windows/python-nondebug.h diff --git a/.bazelrc b/.bazelrc index 0d759b222..727e2101a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -5,6 +5,7 @@ build --enable_platform_specific_config # On all platforms, provide: PYTHON3_BIN_PATH=python ############################################################################### build --action_env=PATH +# For --compilation_mode=dbg, consider enabling checks in the standard library as well (below). build --compilation_mode=opt # This workaround is needed to prevent Bazel from compiling the same file twice (once PIC and once not). build:linux --force_pic @@ -45,6 +46,14 @@ build:windows --color=yes build:windows --per_file_copt="-\\.(asm|S)$@-fansi-escape-codes" build:windows --per_file_copt="-\\.(asm|S)$@-fcolor-diagnostics" +# Debug build flags. Uncomment in '-c dbg' builds to enable checks in the C++ standard library: +#build:linux --cxxopt="-D_GLIBCXX_DEBUG=1" +#build:linux --cxxopt="-D_GLIBCXX_DEBUG_PEDANTIC=1" +#build:linux --cxxopt="-D_LIBCPP_DEBUG=1" +#build:macos --cxxopt="-D_GLIBCXX_DEBUG=1" +#build:macos --cxxopt="-D_GLIBCXX_DEBUG_PEDANTIC=1" +#build:windows --cxxopt="-D_ITERATOR_DEBUG_LEVEL=2" + # Thread sanitizer configuration: build:tsan --strip=never build:tsan --copt -fsanitize=thread diff --git a/BUILD.bazel b/BUILD.bazel index 91cc1a5fb..0e9f1b04a 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -7,7 +7,7 @@ load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") load("@com_github_grpc_grpc//bazel:cython_library.bzl", "pyx_library") load("@rules_proto_grpc//python:defs.bzl", "python_grpc_compile") load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library") -load("//bazel:ray.bzl", "COPTS") +load("//bazel:ray.bzl", "COPTS", "PYX_COPTS", "PYX_SRCS") # === Begin of protobuf definitions === @@ -1598,7 +1598,8 @@ pyx_library( # We need to dlopen this lib with RTLD_GLOBAL to use ABI in this # shared lib, see python/ray/__init__.py. cc_kwargs = dict( - copts = COPTS, + srcs = PYX_SRCS, + copts = COPTS + PYX_COPTS, # see https://github.com/tensorflow/tensorflow/blob/r2.1/tensorflow/lite/BUILD#L444 linkopts = select({ "@bazel_tools//src/conditions:darwin": [ @@ -1636,7 +1637,8 @@ pyx_library( "python/ray/streaming/includes/*.pxi", ]), cc_kwargs = dict( - copts = COPTS, + srcs = PYX_SRCS, + copts = COPTS + PYX_COPTS, ), deps = [ "//streaming:streaming_lib", diff --git a/bazel/ray.bzl b/bazel/ray.bzl index 0d88bdfe0..eb67c348d 100644 --- a/bazel/ray.bzl +++ b/bazel/ray.bzl @@ -13,6 +13,22 @@ COPTS = ["-DRAY_USE_GLOG"] + select({ ], }) +PYX_COPTS = [] + select({ + "@bazel_tools//src/conditions:windows": [ + "/FI" + "src/shims/windows/python-nondebug.h", + ], + "//conditions:default": [ + ], +}) + +PYX_SRCS = [] + select({ + "@bazel_tools//src/conditions:windows": [ + "src/shims/windows/python-nondebug.h", + ], + "//conditions:default": [ + ], +}) + def flatbuffer_py_library(name, srcs, outs, out_prefix, includes = [], include_paths = []): flatbuffer_library_public( name = name, diff --git a/src/ray/util/logging.h b/src/ray/util/logging.h index 543b78fd4..d4a40ad63 100644 --- a/src/ray/util/logging.h +++ b/src/ray/util/logging.h @@ -33,6 +33,16 @@ enum { ERROR = 0 }; #endif #endif + +#if defined(DEBUG) && DEBUG == 1 +// Bazel defines the DEBUG macro for historical reasons: +// https://github.com/bazelbuild/bazel/issues/3513#issuecomment-323829248 +// Undefine the DEBUG macro to prevent conflicts with our usage below +#undef DEBUG +// Redefine DEBUG as itself to allow any '#ifdef DEBUG' to keep working regardless +#define DEBUG DEBUG +#endif + namespace ray { enum class RayLogLevel { DEBUG = -1, INFO = 0, WARNING = 1, ERROR = 2, FATAL = 3 }; diff --git a/src/shims/windows/python-nondebug.h b/src/shims/windows/python-nondebug.h new file mode 100644 index 000000000..e830b542b --- /dev/null +++ b/src/shims/windows/python-nondebug.h @@ -0,0 +1,18 @@ +// This is to avoid depending on the debug version of the Python library on Windows, +// which requires separate library files and linking. +#if defined(_WIN32) && defined(_DEBUG) +#ifdef Py_PYTHON_H +#error Python.h should not have been included at this point. +#endif +// Ensure some headers included before messing with macro +#include +#include +#ifdef Py_CONFIG_H +#error pyconfig.h should not have been included at this point. +#endif +#include "patchlevel.h" +#pragma push_macro("_DEBUG") +#undef _DEBUG +#include "pyconfig.h" +#pragma pop_macro("_DEBUG") +#endif