Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toolchains #1321

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion swift/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
69 changes: 68 additions & 1 deletion swift/internal/swift_autoconfiguration.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.
Expand Down Expand Up @@ -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",
Expand All @@ -252,13 +257,29 @@ 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([
'"{}"'.format(feature)
for feature in feature_values
]),
root = root,
toolchain_type = SWIFT_TOOLCHAIN_TYPE,
version_file = version_file,
),
)
Expand All @@ -279,22 +300,48 @@ 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",
)

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,
),
)

Expand Down Expand Up @@ -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",
Expand All @@ -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,
),
Expand Down
4 changes: 4 additions & 0 deletions toolchains/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
toolchain_type(
name = "toolchain_type",
visibility = ["//visibility:public"],
)