Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move apple specific linking logic from bazel #2609

Merged
merged 23 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ tasks:
bazel: latest
<<: *common

macos_last_rc:
name: "Last RC Bazel"
bazel: last_rc
<<: *common

macos_last_green:
name: "Last Green Bazel"
# FIXME: Use last_green once we cherry-pick in changes needed by
# https://github.com/bazelbuild/bazel/commit/b59004dd17366b09b0758b833f98294fd0e89345
# bazel: last_green
bazel: 21a12c72d84e9108142421d9a8526edf8dceb78c
bazel: last_green
<<: *common

doc_tests:
Expand Down
9 changes: 7 additions & 2 deletions apple/apple_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ load(
"//apple/internal:linking_support.bzl",
"linking_support",
)
load(
"//apple/internal:providers.bzl",
"AppleExecutableBinaryInfo",
"new_appleexecutablebinaryinfo",
)
load(
"//apple/internal:rule_attrs.bzl",
"rule_attrs",
Expand Down Expand Up @@ -116,7 +121,7 @@ Resolved Xcode is version {xcode_version}.
# so that bundles can use it as their loader.
if binary_type == "executable":
providers.append(
linking_support.new_executable_binary_provider(
new_appleexecutablebinaryinfo(
binary = binary_artifact,
cc_info = link_result.cc_info,
),
Expand Down Expand Up @@ -170,7 +175,7 @@ The target representing the executable that will be loading this bundle.
Undefined symbols from the bundle are checked against this executable during
linking as if it were one of the dynamic libraries the bundle was linked with.
""",
providers = [apple_common.AppleExecutableBinary],
providers = [AppleExecutableBinaryInfo],
),
"data": attr.label_list(allow_files = True),
"sdk_dylibs": attr.string_list(
Expand Down
8 changes: 7 additions & 1 deletion apple/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,20 @@ bzl_library(

bzl_library(
name = "linking_support",
srcs = ["linking_support.bzl"],
srcs = [
"linking_support.bzl",
"multi_arch_binary_support.bzl",
],
visibility = [
"//apple:__subpackages__",
],
deps = [
":apple_toolchains",
":cc_toolchain_info_support",
":entitlements_support",
":providers",
":rule_support",
"//apple/internal/providers:apple_dynamic_framework_info",
"@bazel_skylib//lib:collections",
"@build_bazel_apple_support//lib:lipo",
],
Expand Down Expand Up @@ -446,6 +451,7 @@ bzl_library(
"//apple/internal/partials:swift_dynamic_framework",
"//apple/internal/partials:swift_framework",
"//apple/internal/partials:watchos_stub",
"//apple/internal/providers:apple_dynamic_framework_info",
],
)

Expand Down
6 changes: 5 additions & 1 deletion apple/internal/apple_framework_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ load(
"//apple/internal/aspects:swift_usage_aspect.bzl",
"SwiftUsageInfo",
)
load(
"//apple/internal/providers:apple_dynamic_framework_info.bzl",
"new_appledynamicframeworkinfo",
)
load(
"//apple/internal/providers:framework_import_bundle_info.bzl",
"AppleFrameworkImportBundleInfo",
Expand Down Expand Up @@ -281,7 +285,7 @@ def _apple_dynamic_framework_import_impl(ctx):
# Create AppleDynamicFramework provider.
framework_groups = _grouped_framework_files(framework_imports)
framework_dirs_set = depset(framework_groups.keys())
providers.append(framework_import_support.new_dynamic_framework_provider(
providers.append(new_appledynamicframeworkinfo(
cc_info = cc_info,
framework_dirs = framework_dirs_set,
framework_files = depset(framework_imports),
Expand Down
9 changes: 7 additions & 2 deletions apple/internal/apple_xcframework_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ load(
"//apple/internal/aspects:swift_usage_aspect.bzl",
"SwiftUsageInfo",
)
load(
"//apple/internal/providers:apple_dynamic_framework_info.bzl",
"AppleDynamicFrameworkInfo",
"new_appledynamicframeworkinfo",
)
load(
"//apple/internal/providers:framework_import_bundle_info.bzl",
"AppleFrameworkImportBundleInfo",
Expand Down Expand Up @@ -513,7 +518,7 @@ def _apple_dynamic_xcframework_import_impl(ctx):
providers.append(cc_info)

# Create AppleDynamicFrameworkInfo provider
apple_dynamic_framework_info = framework_import_support.new_dynamic_framework_provider(
apple_dynamic_framework_info = new_appledynamicframeworkinfo(
cc_info = cc_info,
)
providers.append(apple_dynamic_framework_info)
Expand Down Expand Up @@ -751,7 +756,7 @@ Unnecssary and ignored, will be removed in the future.
provides = [
AppleFrameworkImportInfo,
CcInfo,
apple_common.AppleDynamicFramework,
AppleDynamicFrameworkInfo,
],
toolchains = use_cpp_toolchain(),
)
Expand Down
15 changes: 0 additions & 15 deletions apple/internal/framework_import_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,6 @@ def _has_versioned_framework_files(framework_files):
return True
return False

def _new_dynamic_framework_provider(**kwargs):
"""A wrapper API for the Bazel API of the same name to better support multiple Bazel versions

Args:
**kwargs: Arguments to pass if supported.
"""

# TODO: Remove once we drop bazel 7.x
_OBJC_PROVIDER_LINKING = hasattr(apple_common.new_objc_provider(), "linkopt")
if not _OBJC_PROVIDER_LINKING:
kwargs.pop("objc", None)

return apple_common.new_dynamic_framework_provider(**kwargs)

def _swift_info_from_module_interface(
*,
actions,
Expand Down Expand Up @@ -497,7 +483,6 @@ framework_import_support = struct(
framework_import_info_with_dependencies = _framework_import_info_with_dependencies,
get_swift_module_files_with_target_triplet = _get_swift_module_files_with_target_triplet,
has_versioned_framework_files = _has_versioned_framework_files,
new_dynamic_framework_provider = _new_dynamic_framework_provider,
swift_info_from_module_interface = _swift_info_from_module_interface,
swift_interop_info_with_dependencies = _swift_interop_info_with_dependencies,
)
7 changes: 4 additions & 3 deletions apple/internal/ios_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ load(
)
load(
"//apple/internal:providers.bzl",
"new_appleexecutablebinaryinfo",
"new_appleframeworkbundleinfo",
"new_iosappclipbundleinfo",
"new_iosapplicationbundleinfo",
Expand Down Expand Up @@ -523,7 +524,7 @@ def _ios_application_impl(ctx):
processor_result.output_groups,
)
),
linking_support.new_executable_binary_provider(
new_appleexecutablebinaryinfo(
binary = binary_artifact,
cc_info = link_result.cc_info,
),
Expand Down Expand Up @@ -837,7 +838,7 @@ def _ios_app_clip_impl(ctx):
processor_result.output_groups,
)
),
linking_support.new_executable_binary_provider(
new_appleexecutablebinaryinfo(
binary = binary_artifact,
cc_info = link_result.cc_info,
),
Expand Down Expand Up @@ -1398,7 +1399,7 @@ def _ios_extension_impl(ctx):
DefaultInfo(
files = processor_result.output_files,
),
linking_support.new_executable_binary_provider(
new_appleexecutablebinaryinfo(
binary = binary_artifact,
cc_info = link_result.cc_info,
),
Expand Down
Loading
Loading