Skip to content

Commit

Permalink
Enable linking of imported Swift static frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
kastiglione committed Sep 5, 2019
1 parent 69c2104 commit 0534a12
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions apple/internal/apple_framework_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

"""Implementation of framework import rules."""

load(
"@bazel_skylib//lib:dicts.bzl",
"dicts",
)
load(
"@bazel_skylib//lib:partial.bzl",
"partial",
Expand All @@ -34,6 +38,11 @@ load(
"@build_bazel_rules_apple//apple:utils.bzl",
"group_files_by_directory",
)
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"SwiftToolchainInfo",
"swift_common",
)

AppleFrameworkImportInfo = provider(
doc = "Provider that propagates information about framework import targets.",
Expand All @@ -45,6 +54,10 @@ application bundle under the Frameworks directory.
},
)

def _is_swiftmodule(path):
"""Predicate to identify Swift modules/interfaces."""
return path.endswith(".swiftmodule") or path.endswith(".swiftinterface")

def _classify_framework_imports(framework_imports):
"""Classify a list of framework files into bundling, header, or module_map."""

Expand All @@ -63,7 +76,7 @@ def _classify_framework_imports(framework_imports):
# This matches /Headers/ and /PrivateHeaders/
header_imports.append(file)
continue
if file_short_path.endswith(".swiftmodule") or file_short_path.endswith(".swiftinterface"):
if _is_swiftmodule(file_short_path):
# Add Swift's module files to header_imports so that they are correctly included in the build
# by Bazel but they aren't processed in any way
header_imports.append(file)
Expand Down Expand Up @@ -223,6 +236,17 @@ def _apple_static_framework_import_impl(ctx):
if ctx.attr.weak_sdk_frameworks:
objc_provider_fields["weak_sdk_framework"] = depset(ctx.attr.weak_sdk_frameworks)

imported_swiftmodules = [
f
for f in header_imports
if _is_swiftmodule(f.basename)
]

if imported_swiftmodules:
swift_toolchain = ctx.attr._toolchain[SwiftToolchainInfo]
swift_linkopts = swift_common.swift_runtime_linkopts(True, swift_toolchain)
objc_provider_fields["linkopt"] = depset(swift_linkopts)

providers.append(_objc_provider_with_dependencies(ctx, objc_provider_fields))

bundle_files = [x for x in framework_imports if ".bundle/" in x.short_path]
Expand Down Expand Up @@ -272,7 +296,7 @@ targets through the `deps` attribute.

apple_static_framework_import = rule(
implementation = _apple_static_framework_import_impl,
attrs = {
attrs = dicts.add(swift_common.toolchain_attrs(), {
"framework_imports": attr.label_list(
allow_empty = False,
allow_files = True,
Expand Down Expand Up @@ -323,7 +347,7 @@ runtime checks for protocol conformances added in extensions in the library but
reference any other symbols in the object file that adds that conformance.
""",
),
},
}),
doc = """
This rule encapsulates an already-built static framework. It is defined by a list of files in a
.framework directory. apple_static_framework_import targets need to be added to library targets
Expand Down

0 comments on commit 0534a12

Please sign in to comment.