diff --git a/crosstool/cc_toolchain_config.bzl b/crosstool/cc_toolchain_config.bzl index 6ff64f8..00295d5 100644 --- a/crosstool/cc_toolchain_config.bzl +++ b/crosstool/cc_toolchain_config.bzl @@ -993,6 +993,38 @@ def _impl(ctx): ], ) + link_dylib_feature = feature( + name = "link_dylib", + flag_sets = [ + flag_set( + actions = _DYNAMIC_LINK_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-dynamiclib", + ], + ), + ], + ), + ], + ) + + link_bundle_feature = feature( + name = "link_bundle", + flag_sets = [ + flag_set( + actions = _DYNAMIC_LINK_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-bundle", + ], + ), + ], + ), + ], + ) + no_deduplicate_feature = feature( name = "no_deduplicate", enabled = True, @@ -2511,6 +2543,8 @@ def _impl(ctx): ubsan_feature, default_sanitizer_flags_feature, treat_warnings_as_errors_feature, + link_dylib_feature, + link_bundle_feature, ] if (ctx.attr.cpu == "darwin_x86_64" or diff --git a/test/linking_tests.bzl b/test/linking_tests.bzl index ed1032f..236ceea 100644 --- a/test/linking_tests.bzl +++ b/test/linking_tests.bzl @@ -64,3 +64,19 @@ def linking_test_suite(name): mnemonic = "ObjcLink", target_under_test = "//test/test_data:macos_binary", ) + + default_test( + name = "{}_dylib_test".format(name), + tags = [name], + expected_argv = [ + "-Xlinker", + "-objc_abi_version", + "-Xlinker", + "2", + "-ObjC", + "-dynamiclib", + ], + not_expected_argv = [], + mnemonic = "ObjcLink", + target_under_test = "//test/test_data:macos_dylib", + ) diff --git a/test/starlark_apple_binary.bzl b/test/starlark_apple_binary.bzl index f9437c5..a8700b4 100644 --- a/test/starlark_apple_binary.bzl +++ b/test/starlark_apple_binary.bzl @@ -2,10 +2,28 @@ load("//test:transitions.bzl", "apple_platform_split_transition") +_supports_extra_requested_features = hasattr(apple_common.platform_type, "visionos") + def _starlark_apple_binary_impl(ctx): + extra_requested_features = [] + bazel_6_linkopts = [] + if ctx.attr.binary_type == "dylib": + extra_requested_features.append("link_dylib") + bazel_6_linkopts = ["-dynamiclib"] + elif ctx.attr.binary_type == "loadable_bundle": + extra_requested_features.append("link_bundle") + bazel_6_linkopts = ["-bundle"] + + kwargs = {} + if _supports_extra_requested_features: + kwargs["extra_requested_features"] = extra_requested_features + else: + kwargs["extra_linkopts"] = bazel_6_linkopts + link_result = apple_common.link_multi_arch_binary( ctx = ctx, stamp = ctx.attr.stamp, + **kwargs ) processed_binary = ctx.actions.declare_file( "{}_lipobin".format(ctx.label.name), @@ -65,7 +83,10 @@ starlark_apple_binary = rule( default = Label("@bazel_tools//tools/objc:xcrunwrapper"), executable = True, ), - "binary_type": attr.string(default = "executable"), + "binary_type": attr.string( + default = "executable", + values = ["dylib", "executable", "loadable_bundle"], + ), "bundle_loader": attr.label(), "deps": attr.label_list( cfg = apple_platform_split_transition, diff --git a/test/test_data/BUILD b/test/test_data/BUILD index 26b9bb4..dea5964 100644 --- a/test/test_data/BUILD +++ b/test/test_data/BUILD @@ -52,6 +52,15 @@ cc_library( tags = TARGETS_UNDER_TEST_TAGS, ) +starlark_apple_binary( + name = "macos_dylib", + binary_type = "dylib", + minimum_os_version = "13.0", + platform_type = "macos", + tags = TARGETS_UNDER_TEST_TAGS, + deps = [":cc_lib"], +) + objc_library( name = "objc_lib", srcs = ["objc_lib.m"],