@@ -25,6 +25,7 @@ Skylib.
25
25
"""
26
26
27
27
load ("@bazel_tools//tools/cpp:unix_cc_configure.bzl" , "configure_unix_toolchain" )
28
+ load ("@bazel_tools//tools/cpp:windows_cc_configure.bzl" , "configure_windows_toolchain" )
28
29
load (
29
30
"@bazel_tools//tools/cpp:lib_cc_configure.bzl" ,
30
31
"get_cpu_value" ,
@@ -261,12 +262,33 @@ def _normalized_linux_cpu(cpu):
261
262
return "x86_64"
262
263
return cpu
263
264
264
- def _create_linux_cc_toolchain (repository_ctx ):
265
+ def _toolchain_root (repository_ctx ):
265
266
path_to_swiftc = repository_ctx .which ("swiftc" )
266
267
if not path_to_swiftc :
267
268
fail ("No 'swiftc' executable found in $PATH" )
269
+ return path_to_swiftc .dirname
270
+
271
+ def _create_xcode_cc_toolchain (repository_ctx ):
272
+ """Creates BUILD alias for the C++ toolchain provided by apple_support
273
+
274
+ Args:
275
+ repository_ctx: The repository rule context.
276
+ """ create_windows_toolchain ("BUILD" , """
277
+ alias(
278
+ name = "toolchain",
279
+ actual = "@local_config_apple_cc//:toolchain",
280
+ visibility = ["//visibility:public"]
281
+ )
282
+ """ )
268
283
269
- toolchain_root = path_to_swiftc .dirname
284
+ def _create_linux_cc_toolchain (repository_ctx ):
285
+ """Creates BUILD targets for the Swift-provided C++ toolchain on Linux.
286
+
287
+ Args:
288
+ repository_ctx: The repository rule context.
289
+ """
290
+
291
+ toolchain_root = _toolchain_root (repository_ctx )
270
292
cpu = get_cpu_value (repository_ctx )
271
293
configure_unix_toolchain (repository_ctx , cpu , overriden_tools = {
272
294
"ar" : toolchain_root .get_child ("llvm-ar" ),
@@ -277,6 +299,23 @@ def _create_linux_cc_toolchain(repository_ctx):
277
299
"gcc" : toolchain_root .get_child ("clang" ),
278
300
})
279
301
302
+ def _create_windows_cc_toolchain (repository_ctx ):
303
+ """Creates BUILD targets for the Swift-provided C++ toolchain on Windows.
304
+
305
+ Args:
306
+ repository_ctx: The repository rule context.
307
+ """
308
+
309
+ toolchain_root = _toolchain_root (repository_ctx )
310
+ configure_windows_toolchain (repository_ctx , overriden_tools = {
311
+ "ar" : toolchain_root .get_child ("llvm-ar.exe" ),
312
+ "ld" : toolchain_root .get_child ("lld.exe" ),
313
+ "llvm-cov" : toolchain_root .get_child ("llvm-cov.exe" ),
314
+ "llvm-profdata" : toolchain_root .get_child ("llvm-profdata.exe" ),
315
+ "cpp" : toolchain_root .get_child ("clang-cpp.exe" ),
316
+ "gcc" : toolchain_root .get_child ("clang.exe" ),
317
+ })
318
+
280
319
def _create_linux_toolchain (repository_ctx ):
281
320
"""Creates BUILD targets for the Swift toolchain on Linux.
282
321
@@ -287,7 +326,7 @@ def _create_linux_toolchain(repository_ctx):
287
326
if not path_to_swiftc :
288
327
fail ("No 'swiftc' executable found in $PATH" )
289
328
290
- toolchain_root = path_to_swiftc . dirname
329
+ toolchain_root = _toolchain_root ( repository_ctx )
291
330
root = path_to_swiftc .dirname .dirname
292
331
feature_values = _compute_feature_values (repository_ctx , path_to_swiftc )
293
332
version_file = _write_swift_version (repository_ctx , path_to_swiftc )
@@ -313,11 +352,6 @@ load(
313
352
314
353
package(default_visibility = ["//visibility:public"])
315
354
316
- alias(
317
- name = "swift_cc_toolchain",
318
- actual = "@build_bazel_rules_swift_local_cc_config//:toolchain"
319
- )
320
-
321
355
swift_toolchain(
322
356
name = "toolchain",
323
357
arch = "{cpu}",
@@ -427,12 +461,6 @@ load(
427
461
428
462
package(default_visibility = ["//visibility:public"])
429
463
430
- # Use the system C++ toolchain
431
- alias(
432
- name = "swift_cc_toolchain",
433
- actual = "@bazel_tools//tools/cpp:current_cc_toolchain"
434
- )
435
-
436
464
swift_toolchain(
437
465
name = "toolchain",
438
466
arch = "x86_64",
@@ -457,10 +485,12 @@ swift_toolchain(
457
485
458
486
def _swift_cc_autoconfiguration_impl (repository_ctx ):
459
487
os_name = repository_ctx .os .name .lower ()
460
- if os_name .startswith ("linux" ):
461
- _create_linux_cc_toolchain (repository_ctx )
488
+ if os_name .startswith ("mac os" ):
489
+ _create_xcode_cc_toolchain (repository_ctx )
490
+ elif os_name .startswith ("windows" ):
491
+ _create_windows_cc_toolchain (repository_ctx )
462
492
else :
463
- fail ( "cc_toolchain detection for Swift is currently only supported on Linux" )
493
+ _create_linux_cc_toolchain ( repository_ctx )
464
494
465
495
def _swift_autoconfiguration_impl (repository_ctx ):
466
496
# TODO(allevato): This is expedient and fragile. Use the
0 commit comments