Skip to content

Commit

Permalink
[bazel][NFC] Replace @bazel_tools//src/conditions with equivalent @pl…
Browse files Browse the repository at this point in the history
…atforms rules

Followup to D147354. Using src/conditions is discouraged in favor of using rules from the `@platforms` repository directly.

This replaces three conditions:
* `@bazel_tools//src/conditions:windows` -> `@platforms//os:windows`
* `@bazel_tools//src/conditions:darwin` -> `@platforms//os:macos`
* `@bazel_tools//src/conditions:freebsd` -> `@platforms//os:freebsd`

`llvm/config.bzl` has a non-trivial OS+CPU selection config, so that is omitted from this patch. There is intentionally no equivalent for that in `@platforms` because every project will have their own opinions about what a platform is, and it is not feasible for the bazel selection list to include every possible combination. The recommended idiom there is for projects to define their own supported platforms list, e.g. in a separate BUILD file or platform mapping.

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D147948
  • Loading branch information
rupprecht committed Apr 10, 2023
1 parent 6de3afe commit 5e57f1b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions utils/bazel/llvm-project-overlay/clang/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ cc_library(
"lib/Driver",
],
linkopts = select({
"@bazel_tools//src/conditions:windows": ["version.lib"],
"@platforms//os:windows": ["version.lib"],
"//conditions:default": [],
}),
textual_hdrs = glob([
Expand Down Expand Up @@ -1881,7 +1881,7 @@ cc_plugin_library(
]),
hdrs = glob(["include/clang-c/*.h"]),
copts = select({
"@bazel_tools//src/conditions:windows": ["-D_CINDEX_LIB_"],
"@platforms//os:windows": ["-D_CINDEX_LIB_"],
"//conditions:default": [],
}),
strip_include_prefix = "include",
Expand Down Expand Up @@ -1970,7 +1970,7 @@ cc_binary(
testonly = 1,
srcs = ["tools/c-arcmt-test/c-arcmt-test.c"],
copts = select({
"@bazel_tools//src/conditions:windows": [],
"@platforms//os:windows": [],
"//conditions:default": ["-std=gnu99"],
}),
stamp = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ cc_test(
"libclang/TestUtils.h",
],
args = select({
"@bazel_tools//src/conditions:windows": [
"@platforms//os:windows": [
# Need to disable the VFS tests that don't use Windows friendly
# paths. These are also disabled on Windows in the CMake build.
"--gtest_filter=-*VirtualFileOverlay*",
Expand Down
38 changes: 19 additions & 19 deletions utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ cc_library(
# To avoid a dependency cycle.
"include/llvm/Option/*.h",
]) + select({
"@bazel_tools//src/conditions:windows": glob([
"@platforms//os:windows": glob([
"lib/Support/Windows/*.h",
"lib/Support/Windows/*.inc",
]),
Expand Down Expand Up @@ -255,8 +255,8 @@ cc_library(
}),
includes = ["include"],
linkopts = select({
"@bazel_tools//src/conditions:windows": [],
"@bazel_tools//src/conditions:freebsd": [
"@platforms//os:windows": [],
"@platforms//os:freebsd": [
"-pthread",
"-lexecinfo",
"-ldl",
Expand Down Expand Up @@ -1124,7 +1124,7 @@ cc_library(
"lib/TargetParser/*.cpp",
"lib/TargetParser/*.h",
]) + select({
"@bazel_tools//src/conditions:windows": glob([
"@platforms//os:windows": glob([
"lib/TargetParser/Windows/*.h",
"lib/TargetParser/Windows/*.inc",
]),
Expand Down Expand Up @@ -2105,7 +2105,7 @@ gentbl(
# MSVC isn't happy with long string literals, while other compilers
# which support them get significant compile time improvements with
# them enabled. Ideally this flag would only be enabled on Windows via
# a select() on `@bazel_tools//src/conditions:windows,`, but that would
# a select() on `@platforms//os:windows,`, but that would
# require refactoring gentbl from a macro into a rule.
# TODO(#92): Refactor gentbl to support this use
tblgen_args = "--long-string-literals=0",
Expand Down Expand Up @@ -2581,9 +2581,9 @@ cc_library(
copts = llvm_copts,
linkopts = select({
"@platforms//os:android": [],
"@bazel_tools//src/conditions:windows": [],
"@bazel_tools//src/conditions:freebsd": [],
"@bazel_tools//src/conditions:darwin": [],
"@platforms//os:windows": [],
"@platforms//os:freebsd": [],
"@platforms//os:macos": [],
"//conditions:default": [
"-lrt",
],
Expand Down Expand Up @@ -2647,9 +2647,9 @@ cc_library(
copts = llvm_copts,
linkopts = select({
"@platforms//os:android": [],
"@bazel_tools//src/conditions:windows": [],
"@bazel_tools//src/conditions:freebsd": [],
"@bazel_tools//src/conditions:darwin": [],
"@platforms//os:windows": [],
"@platforms//os:freebsd": [],
"@platforms//os:macos": [],
"//conditions:default": [
"-lrt",
],
Expand Down Expand Up @@ -3012,8 +3012,8 @@ cc_binary(
# ll scripts rely on symbols from dependent
# libraries being resolvable.
linkopts = select({
"@bazel_tools//src/conditions:windows": [],
"@bazel_tools//src/conditions:darwin": [],
"@platforms//os:windows": [],
"@platforms//os:macos": [],
"//conditions:default": [
"-Wl,--undefined=_ZTIi",
"-Wl,--export-dynamic-symbol=_ZTIi",
Expand Down Expand Up @@ -3521,8 +3521,8 @@ cc_binary(
copts = llvm_copts,
# Make symbols from the standard library dynamically resolvable.
linkopts = select({
"@bazel_tools//src/conditions:windows": [],
"@bazel_tools//src/conditions:darwin": [],
"@platforms//os:windows": [],
"@platforms//os:macos": [],
"//conditions:default": [
"-Wl,--undefined=_ZTIi",
"-Wl,--export-dynamic-symbol=_ZTIi",
Expand Down Expand Up @@ -4471,8 +4471,8 @@ cc_binary(
]),
copts = llvm_copts,
linkopts = select({
"@bazel_tools//src/conditions:windows": [],
"@bazel_tools//src/conditions:darwin": [],
"@platforms//os:windows": [],
"@platforms//os:macos": [],
"//conditions:default": ["-Wl,--export-dynamic"],
}),
stamp = 0,
Expand Down Expand Up @@ -4701,8 +4701,8 @@ cc_binary(
# isn't even used in the main binary, so we also need to force it
# to be included.
linkopts = select({
"@bazel_tools//src/conditions:windows": [],
"@bazel_tools//src/conditions:darwin": [],
"@platforms//os:windows": [],
"@platforms//os:macos": [],
"//conditions:default": [
"-rdynamic",
"-u_ZTIi",
Expand Down
8 changes: 4 additions & 4 deletions utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def cc_plugin_library(name, srcs, hdrs, include_prefix = None, strip_include_pre
native.filegroup(
name = interface_output_name,
srcs = select({
"@bazel_tools//src/conditions:windows": [":" + dll_name],
"@bazel_tools//src/conditions:darwin": [":" + dylib_name],
"@platforms//os:windows": [":" + dll_name],
"@platforms//os:macos": [":" + dylib_name],
"//conditions:default": [":" + so_name],
}),
output_group = "interface_library",
Expand All @@ -53,8 +53,8 @@ def cc_plugin_library(name, srcs, hdrs, include_prefix = None, strip_include_pre
name = import_name,
interface_library = ":" + interface_output_name,
shared_library = select({
"@bazel_tools//src/conditions:windows": ":" + dll_name,
"@bazel_tools//src/conditions:darwin": ":" + dylib_name,
"@platforms//os:windows": ":" + dll_name,
"@platforms//os:macos": ":" + dylib_name,
"//conditions:default": ":" + so_name,
}),
alwayslink = alwayslink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ cc_library(
"__STDC_LIMIT_MACROS",
"__STDC_CONSTANT_MACROS",
] + select({
"@bazel_tools//src/conditions:windows": ["GTEST_USE_OWN_TR1_TUPLE=0"],
"@platforms//os:windows": ["GTEST_USE_OWN_TR1_TUPLE=0"],
"//conditions:default": ["GTEST_USE_OWN_TR1_TUPLE=1"],
}),
includes = [
Expand Down
2 changes: 1 addition & 1 deletion utils/bazel/vulkan_sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _impl(repository_ctx):
cc_library(
name = "sdk",
srcs = select({
"@bazel_tools//src/conditions:windows": [
"@platforms//os:windows": [
"vulkan-sdk/Lib/vulkan-1.lib"
],
"//conditions:default": [
Expand Down

0 comments on commit 5e57f1b

Please sign in to comment.