google / glog

C++ implementation of the Google logging module
http://google.github.io/glog/
BSD 3-Clause "New" or "Revised" License
6.92k stars 2.04k forks source link

Bazel build: Fix ignoring unknown option '-std=c++14' for Windows builds #1100

Open Vertexwahn opened 1 month ago

Vertexwahn commented 1 month ago

When build glog on Windows you get the following warning when using Visual Studio 2022: unknown option '-std=c++14' for Windows builds.

The reason for this is here.

Abseil has a good way to handle flags for different compilers - could copied here - something like this:

in configure_copts.bzl:

GLOG_MSVC_FLAGS = [
    "/std:c++20",
]

GLOG_GCC_FLAGS = [
    "-std=c++23",
]

GLOG_CLANG_FLAGS = [
    "-std=c++20",
]

GLOG_DEFAULT_COPTS = select({
    "//glog:msvc_compiler": GLOG_MSVC_FLAGS,
    "//glog:gcc_compiler": GLOG_GCC_FLAGS,
    "//glog:clang_compiler": GLOG_CLANG_FLAGS,
    "//conditions:default": GLOG_GCC_FLAGS,
})

In BUILD file:

config_setting(
    name = "msvc_compiler",
    flag_values = {
        "@bazel_tools//tools/cpp:compiler": "msvc-cl",
    },
    visibility = [":__subpackages__"],
)

config_setting(
    name = "gcc_compiler",
    flag_values = {
        "@bazel_tools//tools/cpp:compiler": "gcc",
    },
    visibility = [":__subpackages__"],
)

config_setting(
    name = "clang_compiler",
    flag_values = {
        "@bazel_tools//tools/cpp:compiler": "clang",
    },
    visibility = [":__subpackages__"],
)
drigz commented 1 month ago

@Vertexwahn I don't have a way to test this but happy to review a PR if you'd like to assign yourself and try out that suggestion.

drigz commented 1 month ago

If absl have a precedent for testing this with the Bazel CI that would be ideal: https://github.com/google/glog/blob/master/.bazelci/presubmit.yml