diff --git a/apple/internal/BUILD b/apple/internal/BUILD index 4fd1f8401a..c04b5a6f3f 100644 --- a/apple/internal/BUILD +++ b/apple/internal/BUILD @@ -213,6 +213,7 @@ bzl_library( ":apple_product_type", ":apple_toolchains", ":bundling_support", + ":cc_info_support", ":entitlements_support", ":features_support", ":linking_support", @@ -225,10 +226,12 @@ bzl_library( ":rule_support", ":run_support", ":stub_support", + ":swift_support", + ":transition_support", "//apple:providers", - "//apple/internal/aspects:swift_static_framework_aspect", "//apple/internal/utils:clang_rt_dylibs", "@bazel_skylib//lib:collections", + "@build_bazel_rules_swift//swift", ], ) @@ -335,7 +338,6 @@ bzl_library( "//apple/internal/partials:settings_bundle", "//apple/internal/partials:swift_dylibs", "//apple/internal/partials:swift_framework", - "//apple/internal/partials:swift_static_framework", "//apple/internal/partials:watchos_stub", ], ) @@ -415,12 +417,10 @@ bzl_library( ":apple_product_type", ":apple_toolchains", ":rule_support", - ":transition_support", "//apple:common", "//apple:providers", "//apple/internal/aspects:framework_provider_aspect", "//apple/internal/aspects:resource_aspect", - "//apple/internal/aspects:swift_static_framework_aspect", "//apple/internal/aspects:swift_usage_aspect", "//apple/internal/testing:apple_test_bundle_support", "//apple/internal/testing:apple_test_rule_support", @@ -438,7 +438,6 @@ bzl_library( deps = [ ":apple_product_type", ":bundle_package_type", - ":transition_support", ], ) @@ -510,6 +509,7 @@ bzl_library( ":apple_product_type", ":apple_toolchains", ":bundling_support", + ":cc_info_support", ":entitlements_support", ":features_support", ":linking_support", @@ -521,9 +521,11 @@ bzl_library( ":rule_factory", ":rule_support", ":run_support", + ":swift_support", + ":transition_support", "//apple:providers", - "//apple/internal/aspects:swift_static_framework_aspect", "//apple/internal/utils:clang_rt_dylibs", + "@build_bazel_rules_swift//swift", ], ) diff --git a/apple/internal/aspects/BUILD b/apple/internal/aspects/BUILD index 49464bcb18..6ccecee7b0 100644 --- a/apple/internal/aspects/BUILD +++ b/apple/internal/aspects/BUILD @@ -39,18 +39,6 @@ bzl_library( ], ) -bzl_library( - name = "swift_static_framework_aspect", - srcs = ["swift_static_framework_aspect.bzl"], - visibility = [ - "//apple/internal:__pkg__", - ], - deps = [ - "//apple/internal:swift_info_support", - "@build_bazel_rules_swift//swift", - ], -) - bzl_library( name = "swift_usage_aspect", srcs = ["swift_usage_aspect.bzl"], diff --git a/apple/internal/aspects/swift_static_framework_aspect.bzl b/apple/internal/aspects/swift_static_framework_aspect.bzl deleted file mode 100644 index 96db8d0e13..0000000000 --- a/apple/internal/aspects/swift_static_framework_aspect.bzl +++ /dev/null @@ -1,134 +0,0 @@ -# Copyright 2019 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Aspect implementation for Swift static framework support.""" - -load( - "@build_bazel_rules_apple//apple/internal:swift_info_support.bzl", - "swift_info_support", -) -load( - "@build_bazel_rules_swift//swift:swift.bzl", - "SwiftInfo", -) - -SwiftStaticFrameworkInfo = provider( - fields = { - "module_name": "The module name for the single swift_library dependency.", - "swiftinterfaces": """ -Dictionary of architecture to the generated swiftinterface file for that architecture. -""", - "swiftdocs": """ -Dictionary of architecture to the generated swiftdoc file for that architecture. -""", - "generated_header": """ -The generated Objective-C header for the single swift_library dependency. -""", - }, - doc = """ -Provider that collects artifacts required to build a Swift based static framework. -""", -) - -def _swift_target_for_dep(dep): - """Returns the target for which the dependency was compiled. - - This is really hacky, but there's no easy way to acquire the Apple CPU for which the target was - built. One option would be to let this aspect propagate transitively through deps and have - another provider that propagates the CPU, but the model there gets a bit more complicated to - follow. With this approach, we avoid propagating the aspect transitively as well. - - This should be cleaned up when b/141931700 is fixed (adding support for ctx.rule.split_attr). - """ - for action in dep.actions: - if action.mnemonic == "SwiftCompile": - target_found = False - for arg in action.argv: - if target_found: - return arg - if arg == "-target": - target_found = True - fail("error: Expected at least one Swift compilation action for target {}.".format(dep.label)) - -def _swift_arch_for_dep(dep): - """Returns the architecture for which the dependency was built.""" - target = _swift_target_for_dep(dep) - return target.split("-", 1)[0] - -def _swift_static_framework_aspect_impl(_target, ctx): - """Aspect implementation for Swift static framework support.""" - - # Only process the apple_static_library dependency, as that's the place where we can process the - # first level dependencies of the static framework. This is only needed because static framework - # rules (i.e. ios_static_framework) are still macros and not rules. - # Once the static framework rules are migrated to rules instead of macros, this aspect can be - # removed. - if ctx.rule.kind != "apple_static_library": - fail("Internal Error: Should only see the the apple_static_library as a dependency.") - - swiftdeps = [x for x in ctx.rule.attr.deps if SwiftInfo in x] - - # If there are no Swift dependencies, return nothing. - if not swiftdeps: - return [] - - # There can only be one (transitively) exposed swift_library in when wanting to expose a Swift - # from the framework. And there can't really be exposed ObjC since it wouldn't be importable by - # a Swift consumer, but don't bother checking that since it can be useful for other - # libraries/sdks to add implementation detail objc_library instances that aren't exposed, but - # need to be linked to provide a complete library. - - # Collect all relevant artifacts for Swift static framework generation. - avoid_modules = swift_info_support.modules_from_avoid_deps( - avoid_deps = ctx.rule.attr.avoid_deps, - ) - module_name = None - generated_header = None - swiftdocs = {} - swiftinterfaces = {} - for dep in swiftdeps: - swiftinfo = dep[SwiftInfo] - - swift_module = swift_info_support.swift_include_info( - avoid_modules = avoid_modules, - found_module_name = module_name, - transitive_modules = swiftinfo.transitive_modules, - ) - - arch = _swift_arch_for_dep(dep) - swiftdocs[arch] = swift_module.swift.swiftdoc - swiftinterfaces[arch] = swift_module.swift.swiftinterface - module_name = swift_module.name - - # If headers are generated, they should be generated equally for all archs, so just take the - # first one found. - if (not generated_header) and swift_module.clang: - if swift_module.clang.compilation_context.direct_headers: - generated_header = swift_module.clang.compilation_context.direct_headers[0] - - return [ - SwiftStaticFrameworkInfo( - module_name = module_name, - generated_header = generated_header, - swiftdocs = swiftdocs, - swiftinterfaces = swiftinterfaces, - ), - ] - -swift_static_framework_aspect = aspect( - implementation = _swift_static_framework_aspect_impl, - doc = """ -Aspect that collects Swift information to construct a static framework that supports Swift. -""", -) diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index 23e0009081..071acce105 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -31,6 +31,10 @@ load( "@build_bazel_rules_apple//apple/internal:codesigning_support.bzl", "codesigning_support", ) +load( + "@build_bazel_rules_apple//apple/internal:cc_info_support.bzl", + "cc_info_support", +) load( "@build_bazel_rules_apple//apple/internal:entitlements_support.bzl", "entitlements_support", @@ -80,8 +84,16 @@ load( "stub_support", ) load( - "@build_bazel_rules_apple//apple/internal/aspects:swift_static_framework_aspect.bzl", - "SwiftStaticFrameworkInfo", + "@build_bazel_rules_apple//apple/internal:swift_support.bzl", + "swift_support", +) +load( + "@build_bazel_rules_swift//swift:swift.bzl", + "SwiftInfo", +) +load( + "@build_bazel_rules_apple//apple/internal:transition_support.bzl", + "transition_support", ) load( "@build_bazel_rules_apple//apple/internal/aspects:swift_dynamic_framework_aspect.bzl", @@ -102,10 +114,6 @@ load( "IosStaticFrameworkBundleInfo", "IosStickerPackExtensionBundleInfo", ) -load( - "@build_bazel_rules_swift//swift:swift.bzl", - "SwiftInfo", -) load("@bazel_skylib//lib:collections.bzl", "collections") def _ios_application_impl(ctx): @@ -1368,25 +1376,29 @@ def _ios_dynamic_framework_impl(ctx): ] + providers def _ios_static_framework_impl(ctx): - """Experimental implementation of ios_static_framework.""" - binary_target = ctx.attr.deps[0] - binary_artifact = binary_target[apple_common.AppleStaticLibrary].archive + """Implementation of ios_static_framework.""" actions = ctx.actions apple_mac_toolchain_info = ctx.attr._mac_toolchain[AppleMacToolsToolchainInfo] apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo] + avoid_deps = ctx.attr.avoid_deps + deps = ctx.attr.deps + label = ctx.label + predeclared_outputs = ctx.outputs + split_deps = ctx.split_attr.deps bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) executable_name = bundling_support.executable_name(ctx) features = features_support.compute_enabled_features( requested_features = ctx.features, unsupported_features = ctx.disabled_features, ) - label = ctx.label platform_prerequisites = platform_support.platform_prerequisites_from_rule_ctx(ctx) - predeclared_outputs = ctx.outputs resource_deps = ctx.attr.deps + ctx.attr.resources rule_descriptor = rule_support.rule_descriptor(ctx) + link_result = linking_support.register_static_library_linking_action(ctx = ctx) + binary_artifact = link_result.library + processor_partials = [ partials.apple_bundle_info_partial( actions = actions, @@ -1407,15 +1419,28 @@ def _ios_static_framework_impl(ctx): ), ] + swift_infos = {} + if swift_support.uses_swift(deps): + for link_output in link_result.outputs: + split_attr_key = transition_support.apple_common_multi_arch_split_key( + cpu = link_output.architecture, + environment = link_output.environment, + platform_type = link_output.platform, + ) + for dep in split_deps[split_attr_key]: + if SwiftInfo in dep: + swift_infos[link_output.architecture] = dep[SwiftInfo] + # If there's any Swift dependencies on the static framework rule, treat it as a Swift static # framework. - if SwiftStaticFrameworkInfo in binary_target: + if swift_infos: processor_partials.append( - partials.swift_static_framework_partial( + partials.swift_framework_partial( actions = actions, + avoid_deps = avoid_deps, bundle_name = bundle_name, label_name = label.name, - swift_static_framework_info = binary_target[SwiftStaticFrameworkInfo], + swift_infos = swift_infos, ), ) else: @@ -1425,8 +1450,8 @@ def _ios_static_framework_impl(ctx): bundle_name = bundle_name, hdrs = ctx.files.hdrs, label_name = label.name, - sdk_dylibs = getattr(binary_target[apple_common.Objc], "sdk_dylib", []), - sdk_frameworks = getattr(binary_target[apple_common.Objc], "sdk_framework", []), + sdk_dylibs = cc_info_support.get_sdk_dylibs(deps = deps), + sdk_frameworks = cc_info_support.get_sdk_frameworks(deps = deps), umbrella_header = ctx.file.umbrella_header, ), ) diff --git a/apple/internal/partials.bzl b/apple/internal/partials.bzl index e1d39aaeec..d0ce72b7f5 100644 --- a/apple/internal/partials.bzl +++ b/apple/internal/partials.bzl @@ -102,10 +102,6 @@ load( "@build_bazel_rules_apple//apple/internal/partials:swift_framework.bzl", _swift_framework_partial = "swift_framework_partial", ) -load( - "@build_bazel_rules_apple//apple/internal/partials:swift_static_framework.bzl", - _swift_static_framework_partial = "swift_static_framework_partial", -) load( "@build_bazel_rules_apple//apple/internal/partials:watchos_stub.bzl", _watchos_stub_partial = "watchos_stub_partial", @@ -133,7 +129,6 @@ partials = struct( swift_dylibs_partial = _swift_dylibs_partial, swift_dynamic_framework_partial = _swift_dynamic_framework_partial, swift_framework_partial = _swift_framework_partial, - swift_static_framework_partial = _swift_static_framework_partial, apple_symbols_file_partial = _apple_symbols_file_partial, watchos_stub_partial = _watchos_stub_partial, ) diff --git a/apple/internal/partials/BUILD b/apple/internal/partials/BUILD index 093cf2cb1f..e5655be7ee 100644 --- a/apple/internal/partials/BUILD +++ b/apple/internal/partials/BUILD @@ -304,20 +304,6 @@ bzl_library( ], ) -bzl_library( - name = "swift_static_framework", - srcs = ["swift_static_framework.bzl"], - visibility = [ - "//apple/internal:__pkg__", - ], - deps = [ - "//apple/internal:processor", - "//apple/internal:swift_info_support", - "@bazel_skylib//lib:partial", - "@bazel_skylib//lib:paths", - ], -) - bzl_library( name = "watchos_stub", srcs = ["watchos_stub.bzl"], diff --git a/apple/internal/partials/swift_static_framework.bzl b/apple/internal/partials/swift_static_framework.bzl deleted file mode 100644 index 859f5eddc0..0000000000 --- a/apple/internal/partials/swift_static_framework.bzl +++ /dev/null @@ -1,129 +0,0 @@ -# Copyright 2019 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Partial implementation for Swift static frameworks.""" - -load( - "@build_bazel_rules_apple//apple/internal:processor.bzl", - "processor", -) -load( - "@build_bazel_rules_apple//apple/internal:swift_info_support.bzl", - "swift_info_support", -) -load( - "@bazel_skylib//lib:partial.bzl", - "partial", -) -load( - "@bazel_skylib//lib:paths.bzl", - "paths", -) - -def _swift_static_framework_partial_impl( - *, - actions, - bundle_name, - label_name, - output_discriminator, - swift_static_framework_info): - """Implementation for the Swift static framework processing partial.""" - - swift_info_support.verify_found_module_name( - bundle_name = bundle_name, - found_module_name = swift_static_framework_info.module_name, - ) - - generated_header = swift_static_framework_info.generated_header - swiftdocs = swift_static_framework_info.swiftdocs - swiftinterfaces = swift_static_framework_info.swiftinterfaces - - bundle_files = [] - expected_module_name = bundle_name - modules_parent = paths.join("Modules", "{}.swiftmodule".format(expected_module_name)) - - for arch, swiftinterface in swiftinterfaces.items(): - bundle_interface = swift_info_support.declare_swiftinterface( - actions = actions, - arch = arch, - label_name = label_name, - output_discriminator = output_discriminator, - swiftinterface = swiftinterface, - ) - bundle_files.append((processor.location.bundle, modules_parent, depset([bundle_interface]))) - - for arch, swiftdoc in swiftdocs.items(): - bundle_doc = swift_info_support.declare_swiftdoc( - actions = actions, - arch = arch, - label_name = label_name, - output_discriminator = output_discriminator, - swiftdoc = swiftdoc, - ) - bundle_files.append((processor.location.bundle, modules_parent, depset([bundle_doc]))) - - if generated_header: - bundle_header = swift_info_support.declare_generated_header( - actions = actions, - generated_header = generated_header, - label_name = label_name, - output_discriminator = output_discriminator, - module_name = expected_module_name, - ) - bundle_files.append((processor.location.bundle, "Headers", depset([bundle_header]))) - - modulemap = swift_info_support.declare_modulemap( - actions = actions, - label_name = label_name, - framework_modulemap = True, - output_discriminator = output_discriminator, - module_name = expected_module_name, - ) - bundle_files.append((processor.location.bundle, "Modules", depset([modulemap]))) - - return struct(bundle_files = bundle_files) - -def swift_static_framework_partial( - *, - actions, - bundle_name, - label_name, - output_discriminator = None, - swift_static_framework_info): - """Constructor for the Swift static framework processing partial. - - This partial collects and bundles the necessary files to construct a Swift based static - framework. - - Args: - actions: The actions provider from `ctx.actions`. - bundle_name: The name of the output bundle. - label_name: Name of the target being built. - output_discriminator: A string to differentiate between different target intermediate files - or `None`. - swift_static_framework_info: The SwiftStaticFrameworkInfo provider containing the required - artifacts. - - Returns: - A partial that returns the bundle location of the supporting Swift artifacts needed in a - Swift based static framework. - """ - return partial.make( - _swift_static_framework_partial_impl, - actions = actions, - bundle_name = bundle_name, - label_name = label_name, - output_discriminator = output_discriminator, - swift_static_framework_info = swift_static_framework_info, - ) diff --git a/apple/internal/rule_factory.bzl b/apple/internal/rule_factory.bzl index dd5f75076c..a14f382577 100644 --- a/apple/internal/rule_factory.bzl +++ b/apple/internal/rule_factory.bzl @@ -34,10 +34,6 @@ load( "@build_bazel_rules_apple//apple/internal/aspects:resource_aspect.bzl", "apple_resource_aspect", ) -load( - "@build_bazel_rules_apple//apple/internal/aspects:swift_static_framework_aspect.bzl", - "swift_static_framework_aspect", -) load( "@build_bazel_rules_apple//apple/internal/aspects:swift_dynamic_framework_aspect.bzl", "swift_dynamic_framework_aspect", @@ -221,8 +217,6 @@ def _common_binary_linking_attrs(deps_cfg, product_type): if _is_test_product_type(product_type): deps_aspects.append(apple_test_info_aspect) default_stamp = 0 - if product_type == apple_product_type.static_framework: - deps_aspects.append(swift_static_framework_aspect) if product_type == apple_product_type.framework: deps_aspects.append(swift_dynamic_framework_aspect) @@ -570,6 +564,10 @@ to manually dlopen the framework at runtime. }) elif rule_descriptor.product_type == apple_product_type.static_framework: attrs.append({ + "_emitswiftinterface": attr.bool( + default = True, + doc = "Private attribute to generate Swift interfaces for static frameworks.", + ), "hdrs": attr.label_list( allow_files = [".h"], doc = """ @@ -588,6 +586,7 @@ umbrella header will be generated under the same name as this target. """, ), "avoid_deps": attr.label_list( + cfg = apple_common.multi_arch_split, doc = """ A list of library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. @@ -851,6 +850,10 @@ use only extension-safe APIs. }) elif rule_descriptor.product_type == apple_product_type.static_framework: attrs.append({ + "_emitswiftinterface": attr.bool( + default = True, + doc = "Private attribute to generate Swift interfaces for static frameworks.", + ), "hdrs": attr.label_list( allow_files = [".h"], doc = """ @@ -869,6 +872,7 @@ umbrella header will be generated under the same name as this target. """, ), "avoid_deps": attr.label_list( + cfg = apple_common.multi_arch_split, doc = """ A list of library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. @@ -981,6 +985,10 @@ that this target depends on. }) elif rule_descriptor.product_type == apple_product_type.static_framework: attrs.append({ + "_emitswiftinterface": attr.bool( + default = True, + doc = "Private attribute to generate Swift interfaces for static frameworks.", + ), "hdrs": attr.label_list( allow_files = [".h"], doc = """ @@ -999,6 +1007,7 @@ umbrella header will be generated under the same name as this target. """, ), "avoid_deps": attr.label_list( + cfg = apple_common.multi_arch_split, doc = """ A list of library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. diff --git a/apple/internal/rule_support.bzl b/apple/internal/rule_support.bzl index c8fcc15f69..ae699cf650 100644 --- a/apple/internal/rule_support.bzl +++ b/apple/internal/rule_support.bzl @@ -29,10 +29,6 @@ load( "@build_bazel_rules_apple//apple/internal:bundle_package_type.bzl", "bundle_package_type", ) -load( - "@build_bazel_rules_apple//apple/internal:transition_support.bzl", - "transition_support", -) # Options to declare signing behavior and exceptions. # @@ -350,7 +346,7 @@ _RULE_TYPE_DESCRIPTORS = { allowed_device_families = ["iphone", "ipad"], bundle_extension = ".framework", codesigning_exceptions = _CODESIGNING_EXCEPTIONS.skip_signing, - deps_cfg = transition_support.static_framework_transition, + deps_cfg = apple_common.multi_arch_split, has_infoplist = False, product_type = apple_product_type.static_framework, requires_bundle_id = False, @@ -664,7 +660,7 @@ _RULE_TYPE_DESCRIPTORS = { allowed_device_families = ["tv"], bundle_extension = ".framework", codesigning_exceptions = _CODESIGNING_EXCEPTIONS.skip_signing, - deps_cfg = transition_support.static_framework_transition, + deps_cfg = apple_common.multi_arch_split, has_infoplist = False, product_type = apple_product_type.static_framework, requires_bundle_id = False, @@ -768,7 +764,7 @@ _RULE_TYPE_DESCRIPTORS = { allowed_device_families = ["watch"], bundle_extension = ".framework", codesigning_exceptions = _CODESIGNING_EXCEPTIONS.skip_signing, - deps_cfg = transition_support.static_framework_transition, + deps_cfg = apple_common.multi_arch_split, has_infoplist = False, product_type = apple_product_type.static_framework, requires_bundle_id = False, diff --git a/apple/internal/transition_support.bzl b/apple/internal/transition_support.bzl index 226036a8a1..b7bc23a2f1 100644 --- a/apple/internal/transition_support.bzl +++ b/apple/internal/transition_support.bzl @@ -163,8 +163,7 @@ def _command_line_options( ), } - if emit_swiftinterface: - output_dictionary["@build_bazel_rules_swift//swift:emit_swiftinterface"] = True + output_dictionary["@build_bazel_rules_swift//swift:emit_swiftinterface"] = emit_swiftinterface return output_dictionary @@ -174,7 +173,7 @@ def _xcframework_split_attr_key(*, cpu, environment, platform_type): Args: cpu: The architecture of the target that was built. For example, `x86_64` or `arm64`. environment: The environment of the target that was built, which corresponds to the - toolchain's target triple values as reported by `apple_support.link_multi_arch_binary`. + toolchain's target triple values as reported by `apple_support.link_multi_arch_binary` for environment. Typically `device` or `simulator`. platform_type: The platform of the target that was built, which corresponds to the toolchain's target triple values as reported by `apple_support.link_multi_arch_binary` @@ -251,6 +250,7 @@ def _command_line_options_for_xcframework_platform( def _apple_rule_base_transition_impl(settings, attr): """Rule transition for Apple rules.""" return _command_line_options( + emit_swiftinterface = hasattr(attr, "_emitswiftinterface"), minimum_os_version = attr.minimum_os_version, platform_type = attr.platform_type, settings = settings, @@ -285,6 +285,7 @@ _apple_rule_base_transition_outputs = [ "//command_line_option:macos_minimum_os", "//command_line_option:tvos_minimum_os", "//command_line_option:watchos_minimum_os", + "@build_bazel_rules_swift//swift:emit_swiftinterface", ] _apple_universal_binary_rule_transition_outputs = _apple_rule_base_transition_outputs + [ "//command_line_option:ios_multi_cpus", @@ -355,24 +356,31 @@ _apple_universal_binary_rule_transition = transition( outputs = _apple_universal_binary_rule_transition_outputs, ) -def _static_framework_transition_impl(_settings, _attr): - """Attribute transition for static frameworks to enable swiftinterface generation.""" - return { - "@build_bazel_rules_swift//swift:emit_swiftinterface": True, - } +# TODO(b/230527536): Add support for Bazel platforms on ios/tvos_static_framework transition support method +def _apple_common_multi_arch_split_key(*, cpu, environment, platform_type): + """Returns split key for the apple_common.multi_arch_split transition based on target triplet. -# This transition is used, for now, to enable swiftinterface generation on swift_library targets. -# Once apple_common.split_transition is migrated to Starlark, this transition should be merged into -# that one, being enabled by reading either a private attribute on the static framework rules, or -# some other mechanism, so that it is only enabled on static framework rules and not all Apple -# rules. -_static_framework_transition = transition( - implementation = _static_framework_transition_impl, - inputs = [], - outputs = [ - "@build_bazel_rules_swift//swift:emit_swiftinterface", - ], -) + See ApplePlatform.cpuStringForTarget for reference on how apple_common.multi_arch_split + transition key is built. + + Args: + cpu: The architecture of the target that was built. For example, `x86_64` or + `arm64`. + environment: The environment of the target that was built, which corresponds to the + toolchain's target triple values as reported by `apple_support.link_multi_arch_*` + for environment. Typically `device` or `simulator`. + platform_type: The platform of the target that was built, which corresponds to the + toolchain's target triple values as reported by `apple_common.link_multi_arch_*` + for platform. For example, `ios`, `macos`, `tvos` or `watchos`. + """ + cpu = _resolved_cpu_for_cpu( + cpu = cpu, + environment = environment, + ) + return _cpu_string( + cpu = cpu, + platform_type = platform_type, + ) def _xcframework_transition_impl(settings, attr): """Starlark 1:2+ transition for generation of multiple frameworks for the current target.""" @@ -398,16 +406,14 @@ def _xcframework_transition_impl(settings, attr): _xcframework_transition = transition( implementation = _xcframework_transition_impl, inputs = _apple_rule_common_transition_inputs, - outputs = _apple_rule_base_transition_outputs + [ - "@build_bazel_rules_swift//swift:emit_swiftinterface", - ], + outputs = _apple_rule_base_transition_outputs, ) transition_support = struct( apple_rule_transition = _apple_rule_base_transition, apple_rule_arm64_as_arm64e_transition = _apple_rule_arm64_as_arm64e_transition, apple_universal_binary_rule_transition = _apple_universal_binary_rule_transition, - static_framework_transition = _static_framework_transition, + apple_common_multi_arch_split_key = _apple_common_multi_arch_split_key, xcframework_split_attr_key = _xcframework_split_attr_key, xcframework_transition = _xcframework_transition, ) diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index 3925762e4a..45d6906f06 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -35,6 +35,10 @@ load( "@build_bazel_rules_apple//apple/internal:codesigning_support.bzl", "codesigning_support", ) +load( + "@build_bazel_rules_apple//apple/internal:cc_info_support.bzl", + "cc_info_support", +) load( "@build_bazel_rules_apple//apple/internal:entitlements_support.bzl", "entitlements_support", @@ -80,8 +84,16 @@ load( "run_support", ) load( - "@build_bazel_rules_apple//apple/internal/aspects:swift_static_framework_aspect.bzl", - "SwiftStaticFrameworkInfo", + "@build_bazel_rules_apple//apple/internal:swift_support.bzl", + "swift_support", +) +load( + "@build_bazel_rules_swift//swift:swift.bzl", + "SwiftInfo", +) +load( + "@build_bazel_rules_apple//apple/internal:transition_support.bzl", + "transition_support", ) load( "@build_bazel_rules_apple//apple/internal/utils:clang_rt_dylibs.bzl", @@ -94,10 +106,6 @@ load( "TvosFrameworkBundleInfo", "TvosStaticFrameworkBundleInfo", ) -load( - "@build_bazel_rules_swift//swift:swift.bzl", - "SwiftInfo", -) def _tvos_application_impl(ctx): """Experimental implementation of tvos_application.""" @@ -1003,24 +1011,27 @@ def _tvos_extension_impl(ctx): def _tvos_static_framework_impl(ctx): """Implementation of tvos_static_framework.""" - binary_target = ctx.attr.deps[0] - binary_artifact = binary_target[apple_common.AppleStaticLibrary].archive - actions = ctx.actions apple_mac_toolchain_info = ctx.attr._mac_toolchain[AppleMacToolsToolchainInfo] apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo] + avoid_deps = ctx.attr.avoid_deps + deps = ctx.attr.deps + label = ctx.label + predeclared_outputs = ctx.outputs + split_deps = ctx.split_attr.deps bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) executable_name = bundling_support.executable_name(ctx) features = features_support.compute_enabled_features( requested_features = ctx.features, unsupported_features = ctx.disabled_features, ) - label = ctx.label platform_prerequisites = platform_support.platform_prerequisites_from_rule_ctx(ctx) - predeclared_outputs = ctx.outputs resource_deps = ctx.attr.deps + ctx.attr.resources rule_descriptor = rule_support.rule_descriptor(ctx) + link_result = linking_support.register_static_library_linking_action(ctx = ctx) + binary_artifact = link_result.library + processor_partials = [ partials.apple_bundle_info_partial( actions = actions, @@ -1041,15 +1052,28 @@ def _tvos_static_framework_impl(ctx): ), ] + swift_infos = {} + if swift_support.uses_swift(deps): + for link_output in link_result.outputs: + split_attr_key = transition_support.apple_common_multi_arch_split_key( + cpu = link_output.architecture, + environment = link_output.environment, + platform_type = link_output.platform, + ) + for dep in split_deps[split_attr_key]: + if SwiftInfo in dep: + swift_infos[link_output.architecture] = dep[SwiftInfo] + # If there's any Swift dependencies on the static framework rule, treat it as a Swift static # framework. - if SwiftStaticFrameworkInfo in binary_target: + if swift_infos: processor_partials.append( - partials.swift_static_framework_partial( + partials.swift_framework_partial( actions = actions, + avoid_deps = avoid_deps, bundle_name = bundle_name, label_name = label.name, - swift_static_framework_info = binary_target[SwiftStaticFrameworkInfo], + swift_infos = swift_infos, ), ) else: @@ -1059,8 +1083,8 @@ def _tvos_static_framework_impl(ctx): bundle_name = bundle_name, hdrs = ctx.files.hdrs, label_name = label.name, - sdk_dylibs = getattr(binary_target[apple_common.Objc], "sdk_dylib", []), - sdk_frameworks = getattr(binary_target[apple_common.Objc], "sdk_framework", []), + sdk_dylibs = cc_info_support.get_sdk_dylibs(deps = deps), + sdk_frameworks = cc_info_support.get_sdk_frameworks(deps = deps), umbrella_header = ctx.file.umbrella_header, ), ) diff --git a/apple/internal/watchos_rules.bzl b/apple/internal/watchos_rules.bzl index 4549ad1abe..46294190cb 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -35,6 +35,10 @@ load( "@build_bazel_rules_apple//apple/internal:codesigning_support.bzl", "codesigning_support", ) +load( + "@build_bazel_rules_apple//apple/internal:cc_info_support.bzl", + "cc_info_support", +) load( "@build_bazel_rules_apple//apple/internal:entitlements_support.bzl", "entitlements_support", @@ -80,8 +84,12 @@ load( "stub_support", ) load( - "@build_bazel_rules_apple//apple/internal/aspects:swift_static_framework_aspect.bzl", - "SwiftStaticFrameworkInfo", + "@build_bazel_rules_apple//apple/internal:swift_support.bzl", + "swift_support", +) +load( + "@build_bazel_rules_apple//apple/internal:transition_support.bzl", + "transition_support", ) load( "@build_bazel_rules_apple//apple/internal/utils:clang_rt_dylibs.bzl", @@ -790,12 +798,14 @@ def _watchos_extension_impl(ctx): def _watchos_static_framework_impl(ctx): """Implementation of watchos_static_framework.""" - binary_target = ctx.attr.deps[0] - binary_artifact = binary_target[apple_common.AppleStaticLibrary].archive - actions = ctx.actions apple_mac_toolchain_info = ctx.attr._mac_toolchain[AppleMacToolsToolchainInfo] apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo] + avoid_deps = ctx.attr.avoid_deps + deps = ctx.attr.deps + label = ctx.label + predeclared_outputs = ctx.outputs + split_deps = ctx.split_attr.deps bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) executable_name = bundling_support.executable_name(ctx) features = features_support.compute_enabled_features( @@ -807,6 +817,9 @@ def _watchos_static_framework_impl(ctx): predeclared_outputs = ctx.outputs rule_descriptor = rule_support.rule_descriptor(ctx) + link_result = linking_support.register_static_library_linking_action(ctx = ctx) + binary_artifact = link_result.library + processor_partials = [ partials.apple_bundle_info_partial( actions = actions, @@ -827,15 +840,27 @@ def _watchos_static_framework_impl(ctx): ), ] + swift_infos = {} + if swift_support.uses_swift(deps): + for link_output in link_result.outputs: + split_attr_key = transition_support.apple_common_multi_arch_split_key( + cpu = link_output.architecture, + platform_type = link_output.platform, + ) + for dep in split_deps[split_attr_key]: + if SwiftInfo in dep: + swift_infos[link_output.architecture] = dep[SwiftInfo] + # If there's any Swift dependencies on the static framework rule, treat it as a Swift static # framework. - if SwiftStaticFrameworkInfo in binary_target: + if swift_infos: processor_partials.append( - partials.swift_static_framework_partial( + partials.swift_framework_partial( actions = actions, + avoid_deps = avoid_deps, bundle_name = bundle_name, label_name = label.name, - swift_static_framework_info = binary_target[SwiftStaticFrameworkInfo], + swift_infos = swift_infos, ), ) else: @@ -845,8 +870,8 @@ def _watchos_static_framework_impl(ctx): bundle_name = bundle_name, hdrs = ctx.files.hdrs, label_name = label.name, - sdk_dylibs = getattr(binary_target[apple_common.Objc], "sdk_dylib", []), - sdk_frameworks = getattr(binary_target[apple_common.Objc], "sdk_framework", []), + sdk_dylibs = cc_info_support.get_sdk_dylibs(deps = deps), + sdk_frameworks = cc_info_support.get_sdk_frameworks(deps = deps), umbrella_header = ctx.file.umbrella_header, ), ) diff --git a/apple/ios.bzl b/apple/ios.bzl index 3ee4740e19..d5b1e6b0e5 100644 --- a/apple/ios.bzl +++ b/apple/ios.bzl @@ -51,35 +51,7 @@ ios_framework = _ios_framework ios_imessage_application = _ios_imessage_application ios_sticker_pack_extension = _ios_sticker_pack_extension ios_imessage_extension = _ios_imessage_extension - -def ios_static_framework(name, **kwargs): - # buildifier: disable=function-docstring-args - """Builds and bundles an iOS static framework for third-party distribution.""" - avoid_deps = kwargs.get("avoid_deps") - deps = kwargs.get("deps") - apple_static_library_name = "%s.apple_static_library" % name - - native.apple_static_library( - name = apple_static_library_name, - deps = deps, - avoid_deps = avoid_deps, - minimum_os_version = kwargs.get("minimum_os_version"), - platform_type = str(apple_common.platform_type.ios), - tags = kwargs.get("tags"), - testonly = kwargs.get("testonly"), - visibility = kwargs.get("visibility"), - ) - - passthrough_args = kwargs - passthrough_args.pop("avoid_deps", None) - passthrough_args.pop("deps", None) - - _ios_static_framework( - name = name, - deps = [apple_static_library_name], - avoid_deps = [apple_static_library_name], - **passthrough_args - ) +ios_static_framework = _ios_static_framework _DEFAULT_TEST_RUNNER = "@build_bazel_rules_apple//apple/testing/default_runner:ios_default_runner" diff --git a/apple/tvos.bzl b/apple/tvos.bzl index ff2554a2d3..e9739e44f1 100644 --- a/apple/tvos.bzl +++ b/apple/tvos.bzl @@ -43,35 +43,7 @@ tvos_application = _tvos_application tvos_dynamic_framework = _tvos_dynamic_framework tvos_extension = _tvos_extension tvos_framework = _tvos_framework - -def tvos_static_framework(name, **kwargs): - # buildifier: disable=function-docstring-args - """Builds and bundles a tvOS static framework for third-party distribution.""" - avoid_deps = kwargs.get("avoid_deps") - deps = kwargs.get("deps") - apple_static_library_name = "%s.apple_static_library" % name - - native.apple_static_library( - name = apple_static_library_name, - deps = deps, - avoid_deps = avoid_deps, - minimum_os_version = kwargs.get("minimum_os_version"), - platform_type = str(apple_common.platform_type.tvos), - tags = kwargs.get("tags"), - testonly = kwargs.get("testonly"), - visibility = kwargs.get("visibility"), - ) - - passthrough_args = kwargs - passthrough_args.pop("avoid_deps", None) - passthrough_args.pop("deps", None) - - _tvos_static_framework( - name = name, - deps = [apple_static_library_name], - avoid_deps = [apple_static_library_name], - **passthrough_args - ) +tvos_static_framework = _tvos_static_framework _DEFAULT_TEST_RUNNER = "@build_bazel_rules_apple//apple/testing/default_runner:tvos_default_runner" diff --git a/apple/watchos.bzl b/apple/watchos.bzl index 1d0384370a..8b6342e733 100644 --- a/apple/watchos.bzl +++ b/apple/watchos.bzl @@ -41,6 +41,7 @@ load( watchos_application = _watchos_application watchos_dynamic_framework = _watchos_dynamic_framework watchos_extension = _watchos_extension +watchos_static_framework = _watchos_static_framework _DEFAULT_TEST_RUNNER = "@build_bazel_rules_apple//apple/testing/default_runner:watchos_default_runner" @@ -84,31 +85,3 @@ watchos_build_test( """, platform_type = "watchos", ) - -def watchos_static_framework(name, **kwargs): - # buildifier: disable=function-docstring-args - """Builds and bundles a watchOS static framework for third-party distribution.""" - avoid_deps = kwargs.get("avoid_deps") - deps = kwargs.get("deps") - apple_static_library_name = "%s.apple_static_library" % name - - native.apple_static_library( - name = apple_static_library_name, - deps = deps, - avoid_deps = avoid_deps, - minimum_os_version = kwargs.get("minimum_os_version"), - platform_type = str(apple_common.platform_type.watchos), - tags = kwargs.get("tags"), - visibility = kwargs.get("visibility"), - ) - - passthrough_args = kwargs - passthrough_args.pop("avoid_deps", None) - passthrough_args.pop("deps", None) - - _watchos_static_framework( - name = name, - deps = [apple_static_library_name], - avoid_deps = [apple_static_library_name], - **passthrough_args - ) diff --git a/test/starlark_tests/apple_static_xcframework_tests.bzl b/test/starlark_tests/apple_static_xcframework_tests.bzl index f89addb90d..7246d8884b 100644 --- a/test/starlark_tests/apple_static_xcframework_tests.bzl +++ b/test/starlark_tests/apple_static_xcframework_tests.bzl @@ -155,6 +155,7 @@ def apple_static_xcframework_test_suite(name): target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_static_xcframework", binary_test_architecture = "arm64", binary_test_file = "$BUNDLE_ROOT/ios-arm64_x86_64-simulator/ios_static_xcframework.framework/ios_static_xcframework", + macho_load_commands_contain = ["cmd LC_BUILD_VERSION", "platform IOSSIMULATOR"], macho_load_commands_not_contain = ["cmd LC_VERSION_MIN_IPHONEOS"], tags = [name], ) @@ -174,7 +175,7 @@ def apple_static_xcframework_test_suite(name): target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_static_xcframework_min_os_12", binary_test_architecture = "x86_64", binary_test_file = "$BUNDLE_ROOT/ios-arm64_x86_64-simulator/ios_static_xcframework_min_os_12.framework/ios_static_xcframework_min_os_12", - macho_load_commands_contain = ["cmd LC_BUILD_VERSION", "platform 7"], + macho_load_commands_contain = ["cmd LC_BUILD_VERSION", "platform IOSSIMULATOR"], macho_load_commands_not_contain = ["cmd LC_VERSION_MIN_IPHONEOS"], tags = [name], ) @@ -196,7 +197,7 @@ def apple_static_xcframework_test_suite(name): build_type = "device", target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_static_xcframework_min_os_12", binary_test_file = "$BUNDLE_ROOT/ios-arm64/ios_static_xcframework_min_os_12.framework/ios_static_xcframework_min_os_12", - macho_load_commands_contain = ["cmd LC_BUILD_VERSION", "platform 2"], + macho_load_commands_contain = ["cmd LC_BUILD_VERSION", "platform IOS"], macho_load_commands_not_contain = ["cmd LC_VERSION_MIN_IPHONEOS"], tags = [name], ) diff --git a/test/starlark_tests/apple_universal_binary_tests.bzl b/test/starlark_tests/apple_universal_binary_tests.bzl index 75b4a16e7a..e37a23fd50 100644 --- a/test/starlark_tests/apple_universal_binary_tests.bzl +++ b/test/starlark_tests/apple_universal_binary_tests.bzl @@ -39,7 +39,7 @@ def apple_universal_binary_test_suite(name): binary_contents_test( name = "{}_x86_binary_contents_test".format(name), build_type = "device", - macos_cpus = ["x86_64", "arm64"], + cpus = {"macos_cpus": ["x86_64", "arm64"]}, target_under_test = "//test/starlark_tests/targets_under_test/apple:multi_arch_cc_binary", binary_test_file = "$BINARY", binary_test_architecture = "x86_64", @@ -51,7 +51,7 @@ def apple_universal_binary_test_suite(name): binary_contents_test( name = "{}_arm64_binary_contents_test".format(name), build_type = "device", - macos_cpus = ["x86_64", "arm64"], + cpus = {"macos_cpus": ["x86_64", "arm64"]}, target_under_test = "//test/starlark_tests/targets_under_test/apple:multi_arch_cc_binary", binary_test_file = "$BINARY", binary_test_architecture = "arm64", @@ -67,7 +67,7 @@ def apple_universal_binary_test_suite(name): binary_contents_test( name = "{}_forced_cpus_x86_binary_contents_test".format(name), build_type = "device", - macos_cpus = ["arm64"], + cpus = {"macos_cpus": ["arm64"]}, target_under_test = "//test/starlark_tests/targets_under_test/apple:multi_arch_forced_cpus_cc_binary", binary_test_file = "$BINARY", binary_test_architecture = "x86_64", @@ -79,7 +79,7 @@ def apple_universal_binary_test_suite(name): binary_contents_test( name = "{}_forced_cpus_arm64_binary_contents_test".format(name), build_type = "device", - macos_cpus = ["x86_64"], + cpus = {"macos_cpus": ["x86_64"]}, target_under_test = "//test/starlark_tests/targets_under_test/apple:multi_arch_forced_cpus_cc_binary", binary_test_file = "$BINARY", binary_test_architecture = "arm64", diff --git a/test/starlark_tests/ios_static_framework_tests.bzl b/test/starlark_tests/ios_static_framework_tests.bzl index e46e0115e0..0015711002 100644 --- a/test/starlark_tests/ios_static_framework_tests.bzl +++ b/test/starlark_tests/ios_static_framework_tests.bzl @@ -26,6 +26,34 @@ def ios_static_framework_test_suite(name): name: the base name to be used in things created by this macro """ + # Tests Swift ios_static_framework builds correctly for sim_arm64, and x86_64 cpu's. + archive_contents_test( + name = "{}_swift_sim_arm64_builds".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_ios_static_framework", + cpus = { + "ios_multi_cpus": ["x86_64", "sim_arm64"], + }, + binary_test_file = "$BUNDLE_ROOT/SwiftFmwk", + binary_test_architecture = "arm64", + macho_load_commands_contain = ["cmd LC_BUILD_VERSION", "platform IOSSIMULATOR"], + macho_load_commands_not_contain = ["cmd LC_VERSION_MIN_IPHONEOS"], + tags = [name], + ) + archive_contents_test( + name = "{}_swift_x86_64_builds".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/ios:swift_ios_static_framework", + cpus = { + "ios_multi_cpus": ["x86_64", "sim_arm64"], + }, + binary_test_file = "$BUNDLE_ROOT/SwiftFmwk", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["cmd LC_VERSION_MIN_IPHONEOS"], + macho_load_commands_not_contain = ["cmd LC_BUILD_VERSION", "platform IOSSIMULATOR"], + tags = [name], + ) + # Test that it's permitted for a static framework to have multiple # `swift_library` dependencies if only one module remains after excluding # the transitive closure of `avoid_deps`. Likewise, make sure that the diff --git a/test/starlark_tests/rules/apple_verification_test.bzl b/test/starlark_tests/rules/apple_verification_test.bzl index 59ab33a277..1ba2087888 100644 --- a/test/starlark_tests/rules/apple_verification_test.bzl +++ b/test/starlark_tests/rules/apple_verification_test.bzl @@ -19,7 +19,7 @@ that may change at any time. Please do not depend on this rule. """ load( - "@build_bazel_rules_apple//apple/internal:apple_product_type.bzl", + "@build_bazel_rules_apple//apple/internal:apple_product_type.bzl", # buildifier: disable=bzl-visibility "apple_product_type", ) # buildifier: disable=bzl-visibility load( @@ -39,15 +39,9 @@ load( def _apple_verification_transition_impl(settings, attr): """Implementation of the apple_verification_transition transition.""" - # This was added because this transition is also used by - # `infoplist_contents_test` and has no "macos_cpus" attribute. - macos_cpus = "x86_64" - if hasattr(attr, "macos_cpus"): - macos_cpus = ",".join(attr.macos_cpus) - output_dictionary = { "//command_line_option:ios_signing_cert_name": "-", - "//command_line_option:macos_cpus": macos_cpus, + "//command_line_option:macos_cpus": "x86_64", "//command_line_option:compilation_mode": attr.compilation_mode, "//command_line_option:apple_bitcode": attr.apple_bitcode, "//command_line_option:apple_generate_dsym": attr.apple_generate_dsym, @@ -64,12 +58,19 @@ def _apple_verification_transition_impl(settings, attr): "//command_line_option:tvos_cpus": "arm64", "//command_line_option:watchos_cpus": "arm64_32,armv7k", }) + + if hasattr(attr, "cpus"): + for cpu_option, cpus in attr.cpus.items(): + command_line_option = "//command_line_option:%s" % cpu_option + output_dictionary.update({command_line_option: ",".join(cpus)}) + existing_features = settings.get("//command_line_option:features") or [] if hasattr(attr, "target_features"): existing_features.extend(attr.target_features) if hasattr(attr, "sanitizer") and attr.sanitizer != "none": existing_features.append(attr.sanitizer) output_dictionary["//command_line_option:features"] = existing_features + return output_dictionary apple_verification_transition = transition( @@ -231,10 +232,10 @@ https://docs.bazel.build/versions/master/user-manual.html#flag--compilation_mode If true, generates .dSYM debug symbol bundles for the target(s) under test. """, ), - "macos_cpus": attr.string_list( + "cpus": attr.string_list_dict( doc = """ -List of MacOS CPU's to use for test under target. -https://docs.bazel.build/versions/main/command-line-reference.html#flag--macos_cpus +Dictionary of command line options cpu flags (e.g. ios_multi_cpus, macos_cpus) and the list of +cpu's to use for test under target (e.g. {'ios_multi_cpus': ['arm64', 'x86_64']}) """, ), "sanitizer": attr.string( diff --git a/test/starlark_tests/targets_under_test/ios/BUILD b/test/starlark_tests/targets_under_test/ios/BUILD index 399b5dd0b3..0ab0753a65 100644 --- a/test/starlark_tests/targets_under_test/ios/BUILD +++ b/test/starlark_tests/targets_under_test/ios/BUILD @@ -2265,6 +2265,14 @@ ios_dynamic_framework( # --------------------------------------------------------------------------------------- # Targets for iOS static framework tests. +ios_static_framework( + name = "swift_ios_static_framework", + bundle_name = "SwiftFmwk", + minimum_os_version = "8.0", + tags = FIXTURE_TAGS, + deps = [":SwiftFmwk"], +) + ios_static_framework( name = "static_fmwk_with_swift_and_avoid_deps", avoid_deps = [":SwiftFmwkLowerLib"], @@ -2288,6 +2296,13 @@ genrule( cmd = "echo 'public struct Dummy {}' > $@", ) +swift_library( + name = "SwiftFmwk", + srcs = ["Dummy.swift"], + module_name = "SwiftFmwk", + tags = FIXTURE_TAGS, +) + swift_library( name = "SwiftFmwkUpperLib", srcs = ["Dummy.swift"], diff --git a/test/starlark_tests/targets_under_test/tvos/BUILD b/test/starlark_tests/targets_under_test/tvos/BUILD index 767346f521..91ac4c4158 100644 --- a/test/starlark_tests/targets_under_test/tvos/BUILD +++ b/test/starlark_tests/targets_under_test/tvos/BUILD @@ -299,6 +299,21 @@ tvos_static_framework( ], ) +tvos_static_framework( + name = "swift_static_fmwk", + bundle_name = "swift_static_fmwk", + minimum_os_version = "9.0", + tags = FIXTURE_TAGS, + deps = [":swift_fmwk_lib"], +) + +swift_library( + name = "swift_fmwk_lib", + srcs = ["//test/testdata/sources:main.swift"], + module_name = "swift_static_fmwk", + tags = FIXTURE_TAGS, +) + # --------------------------------------------------------------------------------------- tvos_ui_test( diff --git a/test/starlark_tests/tvos_static_framework_tests.bzl b/test/starlark_tests/tvos_static_framework_tests.bzl index 732fd47488..696ee35fe5 100644 --- a/test/starlark_tests/tvos_static_framework_tests.bzl +++ b/test/starlark_tests/tvos_static_framework_tests.bzl @@ -38,6 +38,34 @@ def tvos_static_framework_test_suite(name): tags = [name], ) + # Tests Swift tvos_static_framework builds correctly for sim_arm64, and x86_64 cpu's. + archive_contents_test( + name = "{}_swift_sim_arm64_builds".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/tvos:swift_static_fmwk", + cpus = { + "tvos_cpus": ["x86_64", "sim_arm64"], + }, + binary_test_file = "$BUNDLE_ROOT/swift_static_fmwk", + binary_test_architecture = "arm64", + macho_load_commands_contain = ["cmd LC_BUILD_VERSION", "platform TVOSSIMULATOR"], + macho_load_commands_not_contain = ["cmd LC_VERSION_MIN_TVOS"], + tags = [name], + ) + archive_contents_test( + name = "{}_swift_x86_64_builds".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/tvos:swift_static_fmwk", + cpus = { + "tvos_cpus": ["x86_64", "sim_arm64"], + }, + binary_test_file = "$BUNDLE_ROOT/swift_static_fmwk", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["cmd LC_VERSION_MIN_TVOS"], + macho_load_commands_not_contain = ["cmd LC_BUILD_VERSION", "platform TVOSSIMULATOR"], + tags = [name], + ) + native.test_suite( name = name, tags = [name], diff --git a/test/starlark_tests/verifier_scripts/archive_contents_test.sh b/test/starlark_tests/verifier_scripts/archive_contents_test.sh index 33f78f8ad3..5eef1adaf3 100644 --- a/test/starlark_tests/verifier_scripts/archive_contents_test.sh +++ b/test/starlark_tests/verifier_scripts/archive_contents_test.sh @@ -207,10 +207,10 @@ if [[ -n "${BINARY_TEST_FILE-}" ]]; then if [[ ! -n $arch ]]; then fail "No architecture specified for binary file at \"$path\"" else - actual_symbols=($(otool -arch "$arch" -l "$path" | awk '{$1=$1}1')) + actual_symbols=($(otool -v -arch "$arch" -l "$path" | awk '{$1=$1}1')) fi else - actual_symbols=($(otool -l "$path" | awk '{$1=$1}1')) + actual_symbols=($(otool -v -l "$path" | awk '{$1=$1}1')) fi if [[ -n "${MACHO_LOAD_COMMANDS_CONTAIN-}" ]]; then for test_symbol in "${MACHO_LOAD_COMMANDS_CONTAIN[@]}"