From 5e57f1bf52834cd5133011624c9bbc8cbf58c272 Mon Sep 17 00:00:00 2001 From: Jordan Rupprecht Date: Mon, 10 Apr 2023 11:42:58 -0700 Subject: [PATCH] [bazel][NFC] Replace @bazel_tools//src/conditions with equivalent @platforms 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 --- .../llvm-project-overlay/clang/BUILD.bazel | 6 +-- .../clang/unittests/BUILD.bazel | 2 +- .../llvm-project-overlay/llvm/BUILD.bazel | 38 +++++++++---------- .../llvm/cc_plugin_library.bzl | 8 ++-- .../third-party/unittest/BUILD.bazel | 2 +- utils/bazel/vulkan_sdk.bzl | 2 +- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel index 8014f2ce11e6..ebe12dc561d5 100644 --- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel @@ -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([ @@ -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", @@ -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, diff --git a/utils/bazel/llvm-project-overlay/clang/unittests/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/unittests/BUILD.bazel index df09837ef5fb..ae65e833ec24 100644 --- a/utils/bazel/llvm-project-overlay/clang/unittests/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/clang/unittests/BUILD.bazel @@ -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*", diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel index 3900979f5efc..facc1f106e0e 100644 --- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel @@ -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", ]), @@ -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", @@ -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", ]), @@ -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", @@ -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", ], @@ -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", ], @@ -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", @@ -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", @@ -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, @@ -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", diff --git a/utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl b/utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl index 2ebd39c630dc..b28425efa397 100644 --- a/utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl +++ b/utils/bazel/llvm-project-overlay/llvm/cc_plugin_library.bzl @@ -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", @@ -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, diff --git a/utils/bazel/llvm-project-overlay/third-party/unittest/BUILD.bazel b/utils/bazel/llvm-project-overlay/third-party/unittest/BUILD.bazel index ae9f46fae05d..fcb29d6e3771 100644 --- a/utils/bazel/llvm-project-overlay/third-party/unittest/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/third-party/unittest/BUILD.bazel @@ -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 = [ diff --git a/utils/bazel/vulkan_sdk.bzl b/utils/bazel/vulkan_sdk.bzl index 1252ccd2147d..e23dc42131c4 100644 --- a/utils/bazel/vulkan_sdk.bzl +++ b/utils/bazel/vulkan_sdk.bzl @@ -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": [