From cfd4b6d01e9ce1d915745d83a2f7553991ba020f Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Tue, 1 Oct 2024 11:28:25 -0500 Subject: [PATCH] Add toolchains (#1321) These can be used once we flip the ruleset to actual return the toolchain type from `use_swift_toolchain()`. Signed-off-by: Brentley Jones --- swift/internal/BUILD | 5 +- swift/internal/swift_autoconfiguration.bzl | 69 +++++++++++++++++++++- toolchains/BUILD | 4 ++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 toolchains/BUILD diff --git a/swift/internal/BUILD b/swift/internal/BUILD index 8a1c4bd75..00b7702a4 100644 --- a/swift/internal/BUILD +++ b/swift/internal/BUILD @@ -202,7 +202,10 @@ bzl_library( name = "swift_autoconfiguration", srcs = ["swift_autoconfiguration.bzl"], visibility = ["//swift:__subpackages__"], - deps = ["//swift/internal:feature_names"], + deps = [ + ":toolchain_utils", + "//swift/internal:feature_names", + ], ) bzl_library( diff --git a/swift/internal/swift_autoconfiguration.bzl b/swift/internal/swift_autoconfiguration.bzl index 38a72019a..2f067b4f0 100644 --- a/swift/internal/swift_autoconfiguration.bzl +++ b/swift/internal/swift_autoconfiguration.bzl @@ -25,7 +25,7 @@ Skylib. """ load( - "//swift/internal:feature_names.bzl", + ":feature_names.bzl", "SWIFT_FEATURE_CODEVIEW_DEBUG_INFO", "SWIFT_FEATURE_DEBUG_PREFIX_MAP", "SWIFT_FEATURE_EMIT_SWIFTDOC", @@ -41,6 +41,7 @@ load( "SWIFT_FEATURE_USE_MODULE_WRAP", "SWIFT_FEATURE_USE_OLD_DRIVER", ) +load(":toolchain_utils.bzl", "SWIFT_TOOLCHAIN_TYPE") def _scratch_file(repository_ctx, temp_dir, name, content = ""): """Creates and returns a scratch file with the given name and content. @@ -237,6 +238,10 @@ def _create_linux_toolchain(repository_ctx): repository_ctx.file( "BUILD", """ +load( + "@build_bazel_apple_support//configs:platforms.bzl", + "APPLE_PLATFORMS_CONSTRAINTS", +) load( "@build_bazel_rules_swift//swift/toolchains:swift_toolchain.bzl", "swift_toolchain", @@ -252,6 +257,21 @@ swift_toolchain( root = "{root}", version_file = "{version_file}", ) + +[ + toolchain( + name = "xcode-toolchain-" + arch + "-{cpu}", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:{cpu}", + ], + target_compatible_with = APPLE_PLATFORMS_CONSTRAINTS[arch], + toolchain = ":toolchain", + toolchain_type = "{toolchain_type}", + visibility = ["//visibility:public"], + ) + for arch in APPLE_PLATFORMS_CONSTRAINTS.keys() +] """.format( cpu = _normalized_linux_cpu(repository_ctx.os.arch), feature_list = ", ".join([ @@ -259,6 +279,7 @@ swift_toolchain( for feature in feature_values ]), root = root, + toolchain_type = SWIFT_TOOLCHAIN_TYPE, version_file = version_file, ), ) @@ -279,6 +300,10 @@ def _create_xcode_toolchain(repository_ctx): repository_ctx.file( "BUILD", """ +load( + "@build_bazel_apple_support//configs:platforms.bzl", + "APPLE_PLATFORMS_CONSTRAINTS", +) load( "@build_bazel_rules_swift//swift/toolchains:xcode_swift_toolchain.bzl", "xcode_swift_toolchain", @@ -286,15 +311,37 @@ load( package(default_visibility = ["//visibility:public"]) +_OSX_DEVELOPER_PLATFORM_CPUS = [ + "arm64", + "x86_64", +] + xcode_swift_toolchain( name = "toolchain", features = [{feature_list}], ) + +[ + toolchain( + name = "xcode-toolchain-" + arch + "-" + cpu, + exec_compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:" + cpu, + ], + target_compatible_with = APPLE_PLATFORMS_CONSTRAINTS[arch], + toolchain = ":toolchain", + toolchain_type = "{toolchain_type}", + visibility = ["//visibility:public"], + ) + for arch in APPLE_PLATFORMS_CONSTRAINTS.keys() + for cpu in _OSX_DEVELOPER_PLATFORM_CPUS +] """.format( feature_list = ", ".join([ '"{}"'.format(feature) for feature in feature_values ]), + toolchain_type = SWIFT_TOOLCHAIN_TYPE, ), ) @@ -345,6 +392,10 @@ def _create_windows_toolchain(repository_ctx): repository_ctx.file( "BUILD", """ +load( + "@build_bazel_apple_support//configs:platforms.bzl", + "APPLE_PLATFORMS_CONSTRAINTS", +) load( "@build_bazel_rules_swift//swift/toolchains:swift_toolchain.bzl", "swift_toolchain", @@ -364,11 +415,27 @@ swift_toolchain( tool_executable_suffix = ".exe", xctest_version = "{xctest_version}", ) + +[ + toolchain( + name = "windows-toolchain-" + arch + "-x86_64", + exec_compatible_with = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], + target_compatible_with = APPLE_PLATFORMS_CONSTRAINTS[arch], + toolchain = ":toolchain", + toolchain_type = "{toolchain_type}", + visibility = ["//visibility:public"], + ) + for arch in APPLE_PLATFORMS_CONSTRAINTS.keys() +] """.format( features = ", ".join(['"{}"'.format(feature) for feature in enabled_features] + ['"-{}"'.format(feature) for feature in disabled_features]), root = root, env = env, sdkroot = repository_ctx.os.environ["SDKROOT"].replace("\\", "/"), + toolchain_type = SWIFT_TOOLCHAIN_TYPE, xctest_version = xctest_version.stdout.rstrip(), version_file = version_file, ), diff --git a/toolchains/BUILD b/toolchains/BUILD new file mode 100644 index 000000000..c6d09a29f --- /dev/null +++ b/toolchains/BUILD @@ -0,0 +1,4 @@ +toolchain_type( + name = "toolchain_type", + visibility = ["//visibility:public"], +)