Skip to content

Commit 737b285

Browse files
committed
Fix _cc_toolchain attribute values
1 parent 5e6c76b commit 737b285

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

MODULE.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ use_repo(apple_cc_configure, "local_config_apple_cc")
3535
# Dev dependencies
3636
bazel_dep(name = "stardoc", version = "0.5.3", dev_dependency = True, repo_name = "io_bazel_stardoc")
3737

38-
register_toolchains("@build_bazel_rules_swift_cc_toolchain//:all")
38+
register_toolchains("@build_bazel_rules_swift_local_cc_config//:all")

swift/internal/swift_autoconfiguration.bzl

+47-17
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Skylib.
2525
"""
2626

2727
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")
2829
load(
2930
"@bazel_tools//tools/cpp:lib_cc_configure.bzl",
3031
"get_cpu_value",
@@ -261,12 +262,33 @@ def _normalized_linux_cpu(cpu):
261262
return "x86_64"
262263
return cpu
263264

264-
def _create_linux_cc_toolchain(repository_ctx):
265+
def _toolchain_root(repository_ctx):
265266
path_to_swiftc = repository_ctx.which("swiftc")
266267
if not path_to_swiftc:
267268
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+
""")
268283

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)
270292
cpu = get_cpu_value(repository_ctx)
271293
configure_unix_toolchain(repository_ctx, cpu, overriden_tools = {
272294
"ar": toolchain_root.get_child("llvm-ar"),
@@ -277,6 +299,23 @@ def _create_linux_cc_toolchain(repository_ctx):
277299
"gcc": toolchain_root.get_child("clang"),
278300
})
279301

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+
280319
def _create_linux_toolchain(repository_ctx):
281320
"""Creates BUILD targets for the Swift toolchain on Linux.
282321
@@ -287,7 +326,7 @@ def _create_linux_toolchain(repository_ctx):
287326
if not path_to_swiftc:
288327
fail("No 'swiftc' executable found in $PATH")
289328

290-
toolchain_root = path_to_swiftc.dirname
329+
toolchain_root = _toolchain_root(repository_ctx)
291330
root = path_to_swiftc.dirname.dirname
292331
feature_values = _compute_feature_values(repository_ctx, path_to_swiftc)
293332
version_file = _write_swift_version(repository_ctx, path_to_swiftc)
@@ -313,11 +352,6 @@ load(
313352
314353
package(default_visibility = ["//visibility:public"])
315354
316-
alias(
317-
name = "swift_cc_toolchain",
318-
actual = "@build_bazel_rules_swift_local_cc_config//:toolchain"
319-
)
320-
321355
swift_toolchain(
322356
name = "toolchain",
323357
arch = "{cpu}",
@@ -427,12 +461,6 @@ load(
427461
428462
package(default_visibility = ["//visibility:public"])
429463
430-
# Use the system C++ toolchain
431-
alias(
432-
name = "swift_cc_toolchain",
433-
actual = "@bazel_tools//tools/cpp:current_cc_toolchain"
434-
)
435-
436464
swift_toolchain(
437465
name = "toolchain",
438466
arch = "x86_64",
@@ -457,10 +485,12 @@ swift_toolchain(
457485

458486
def _swift_cc_autoconfiguration_impl(repository_ctx):
459487
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)
462492
else:
463-
fail("cc_toolchain detection for Swift is currently only supported on Linux")
493+
_create_linux_cc_toolchain(repository_ctx)
464494

465495
def _swift_autoconfiguration_impl(repository_ctx):
466496
# TODO(allevato): This is expedient and fragile. Use the

swift/internal/swift_import.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ The `.swiftmodule` file provided to Swift targets that depend on this target.
172172
mandatory = False,
173173
),
174174
"_cc_toolchain": attr.label(
175-
default = Label("@build_bazel_rules_swift_local_config//:swift_cc_toolchain"),
175+
default = Label("@build_bazel_rules_swift_local_cc_config//:toolchain"),
176176
doc = """\
177177
The C++ toolchain from which linking flags and other tools needed by the Swift
178178
toolchain (such as `clang`) will be retrieved.

swift/internal/swift_toolchain.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ configuration options that are applied to targets on a per-package basis.
432432
allow_single_file = True,
433433
),
434434
"_cc_toolchain": attr.label(
435-
default = Label("@build_bazel_rules_swift_local_config//:swift_cc_toolchain"),
435+
default = Label("@build_bazel_rules_swift_local_cc_config//:toolchain"),
436436
doc = """\
437437
The C++ toolchain from which other tools needed by the Swift toolchain (such as
438438
`clang` and `ar`) will be retrieved.

swift/internal/xcode_swift_toolchain.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ configuration options that are applied to targets on a per-package basis.
779779
providers = [[SwiftPackageConfigurationInfo]],
780780
),
781781
"_cc_toolchain": attr.label(
782-
default = Label("@build_bazel_rules_swift_local_config//:swift_cc_toolchain"),
782+
default = Label("@build_bazel_rules_swift_local_cc_config//:toolchain"),
783783
doc = """\
784784
The C++ toolchain from which linking flags and other tools needed by the Swift
785785
toolchain (such as `clang`) will be retrieved.

0 commit comments

Comments
 (0)