Skip to content

Commit

Permalink
Add toolchains (#1321)
Browse files Browse the repository at this point in the history
These can be used once we flip the ruleset to actual return the
toolchain type from `use_swift_toolchain()`.

Signed-off-by: Brentley Jones <github@brentleyjones.com>
  • Loading branch information
brentleyjones authored Oct 1, 2024
1 parent 586ba7a commit cfd4b6d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
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"],
)

0 comments on commit cfd4b6d

Please sign in to comment.