Skip to content

Commit

Permalink
Cherry-pick Swift toolchain changes from upstream
Browse files Browse the repository at this point in the history
73b248d and cba3ae0.

Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
allevato authored and brentleyjones committed Feb 4, 2025
1 parent b8651b6 commit cc3fd7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
18 changes: 12 additions & 6 deletions apple/internal/apple_framework_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ load(
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"SwiftToolchainInfo",
"swift_clang_module_aspect",
"swift_common",
)
Expand Down Expand Up @@ -78,6 +77,10 @@ load(
"AppleFrameworkImportBundleInfo",
)

# The name of the execution group that houses the Swift toolchain and is used to
# run Swift actions.
_SWIFT_EXEC_GROUP = "swift"

def _swiftmodule_for_cpu(swiftmodule_files, cpu):
"""Select the cpu specific swiftmodule."""

Expand Down Expand Up @@ -255,7 +258,7 @@ def _apple_dynamic_framework_import_impl(ctx):

if "apple._import_framework_via_swiftinterface" in features and framework.swift_interface_imports:
# Create SwiftInfo provider
swift_toolchain = ctx.attr._swift_toolchain[SwiftToolchainInfo]
swift_toolchain = swift_common.get_toolchain(ctx, exec_group = _SWIFT_EXEC_GROUP)
swiftinterface_files = framework_import_support.get_swift_module_files_with_target_triplet(
swift_module_files = framework.swift_interface_imports,
target_triplet = target_triplet,
Expand Down Expand Up @@ -321,7 +324,7 @@ def _apple_static_framework_import_impl(ctx):
additional_objc_providers = []
additional_objc_provider_fields = {}
if framework.swift_interface_imports or framework.swift_module_imports or has_swift:
toolchain = ctx.attr._swift_toolchain[SwiftToolchainInfo]
toolchain = swift_common.get_toolchain(ctx, exec_group = _SWIFT_EXEC_GROUP)
providers.append(SwiftUsageInfo())

# The Swift toolchain propagates Swift-specific linker flags (e.g.,
Expand Down Expand Up @@ -390,7 +393,7 @@ def _apple_static_framework_import_impl(ctx):

if "apple._import_framework_via_swiftinterface" in features and framework.swift_interface_imports:
# Create SwiftInfo provider
swift_toolchain = ctx.attr._swift_toolchain[SwiftToolchainInfo]
swift_toolchain = swift_common.get_toolchain(ctx, exec_group = _SWIFT_EXEC_GROUP)
swiftinterface_files = framework_import_support.get_swift_module_files_with_target_triplet(
swift_module_files = framework.swift_interface_imports,
target_triplet = target_triplet,
Expand Down Expand Up @@ -429,7 +432,6 @@ apple_dynamic_framework_import = rule(
fragments = ["cpp"],
attrs = dicts.add(
rule_attrs.common_tool_attrs(),
swift_common.toolchain_attrs(toolchain_attr_name = "_swift_toolchain"),
{
"framework_imports": attr.label_list(
allow_empty = False,
Expand Down Expand Up @@ -499,7 +501,6 @@ apple_static_framework_import = rule(
fragments = ["cpp", "objc"],
attrs = dicts.add(
rule_attrs.common_tool_attrs(),
swift_common.toolchain_attrs(toolchain_attr_name = "_swift_toolchain"),
{
"framework_imports": attr.label_list(
allow_empty = False,
Expand Down Expand Up @@ -576,6 +577,11 @@ not include Swift interface or Swift module files.
),
},
),
exec_groups = {
_SWIFT_EXEC_GROUP: exec_group(
toolchains = swift_common.use_toolchain(),
),
},
toolchains = use_cpp_toolchain(),
doc = """
This rule encapsulates an already-built static framework. It is defined by a list of
Expand Down
21 changes: 17 additions & 4 deletions apple/internal/apple_xcframework_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
load("@build_bazel_apple_support//lib:apple_support.bzl", "apple_support")
load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftToolchainInfo", "swift_clang_module_aspect", "swift_common")
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"swift_clang_module_aspect",
"swift_common",
)
load("//apple:providers.bzl", "AppleFrameworkImportInfo")
load(
"//apple/internal:apple_toolchains.bzl",
Expand Down Expand Up @@ -57,6 +61,10 @@ load(
# This defines an _enum_ to identify an imported XCFramework bundle type.
_BUNDLE_TYPE = struct(frameworks = 1, libraries = 2)

# The name of the execution group that houses the Swift toolchain and is used to
# run Swift actions.
_SWIFT_EXEC_GROUP = "swift"

def _classify_xcframework_imports(config_vars, xcframework_imports):
"""Classifies XCFramework files for later processing.
Expand Down Expand Up @@ -557,7 +565,7 @@ def _apple_dynamic_xcframework_import_impl(ctx):

if "apple._import_framework_via_swiftinterface" in features and xcframework_library.swift_module_interface:
# Create SwiftInfo provider
swift_toolchain = ctx.attr._toolchain[SwiftToolchainInfo]
swift_toolchain = swift_common.get_toolchain(ctx, exec_group = _SWIFT_EXEC_GROUP)
providers.append(
framework_import_support.swift_info_from_module_interface(
actions = actions,
Expand Down Expand Up @@ -634,7 +642,7 @@ def _apple_static_xcframework_import_impl(ctx):
if xcframework.files_by_category.swift_interface_imports or \
xcframework.files_by_category.swift_module_imports or \
has_swift:
swift_toolchain = ctx.attr._toolchain[SwiftToolchainInfo]
swift_toolchain = swift_common.get_toolchain(ctx, exec_group = _SWIFT_EXEC_GROUP)
providers.append(SwiftUsageInfo())

# The Swift toolchain propagates Swift-specific linker flags (e.g.,
Expand Down Expand Up @@ -688,7 +696,7 @@ def _apple_static_xcframework_import_impl(ctx):

if "apple._import_framework_via_swiftinterface" in features and xcframework_library.swift_module_interface:
# Create SwiftInfo provider
swift_toolchain = ctx.attr._toolchain[SwiftToolchainInfo]
swift_toolchain = swift_common.get_toolchain(ctx, exec_group = _SWIFT_EXEC_GROUP)
providers.append(
framework_import_support.swift_info_from_module_interface(
actions = actions,
Expand Down Expand Up @@ -784,6 +792,11 @@ Unnecssary and ignored, will be removed in the future.
),
},
),
exec_groups = {
_SWIFT_EXEC_GROUP: exec_group(
toolchains = swift_common.use_toolchain(),
),
},
fragments = ["apple", "cpp"],
provides = [
AppleFrameworkImportInfo,
Expand Down

0 comments on commit cc3fd7f

Please sign in to comment.