Skip to content

Commit e8917c3

Browse files
committed
Add toolchains
These can be used once we flip the ruleset to actual return the toolchain type from `use_swift_toolchain()`. Signed-off-by: Brentley Jones <[email protected]>
1 parent 24f42ed commit e8917c3

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

swift/internal/BUILD

+4-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ bzl_library(
202202
name = "swift_autoconfiguration",
203203
srcs = ["swift_autoconfiguration.bzl"],
204204
visibility = ["//swift:__subpackages__"],
205-
deps = ["//swift/internal:feature_names"],
205+
deps = [
206+
":toolchain_utils",
207+
"//swift/internal:feature_names",
208+
],
206209
)
207210

208211
bzl_library(

swift/internal/swift_autoconfiguration.bzl

+68-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Skylib.
2525
"""
2626

2727
load(
28-
"//swift/internal:feature_names.bzl",
28+
":feature_names.bzl",
2929
"SWIFT_FEATURE_CODEVIEW_DEBUG_INFO",
3030
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
3131
"SWIFT_FEATURE_EMIT_SWIFTDOC",
@@ -41,6 +41,7 @@ load(
4141
"SWIFT_FEATURE_USE_MODULE_WRAP",
4242
"SWIFT_FEATURE_USE_OLD_DRIVER",
4343
)
44+
load(":toolchain_utils.bzl", "SWIFT_TOOLCHAIN_TYPE")
4445

4546
def _scratch_file(repository_ctx, temp_dir, name, content = ""):
4647
"""Creates and returns a scratch file with the given name and content.
@@ -237,6 +238,10 @@ def _create_linux_toolchain(repository_ctx):
237238
repository_ctx.file(
238239
"BUILD",
239240
"""
241+
load(
242+
"@build_bazel_apple_support//configs:platforms.bzl",
243+
"APPLE_PLATFORMS_CONSTRAINTS",
244+
)
240245
load(
241246
"@build_bazel_rules_swift//swift/toolchains:swift_toolchain.bzl",
242247
"swift_toolchain",
@@ -252,13 +257,29 @@ swift_toolchain(
252257
root = "{root}",
253258
version_file = "{version_file}",
254259
)
260+
261+
[
262+
toolchain(
263+
name = "xcode-toolchain-" + arch + "-{cpu}",
264+
exec_compatible_with = [
265+
"@platforms//os:linux",
266+
"@platforms//cpu:{cpu}",
267+
],
268+
target_compatible_with = APPLE_PLATFORMS_CONSTRAINTS[arch],
269+
toolchain = ":toolchain",
270+
toolchain_type = "{toolchain_type}",
271+
visibility = ["//visibility:public"],
272+
)
273+
for arch in APPLE_PLATFORMS_CONSTRAINTS.keys()
274+
]
255275
""".format(
256276
cpu = _normalized_linux_cpu(repository_ctx.os.arch),
257277
feature_list = ", ".join([
258278
'"{}"'.format(feature)
259279
for feature in feature_values
260280
]),
261281
root = root,
282+
toolchain_type = SWIFT_TOOLCHAIN_TYPE,
262283
version_file = version_file,
263284
),
264285
)
@@ -279,22 +300,48 @@ def _create_xcode_toolchain(repository_ctx):
279300
repository_ctx.file(
280301
"BUILD",
281302
"""
303+
load(
304+
"@build_bazel_apple_support//configs:platforms.bzl",
305+
"APPLE_PLATFORMS_CONSTRAINTS",
306+
)
282307
load(
283308
"@build_bazel_rules_swift//swift/toolchains:xcode_swift_toolchain.bzl",
284309
"xcode_swift_toolchain",
285310
)
286311
287312
package(default_visibility = ["//visibility:public"])
288313
314+
_OSX_DEVELOPER_PLATFORM_CPUS = [
315+
"arm64",
316+
"x86_64",
317+
]
318+
289319
xcode_swift_toolchain(
290320
name = "toolchain",
291321
features = [{feature_list}],
292322
)
323+
324+
[
325+
toolchain(
326+
name = "xcode-toolchain-" + arch + "-" + cpu,
327+
exec_compatible_with = [
328+
"@platforms//os:macos",
329+
"@platforms//cpu:" + cpu,
330+
],
331+
target_compatible_with = APPLE_PLATFORMS_CONSTRAINTS[arch],
332+
toolchain = ":toolchain",
333+
toolchain_type = "{toolchain_type}",
334+
visibility = ["//visibility:public"],
335+
)
336+
for arch in APPLE_PLATFORMS_CONSTRAINTS.keys()
337+
for cpu in _OSX_DEVELOPER_PLATFORM_CPUS
338+
]
293339
""".format(
294340
feature_list = ", ".join([
295341
'"{}"'.format(feature)
296342
for feature in feature_values
297343
]),
344+
toolchain_type = SWIFT_TOOLCHAIN_TYPE,
298345
),
299346
)
300347

@@ -345,6 +392,10 @@ def _create_windows_toolchain(repository_ctx):
345392
repository_ctx.file(
346393
"BUILD",
347394
"""
395+
load(
396+
"@build_bazel_apple_support//configs:platforms.bzl",
397+
"APPLE_PLATFORMS_CONSTRAINTS",
398+
)
348399
load(
349400
"@build_bazel_rules_swift//swift/toolchains:swift_toolchain.bzl",
350401
"swift_toolchain",
@@ -364,11 +415,27 @@ swift_toolchain(
364415
tool_executable_suffix = ".exe",
365416
xctest_version = "{xctest_version}",
366417
)
418+
419+
[
420+
toolchain(
421+
name = "windows-toolchain-" + arch + "-x86_64",
422+
exec_compatible_with = [
423+
"@platforms//os:windows",
424+
"@platforms//cpu:x86_64",
425+
],
426+
target_compatible_with = APPLE_PLATFORMS_CONSTRAINTS[arch],
427+
toolchain = ":toolchain",
428+
toolchain_type = "{toolchain_type}",
429+
visibility = ["//visibility:public"],
430+
)
431+
for arch in APPLE_PLATFORMS_CONSTRAINTS.keys()
432+
]
367433
""".format(
368434
features = ", ".join(['"{}"'.format(feature) for feature in enabled_features] + ['"-{}"'.format(feature) for feature in disabled_features]),
369435
root = root,
370436
env = env,
371437
sdkroot = repository_ctx.os.environ["SDKROOT"].replace("\\", "/"),
438+
toolchain_type = SWIFT_TOOLCHAIN_TYPE,
372439
xctest_version = xctest_version.stdout.rstrip(),
373440
version_file = version_file,
374441
),

toolchains/BUILD

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
toolchain_type(
2+
name = "toolchain_type",
3+
visibility = ["//visibility:public"],
4+
)

0 commit comments

Comments
 (0)