@@ -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,35 @@ 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
268
273
269
- toolchain_root = path_to_swiftc .dirname
274
+ Args:
275
+ repository_ctx: The repository rule context.
276
+ """
277
+
278
+ repository_ctx .file ("BUILD" , """
279
+ alias(
280
+ name = "toolchain",
281
+ actual = "@local_config_apple_cc//:toolchain",
282
+ visibility = ["//visibility:public"]
283
+ )
284
+ """ )
285
+
286
+ def _create_linux_cc_toolchain (repository_ctx ):
287
+ """Creates BUILD targets for the Swift-provided C++ toolchain on Linux.
288
+
289
+ Args:
290
+ repository_ctx: The repository rule context.
291
+ """
292
+
293
+ toolchain_root = _toolchain_root (repository_ctx )
270
294
cpu = get_cpu_value (repository_ctx )
271
295
configure_unix_toolchain (repository_ctx , cpu , overriden_tools = {
272
296
"ar" : toolchain_root .get_child ("llvm-ar" ),
@@ -277,6 +301,23 @@ def _create_linux_cc_toolchain(repository_ctx):
277
301
"gcc" : toolchain_root .get_child ("clang" ),
278
302
})
279
303
304
+ def _create_windows_cc_toolchain (repository_ctx ):
305
+ """Creates BUILD targets for the Swift-provided C++ toolchain on Windows.
306
+
307
+ Args:
308
+ repository_ctx: The repository rule context.
309
+ """
310
+
311
+ toolchain_root = _toolchain_root (repository_ctx )
312
+ configure_windows_toolchain (repository_ctx , overriden_tools = {
313
+ "ar" : toolchain_root .get_child ("llvm-ar.exe" ),
314
+ "ld" : toolchain_root .get_child ("lld.exe" ),
315
+ "llvm-cov" : toolchain_root .get_child ("llvm-cov.exe" ),
316
+ "llvm-profdata" : toolchain_root .get_child ("llvm-profdata.exe" ),
317
+ "cpp" : toolchain_root .get_child ("clang-cpp.exe" ),
318
+ "gcc" : toolchain_root .get_child ("clang.exe" ),
319
+ })
320
+
280
321
def _create_linux_toolchain (repository_ctx ):
281
322
"""Creates BUILD targets for the Swift toolchain on Linux.
282
323
@@ -287,7 +328,7 @@ def _create_linux_toolchain(repository_ctx):
287
328
if not path_to_swiftc :
288
329
fail ("No 'swiftc' executable found in $PATH" )
289
330
290
- toolchain_root = path_to_swiftc . dirname
331
+ toolchain_root = _toolchain_root ( repository_ctx )
291
332
root = path_to_swiftc .dirname .dirname
292
333
feature_values = _compute_feature_values (repository_ctx , path_to_swiftc )
293
334
version_file = _write_swift_version (repository_ctx , path_to_swiftc )
@@ -313,11 +354,6 @@ load(
313
354
314
355
package(default_visibility = ["//visibility:public"])
315
356
316
- alias(
317
- name = "swift_cc_toolchain",
318
- actual = "@build_bazel_rules_swift_local_cc_config//:toolchain"
319
- )
320
-
321
357
swift_toolchain(
322
358
name = "toolchain",
323
359
arch = "{cpu}",
@@ -427,12 +463,6 @@ load(
427
463
428
464
package(default_visibility = ["//visibility:public"])
429
465
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
466
swift_toolchain(
437
467
name = "toolchain",
438
468
arch = "x86_64",
@@ -457,10 +487,12 @@ swift_toolchain(
457
487
458
488
def _swift_cc_autoconfiguration_impl (repository_ctx ):
459
489
os_name = repository_ctx .os .name .lower ()
460
- if os_name .startswith ("linux" ):
461
- _create_linux_cc_toolchain (repository_ctx )
490
+ if os_name .startswith ("mac os" ):
491
+ _create_xcode_cc_toolchain (repository_ctx )
492
+ elif os_name .startswith ("windows" ):
493
+ _create_windows_cc_toolchain (repository_ctx )
462
494
else :
463
- fail ( "cc_toolchain detection for Swift is currently only supported on Linux" )
495
+ _create_linux_cc_toolchain ( repository_ctx )
464
496
465
497
def _swift_autoconfiguration_impl (repository_ctx ):
466
498
# TODO(allevato): This is expedient and fragile. Use the
0 commit comments