Skip to content

Commit 7146603

Browse files
authored
Update for rules_swift 3.0 (#945)
Signed-off-by: Luis Padron <lpadron@squareup.com>
1 parent 9d33c7a commit 7146603

File tree

7 files changed

+35
-37
lines changed

7 files changed

+35
-37
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
env:
2929
XCODE_VERSION: ${{ matrix.xcode_version }}
3030
USE_BAZEL_VERSION: ${{ matrix.bazel_version }}
31-
LATEST_RULES_SWIFT_VERSION: 2.1.1
32-
LATEST_RULES_APPLE_VERSION: 3.15.0
31+
LATEST_RULES_SWIFT_VERSION: 3.0.2
32+
LATEST_RULES_APPLE_VERSION: 4.0.1
3333
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3434
steps:
3535
- uses: actions/checkout@v4

MODULE.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bazel_dep(
2222
)
2323
bazel_dep(
2424
name = "rules_apple",
25-
version = "3.15.0",
25+
version = "4.0.1",
2626
repo_name = "build_bazel_rules_apple",
2727
)
2828
bazel_dep(
@@ -31,8 +31,8 @@ bazel_dep(
3131
)
3232
bazel_dep(
3333
name = "rules_swift",
34-
version = "1.18.0",
35-
max_compatibility_level = 2,
34+
version = "3.0.2",
35+
max_compatibility_level = 3,
3636
repo_name = "build_bazel_rules_swift",
3737
)
3838
bazel_dep(

rules/framework.bzl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ load("@build_bazel_rules_apple//apple/internal:apple_toolchains.bzl", "AppleMacT
2525
load("@build_bazel_rules_apple//apple/internal:swift_support.bzl", "swift_support")
2626
load("@build_bazel_rules_apple//apple/internal/utils:clang_rt_dylibs.bzl", "clang_rt_dylibs")
2727
load("@build_bazel_rules_apple//apple/internal:providers.bzl", "AppleBundleInfo", "ApplePlatformInfo", "IosFrameworkBundleInfo", "new_applebundleinfo", "new_iosframeworkbundleinfo")
28-
load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftInfo", "swift_clang_module_aspect", "swift_common")
28+
load("@build_bazel_rules_swift//swift:providers.bzl", "SwiftInfo", "create_clang_module_inputs", "create_swift_module_context", "create_swift_module_inputs")
29+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_clang_module_aspect")
2930
load(
3031
"@build_bazel_rules_apple//apple/internal/aspects:resource_aspect.bzl",
3132
"apple_resource_aspect",
@@ -558,7 +559,7 @@ def _create_swiftmodule(attrs):
558559
if attrs.symbol_graph:
559560
kwargs["symbol_graph"] = attrs.symbol_graph
560561

561-
return swift_common.create_swift_module(
562+
return create_swift_module_inputs(
562563
swiftdoc = attrs.swiftdoc,
563564
swiftmodule = attrs.swiftmodule,
564565
swiftinterface = attrs.swiftinterface,
@@ -585,7 +586,7 @@ def _copy_swiftmodule(ctx, framework_files, clang_module):
585586
return [
586587
# only add the swift module, the objc modulemap is already listed as a header,
587588
# and it will be discovered via the framework search path
588-
swift_common.create_module(
589+
create_swift_module_context(
589590
name = swiftmodule_name,
590591
clang = clang_module,
591592
swift = swift_module,
@@ -600,13 +601,13 @@ def _get_merged_swift_info(ctx, framework_files, transitive_deps, clang_module):
600601
swift_info_fields["modules"] = _copy_swiftmodule(ctx, framework_files, clang_module)
601602
else:
602603
swift_info_fields["modules"] = [
603-
swift_common.create_module(
604+
create_swift_module_context(
604605
name = ctx.attr.framework_name,
605606
clang = clang_module,
606607
),
607608
]
608609

609-
return swift_common.create_swift_info(**swift_info_fields)
610+
return SwiftInfo(**swift_info_fields)
610611

611612
def _merge_root_infoplists(ctx):
612613
if ctx.attr.infoplists == None or len(ctx.attr.infoplists) == 0:
@@ -695,6 +696,7 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps):
695696
actions = ctx.actions
696697
apple_mac_toolchain_info = ctx.attr._mac_toolchain[AppleMacToolsToolchainInfo]
697698
apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo]
699+
cc_toolchain_forwarder = ctx.split_attr._child_configuration_dummy
698700
bin_root_path = ctx.bin_dir.path
699701
bundle_id = ctx.attr.bundle_id
700702
if not bundle_id:
@@ -753,6 +755,7 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps):
753755
)
754756
link_result = linking_support.register_binary_linking_action(
755757
ctx,
758+
cc_toolchains = cc_toolchain_forwarder,
756759
avoid_deps = avoid_deps,
757760
entitlements = None,
758761
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1104,15 +1107,15 @@ def _apple_framework_packaging_impl(ctx):
11041107

11051108
# rules_swift 2.x no longers takes compilation_context from CcInfo, need to pass it in via SwiftInfo's clang_module
11061109
if virtualize_frameworks:
1107-
clang_module = swift_common.create_clang_module(
1110+
clang_module = create_clang_module_inputs(
11081111
module_map = None,
11091112
compilation_context = compilation_context,
11101113
)
11111114
else:
11121115
# Setup the `clang` attr of the Swift module for non-vfs case this is required to have it locate the modulemap
11131116
# and headers correctly.
11141117
module_map = outputs.modulemaps[0] if outputs.modulemaps else None
1115-
clang_module = swift_common.create_clang_module(
1118+
clang_module = create_clang_module_inputs(
11161119
module_map = module_map,
11171120
compilation_context = cc_common.create_compilation_context(
11181121
headers = depset(_compact(

rules/framework/vfs_overlay.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ to each of the entries.
1010
"""
1111

1212
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
13-
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_common")
13+
load("@build_bazel_rules_swift//swift:providers.bzl", "SwiftInfo")
1414
load("//rules:features.bzl", "feature_names")
1515
load("//rules:providers.bzl", "FrameworkInfo")
1616

@@ -298,7 +298,7 @@ def _framework_vfs_overlay_impl(ctx):
298298
files = depset([vfs.vfsoverlay_file]),
299299
vfs_info = vfs.vfs_info,
300300
),
301-
swift_common.create_swift_info(),
301+
SwiftInfo(),
302302
]
303303

304304
def _merge_vfs_infos(base, vfs_infos):

rules/library.bzl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ load("@bazel_skylib//lib:selects.bzl", "selects")
77
load("@bazel_skylib//rules:write_file.bzl", "write_file")
88
load("@build_bazel_rules_apple//apple/internal:apple_framework_import.bzl", "apple_dynamic_framework_import", "apple_static_framework_import")
99
load("@build_bazel_rules_apple//apple/internal/resource_rules:apple_intent_library.bzl", "apple_intent_library")
10-
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
10+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_interop_hint", "swift_library")
1111
load("//rules:precompiled_apple_resource_bundle.bzl", "precompiled_apple_resource_bundle")
1212
load("//rules:hmap.bzl", "headermap")
1313
load("//rules:features.bzl", "feature_names")
@@ -1106,15 +1106,23 @@ def apple_library(
11061106
if module_map:
11071107
objc_hdrs.append(module_map)
11081108

1109+
swift_interop_hint_name = name + "_swift_interop_hint"
1110+
swift_interop_hint(
1111+
name = swift_interop_hint_name,
1112+
module_name = module_name,
1113+
module_map = module_map,
1114+
tags = _MANUAL,
1115+
)
1116+
11091117
default_alwayslink = kwargs.pop("alwayslink", True) # ensure symbols from any static deps are always included (see https://github.com/bazelbuild/rules_apple/issues/1938)
11101118
native.objc_library(
11111119
name = objc_libname,
1120+
aspect_hints = [swift_interop_hint_name],
11121121
srcs = objc_sources + objc_private_hdrs + objc_non_exported_hdrs,
11131122
non_arc_srcs = objc_non_arc_sources,
11141123
hdrs = objc_hdrs,
11151124
copts = copts_by_build_setting.objc_copts + objc_copts + additional_objc_vfs_copts + additional_objc_copts + index_while_building_objc_copts,
11161125
deps = deps + private_deps + private_dep_names + lib_names + additional_objc_vfs_deps,
1117-
module_map = module_map,
11181126
sdk_dylibs = sdk_dylibs,
11191127
sdk_frameworks = sdk_frameworks,
11201128
weak_sdk_frameworks = weak_sdk_frameworks,

rules/repositories.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""Definitions for handling Bazel repositories used by the Apple rules."""
22

3+
load(
4+
"@bazel_tools//tools/build_defs/repo:git.bzl",
5+
"new_git_repository",
6+
)
37
load(
48
"@bazel_tools//tools/build_defs/repo:http.bzl",
59
"http_archive",
610
"http_file",
711
)
8-
load(
9-
"@bazel_tools//tools/build_defs/repo:git.bzl",
10-
"new_git_repository",
11-
)
1212

1313
def _maybe(repo_rule, name, **kwargs):
1414
"""Executes the given repository rule if it hasn't been executed already.
@@ -85,15 +85,15 @@ def _rules_ios_bzlmod_dependencies():
8585
_maybe(
8686
http_archive,
8787
name = "build_bazel_rules_swift",
88-
sha256 = "bb01097c7c7a1407f8ad49a1a0b1960655cf823c26ad2782d0b7d15b323838e2",
89-
url = "https://github.com/bazelbuild/rules_swift/releases/download/1.18.0/rules_swift.1.18.0.tar.gz",
88+
sha256 = "ae6673d27024914fa89e32fd1369e9563fb8ede463feac703aaec1ba6ca0358c",
89+
url = "https://github.com/bazelbuild/rules_swift/releases/download/3.0.1/rules_swift.3.0.1.tar.gz",
9090
)
9191

9292
_maybe(
9393
http_archive,
9494
name = "build_bazel_rules_apple",
95-
sha256 = "b4df908ec14868369021182ab191dbd1f40830c9b300650d5dc389e0b9266c8d",
96-
url = "https://github.com/bazelbuild/rules_apple/releases/download/3.5.1/rules_apple.3.5.1.tar.gz",
95+
sha256 = "b28822cb81916fb544119f5533de010cc67ec6a789f2e7d0fc19d53bfcbb8285",
96+
url = "https://github.com/bazelbuild/rules_apple/releases/download/4.0.1/rules_apple.4.0.1.tar.gz",
9797
)
9898
_maybe(
9999
http_archive,

rules/transition_support.bzl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ def _is_arch_supported_for_target_tuple(*, environment_arch, minimum_os_version,
252252
def _command_line_options(
253253
*,
254254
apple_platforms = [],
255-
emit_swiftinterface = False,
256255
environment_arch = None,
257256
force_bundle_outputs = False,
258257
minimum_os_version,
@@ -267,8 +266,6 @@ def _command_line_options(
267266
first element will be applied to `platforms` as that will be what is resolved by the
268267
underlying rule. Defaults to an empty list, which will signal to Bazel that platform
269268
mapping can take place as a fallback measure.
270-
emit_swiftinterface: Wheither to emit swift interfaces for the given target. Defaults to
271-
`False`.
272269
environment_arch: A valid Apple environment when applicable with its architecture as a
273270
string (for example `sim_arm64` from `ios_sim_arm64`, or `arm64` from `ios_arm64`), or
274271
None to infer a value from command line options passed through settings.
@@ -339,7 +336,6 @@ def _command_line_options(
339336
platform = "watchos",
340337
platform_type = platform_type,
341338
),
342-
"@build_bazel_rules_swift//swift:emit_swiftinterface": emit_swiftinterface,
343339
}
344340

345341
def _apple_rule_base_transition_impl(settings, attr):
@@ -351,7 +347,6 @@ def _apple_rule_base_transition_impl(settings, attr):
351347
# PATCH: end
352348

353349
return _command_line_options(
354-
emit_swiftinterface = hasattr(attr, "_emitswiftinterface"),
355350
environment_arch = _environment_archs(platform_type, settings)[0],
356351
minimum_os_version = minimum_os_version,
357352
platform_type = platform_type,
@@ -401,7 +396,6 @@ _apple_rule_base_transition_outputs = [
401396
"//command_line_option:platforms",
402397
"//command_line_option:tvos_minimum_os",
403398
"//command_line_option:watchos_minimum_os",
404-
"@build_bazel_rules_swift//swift:emit_swiftinterface",
405399
]
406400

407401
_apple_rule_base_transition = transition(
@@ -420,11 +414,6 @@ def _apple_platform_split_transition_impl(settings, attr):
420414
minimum_os_version = _rules_ios_minimum_os_version(platform_type, attr)
421415
# PATCH: end
422416

423-
# iOS and tvOS static frameworks require underlying swift_library targets generate a Swift
424-
# interface file. These rules define a private attribute called `_emitswiftinterface` that
425-
# let's this transition flip rules_swift config down the build graph.
426-
emit_swiftinterface = hasattr(attr, "_emitswiftinterface")
427-
428417
if settings["//command_line_option:incompatible_enable_apple_toolchain_resolution"]:
429418
platforms = (
430419
settings["//command_line_option:apple_platforms"] or
@@ -445,7 +434,6 @@ def _apple_platform_split_transition_impl(settings, attr):
445434
if str(platform) not in output_dictionary:
446435
output_dictionary[str(platform)] = _command_line_options(
447436
apple_platforms = apple_platforms,
448-
emit_swiftinterface = emit_swiftinterface,
449437
minimum_os_version = minimum_os_version,
450438
platform_type = platform_type,
451439
settings = settings,
@@ -492,7 +480,6 @@ def _apple_platform_split_transition_impl(settings, attr):
492480
continue
493481

494482
output_dictionary[found_cpu] = _command_line_options(
495-
emit_swiftinterface = emit_swiftinterface,
496483
environment_arch = environment_arch,
497484
minimum_os_version = minimum_os_version,
498485
platform_type = platform_type,

0 commit comments

Comments
 (0)