Skip to content

Commit

Permalink
Use Bazel rules_cc for many compiler-specific rules
Browse files Browse the repository at this point in the history
instead of our custom ones from before the Bazel rules existed.

Also add the missing rules_cc to WORKSPACE, since we already had
it in MODULE.bazel

PiperOrigin-RevId: 715006932
Change-Id: Ibb38a78c115a7dc2983426455bb271162795846f
  • Loading branch information
derekmauro authored and copybara-github committed Jan 13, 2025
1 parent 3f770c4 commit f4af6c0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 109 deletions.
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ http_archive(
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz"],
)

# C++ rules for Bazel
http_archive(
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.1.0/rules_cc-0.1.0.tar.gz"],
sha256 = "4b12149a041ddfb8306a8fd0e904e39d673552ce82e4296e96fac9cbf0780e59",
strip_prefix = "rules_cc-0.1.0",
)

# Bazel platform rules.
http_archive(
name = "platforms",
Expand Down
71 changes: 0 additions & 71 deletions absl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ config_setting(
visibility = [":__subpackages__"],
)

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

config_setting(
name = "mingw_unspecified_compiler",
flag_values = {
Expand All @@ -52,69 +44,6 @@ config_setting(
visibility = [":__subpackages__"],
)

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

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

config_setting(
name = "osx",
constraint_values = [
"@platforms//os:osx",
],
)

config_setting(
name = "ios",
constraint_values = [
"@platforms//os:ios",
],
)

config_setting(
name = "ppc",
constraint_values = [
"@platforms//cpu:ppc",
],
visibility = [":__subpackages__"],
)

config_setting(
name = "platforms_wasm32",
constraint_values = [
"@platforms//cpu:wasm32",
],
visibility = [":__subpackages__"],
)

config_setting(
name = "platforms_wasm64",
constraint_values = [
"@platforms//cpu:wasm64",
],
visibility = [":__subpackages__"],
)

selects.config_setting_group(
name = "wasm",
match_any = [
":platforms_wasm32",
":platforms_wasm64",
],
visibility = [":__subpackages__"],
)

config_setting(
name = "fuchsia",
constraint_values = [
Expand Down
12 changes: 6 additions & 6 deletions absl/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ cc_library(
"//conditions:default": [],
}),
linkopts = select({
"//absl:msvc_compiler": [],
"//absl:clang-cl_compiler": [],
"//absl:wasm": [],
"@rules_cc//cc/compiler:msvc-cl": [],
"@rules_cc//cc/compiler:clang-cl": [],
"@rules_cc//cc/compiler:emscripten": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
visibility = [
Expand Down Expand Up @@ -268,17 +268,17 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
"//absl:msvc_compiler": [
"@rules_cc//cc/compiler:msvc-cl": [
"-DEFAULTLIB:advapi32.lib",
],
"//absl:clang-cl_compiler": [
"@rules_cc//cc/compiler:clang-cl": [
"-DEFAULTLIB:advapi32.lib",
],
"//absl:mingw_compiler": [
"-DEFAULTLIB:advapi32.lib",
"-ladvapi32",
],
"//absl:wasm": [],
"@rules_cc//cc/compiler:emscripten": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
deps = [
Expand Down
22 changes: 11 additions & 11 deletions absl/copts/configure_copts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ load(
)

ABSL_DEFAULT_COPTS = select({
"//absl:msvc_compiler": ABSL_MSVC_FLAGS,
"//absl:clang-cl_compiler": ABSL_CLANG_CL_FLAGS,
"//absl:clang_compiler": ABSL_LLVM_FLAGS,
"//absl:gcc_compiler": ABSL_GCC_FLAGS,
"//conditions:default": ABSL_GCC_FLAGS,
"@rules_cc//cc/compiler:msvc-cl": ABSL_MSVC_FLAGS,
"@rules_cc//cc/compiler:clang-cl": ABSL_CLANG_CL_FLAGS,
"@rules_cc//cc/compiler:clang": ABSL_LLVM_FLAGS,
"@rules_cc//cc/compiler:gcc": ABSL_GCC_FLAGS,
"//conditions:default": [],
})

ABSL_TEST_COPTS = select({
"//absl:msvc_compiler": ABSL_MSVC_TEST_FLAGS,
"//absl:clang-cl_compiler": ABSL_CLANG_CL_TEST_FLAGS,
"//absl:clang_compiler": ABSL_LLVM_TEST_FLAGS,
"//absl:gcc_compiler": ABSL_GCC_TEST_FLAGS,
"//conditions:default": ABSL_GCC_TEST_FLAGS,
"@rules_cc//cc/compiler:msvc-cl": ABSL_MSVC_TEST_FLAGS,
"@rules_cc//cc/compiler:clang-cl": ABSL_CLANG_CL_TEST_FLAGS,
"@rules_cc//cc/compiler:clang": ABSL_LLVM_TEST_FLAGS,
"@rules_cc//cc/compiler:gcc": ABSL_GCC_TEST_FLAGS,
"//conditions:default": [],
})

ABSL_DEFAULT_LINKOPTS = select({
"//absl:msvc_compiler": ABSL_MSVC_LINKOPTS,
"@rules_cc//cc/compiler:msvc-cl": ABSL_MSVC_LINKOPTS,
"//conditions:default": [],
})
18 changes: 9 additions & 9 deletions absl/debugging/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS + select({
"//absl:msvc_compiler": ["-DEFAULTLIB:dbghelp.lib"],
"//absl:clang-cl_compiler": ["-DEFAULTLIB:dbghelp.lib"],
"@rules_cc//cc/compiler:msvc-cl": ["-DEFAULTLIB:dbghelp.lib"],
"@rules_cc//cc/compiler:clang-cl": ["-DEFAULTLIB:dbghelp.lib"],
"//absl:mingw_compiler": [
"-DEFAULTLIB:dbghelp.lib",
"-ldbghelp",
Expand All @@ -113,13 +113,13 @@ cc_test(
name = "symbolize_test",
srcs = ["symbolize_test.cc"],
copts = ABSL_TEST_COPTS + select({
"//absl:msvc_compiler": ["/Z7"],
"//absl:clang-cl_compiler": ["/Z7"],
"@rules_cc//cc/compiler:msvc-cl": ["/Z7"],
"@rules_cc//cc/compiler:clang-cl": ["/Z7"],
"//conditions:default": [],
}),
linkopts = ABSL_DEFAULT_LINKOPTS + select({
"//absl:msvc_compiler": ["/DEBUG"],
"//absl:clang-cl_compiler": ["/DEBUG"],
"@rules_cc//cc/compiler:msvc-cl": ["/DEBUG"],
"@rules_cc//cc/compiler:clang-cl": ["/DEBUG"],
"//conditions:default": [],
}),
deps = [
Expand Down Expand Up @@ -177,9 +177,9 @@ cc_test(
srcs = ["failure_signal_handler_test.cc"],
copts = ABSL_TEST_COPTS,
linkopts = select({
"//absl:msvc_compiler": [],
"//absl:clang-cl_compiler": [],
"//absl:wasm": [],
"@rules_cc//cc/compiler:msvc-cl": [],
"@rules_cc//cc/compiler:clang-cl": [],
"@rules_cc//cc/compiler:emscripten": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
deps = [
Expand Down
4 changes: 2 additions & 2 deletions absl/log/internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ cc_library(
"//absl/strings",
"//absl/time",
] + select({
"//absl:msvc_compiler": [],
"@rules_cc//cc/compiler:msvc-cl": [],
"//conditions:default": [
],
}),
Expand Down Expand Up @@ -404,7 +404,7 @@ cc_library(
"//absl/time",
"@googletest//:gtest",
] + select({
"//absl:msvc_compiler": [],
"@rules_cc//cc/compiler:msvc-cl": [],
"//conditions:default": [
],
}),
Expand Down
14 changes: 7 additions & 7 deletions absl/random/internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS + select({
"//absl:msvc_compiler": ["-DEFAULTLIB:bcrypt.lib"],
"//absl:clang-cl_compiler": ["-DEFAULTLIB:bcrypt.lib"],
"@rules_cc//cc/compiler:msvc-cl": ["-DEFAULTLIB:bcrypt.lib"],
"@rules_cc//cc/compiler:clang-cl": ["-DEFAULTLIB:bcrypt.lib"],
"//absl:mingw_compiler": [
"-DEFAULTLIB:bcrypt.lib",
"-lbcrypt",
Expand Down Expand Up @@ -183,9 +183,9 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
"//absl:msvc_compiler": [],
"//absl:clang-cl_compiler": [],
"//absl:wasm": [],
"@rules_cc//cc/compiler:msvc-cl": [],
"@rules_cc//cc/compiler:clang-cl": [],
"@rules_cc//cc/compiler:emscripten": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
deps = [
Expand Down Expand Up @@ -414,8 +414,8 @@ cc_library(
"randen_hwaes.h",
],
copts = ABSL_DEFAULT_COPTS + ABSL_RANDOM_RANDEN_COPTS + select({
"//absl:msvc_compiler": [],
"//absl:clang-cl_compiler": [],
"@rules_cc//cc/compiler:msvc-cl": [],
"@rules_cc//cc/compiler:clang-cl": [],
"//conditions:default": ["-Wno-pass-failed"],
}),
linkopts = ABSL_DEFAULT_LINKOPTS,
Expand Down
6 changes: 3 additions & 3 deletions absl/synchronization/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
"//absl:msvc_compiler": [],
"//absl:clang-cl_compiler": [],
"//absl:wasm": [],
"@rules_cc//cc/compiler:msvc-cl": [],
"@rules_cc//cc/compiler:clang-cl": [],
"@rules_cc//cc/compiler:emscripten": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
visibility = ["//visibility:public"],
Expand Down

0 comments on commit f4af6c0

Please sign in to comment.