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 some linkopts to crosstool features #2214

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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: 5 additions & 5 deletions apple/apple_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ def _apple_binary_impl(ctx):
bundle_loader = ctx.attr.bundle_loader

extra_linkopts = []
extra_requested_features = []

if binary_type == "dylib":
extra_linkopts.append("-dynamiclib")
extra_requested_features.append("link_dylib")
elif binary_type == "loadable_bundle":
extra_linkopts.extend([
"-bundle",
"-Wl,-rpath,@loader_path/Frameworks",
])
extra_linkopts.append("-Wl,-rpath,@loader_path/Frameworks")
extra_requested_features.append("link_bundle")

extra_linkopts.extend([
_linker_flag_for_sdk_dylib(dylib)
Expand All @@ -80,6 +79,7 @@ def _apple_binary_impl(ctx):
bundle_loader = bundle_loader,
exported_symbols_lists = ctx.files.exported_symbols_lists,
extra_linkopts = extra_linkopts,
extra_requested_features = extra_requested_features,
platform_prerequisites = None,
rule_descriptor = None,
stamp = ctx.attr.stamp,
Expand Down
9 changes: 7 additions & 2 deletions apple/internal/ios_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,21 @@ def _ios_application_impl(ctx):
)

extra_linkopts = []
extra_requested_features = []
if ctx.attr.sdk_frameworks:
extra_linkopts.extend(
collections.before_each("-framework", ctx.attr.sdk_frameworks),
)
if ctx.attr.testonly:
extra_requested_features.append("exported_symbols")

link_result = linking_support.register_binary_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
entitlements = entitlements.linking,
exported_symbols_lists = ctx.files.exported_symbols_lists,
extra_linkopts = extra_linkopts,
extra_requested_features = extra_requested_features,
platform_prerequisites = platform_prerequisites,
rule_descriptor = rule_descriptor,
stamp = ctx.attr.stamp,
Expand Down Expand Up @@ -863,8 +867,8 @@ def _ios_framework_impl(ctx):
)

extra_linkopts = [
"-dynamiclib",
"-Wl,-install_name,@rpath/{name}{extension}/{name}".format(
"-install_name",
"@rpath/{name}{extension}/{name}".format(
extension = bundle_extension,
name = bundle_name,
),
Expand All @@ -879,6 +883,7 @@ def _ios_framework_impl(ctx):
entitlements = None,
exported_symbols_lists = ctx.files.exported_symbols_lists,
extra_linkopts = extra_linkopts,
extra_requested_features = ["link_dylib"],
platform_prerequisites = platform_prerequisites,
rule_descriptor = rule_descriptor,
stamp = ctx.attr.stamp,
Expand Down
4 changes: 4 additions & 0 deletions apple/internal/linking_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def _register_binary_linking_action(
exported_symbols_lists,
extra_linkopts = [],
extra_link_inputs = [],
extra_requested_features = [],
extra_disabled_features = [],
platform_prerequisites = None,
rule_descriptor = None,
stamp = -1):
Expand Down Expand Up @@ -221,6 +223,8 @@ def _register_binary_linking_action(
avoid_deps = all_avoid_deps,
extra_linkopts = linkopts,
extra_link_inputs = link_inputs,
extra_requested_features = extra_requested_features,
extra_disabled_features = extra_disabled_features,
stamp = stamp,
)

Expand Down
11 changes: 8 additions & 3 deletions apple/internal/macos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,16 @@ def _macos_application_impl(ctx):
validation_mode = ctx.attr.entitlements_validation,
)

extra_requested_features = []
if ctx.attr.testonly:
extra_requested_features.append("exported_symbols")

link_result = linking_support.register_binary_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
entitlements = entitlements.linking,
exported_symbols_lists = ctx.files.exported_symbols_lists,
extra_requested_features = extra_requested_features,
platform_prerequisites = platform_prerequisites,
rule_descriptor = rule_descriptor,
stamp = ctx.attr.stamp,
Expand Down Expand Up @@ -520,7 +525,7 @@ def _macos_bundle_impl(ctx):
bundle_loader = ctx.attr.bundle_loader,
entitlements = entitlements.linking,
exported_symbols_lists = ctx.files.exported_symbols_lists,
extra_linkopts = ["-bundle"],
extra_requested_features = ["link_bundle"],
platform_prerequisites = platform_prerequisites,
rule_descriptor = rule_descriptor,
stamp = ctx.attr.stamp,
Expand Down Expand Up @@ -1015,7 +1020,6 @@ def _macos_quick_look_plugin_impl(ctx):
)

extra_linkopts = [
"-dynamiclib",
"-install_name",
"\"/Library/Frameworks/{0}.qlgenerator/{0}\"".format(ctx.attr.bundle_name),
]
Expand All @@ -1024,6 +1028,7 @@ def _macos_quick_look_plugin_impl(ctx):
entitlements = entitlements.linking,
exported_symbols_lists = ctx.files.exported_symbols_lists,
extra_linkopts = extra_linkopts,
extra_requested_features = ["link_dylib"],
platform_prerequisites = platform_prerequisites,
rule_descriptor = rule_descriptor,
stamp = ctx.attr.stamp,
Expand Down Expand Up @@ -2076,7 +2081,7 @@ def _macos_dylib_impl(ctx):
# Dynamic libraries do not have entitlements.
entitlements = None,
exported_symbols_lists = ctx.files.exported_symbols_lists,
extra_linkopts = ["-dynamiclib"],
extra_requested_features = ["link_dylib"],
platform_prerequisites = platform_prerequisites,
rule_descriptor = rule_descriptor,
stamp = ctx.attr.stamp,
Expand Down
2 changes: 1 addition & 1 deletion apple/internal/testing/apple_test_bundle_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ def _apple_test_bundle_impl(*, ctx, product_type):
extra_linkopts = [
"-framework",
"XCTest",
"-bundle",
]
extra_link_inputs = []

Expand Down Expand Up @@ -378,6 +377,7 @@ def _apple_test_bundle_impl(*, ctx, product_type):
exported_symbols_lists = ctx.files.exported_symbols_lists,
extra_link_inputs = extra_link_inputs,
extra_linkopts = extra_linkopts,
extra_requested_features = ["link_bundle"],
platform_prerequisites = platform_prerequisites,
rule_descriptor = rule_descriptor,
stamp = ctx.attr.stamp,
Expand Down
10 changes: 8 additions & 2 deletions apple/internal/tvos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,16 @@ def _tvos_application_impl(ctx):
validation_mode = ctx.attr.entitlements_validation,
)

extra_requested_features = []
if ctx.attr.testonly:
extra_requested_features.append("exported_symbols")

link_result = linking_support.register_binary_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
entitlements = entitlements.linking,
exported_symbols_lists = ctx.files.exported_symbols_lists,
extra_requested_features = extra_requested_features,
platform_prerequisites = platform_prerequisites,
rule_descriptor = rule_descriptor,
stamp = ctx.attr.stamp,
Expand Down Expand Up @@ -801,12 +806,13 @@ def _tvos_framework_impl(ctx):
entitlements = None,
exported_symbols_lists = ctx.files.exported_symbols_lists,
extra_linkopts = [
"-dynamiclib",
"-Wl,-install_name,@rpath/{name}{extension}/{name}".format(
"-install_name",
"@rpath/{name}{extension}/{name}".format(
extension = bundle_extension,
name = bundle_name,
),
],
extra_requested_features = ["link_dylib"],
platform_prerequisites = platform_prerequisites,
rule_descriptor = rule_descriptor,
stamp = ctx.attr.stamp,
Expand Down
5 changes: 3 additions & 2 deletions apple/internal/xcframework_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,13 @@ def _apple_xcframework_impl(ctx):
# executables. Only macOS (which is not yet supported) is an outlier; this will require
# changes to native Bazel linking logic for Apple binary targets.
"-Wl,-rpath,@executable_path/Frameworks",
"-dynamiclib",
"-Wl,-install_name,@rpath/{name}{extension}/{name}".format(
"-install_name",
"@rpath/{name}{extension}/{name}".format(
extension = nested_bundle_extension,
name = bundle_name,
),
],
extra_requested_features = ["link_dylib"],
platform_prerequisites = None,
# All required knowledge for 3P facing frameworks is passed directly through the given
# `extra_linkopts`; no rule_descriptor is needed to share with this linking action.
Expand Down
2 changes: 2 additions & 0 deletions examples/multi_platform/Buttons/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ ios_application(
"iphone",
"ipad",
],
features = ["exported_symbols"],
infoplists = ["Buttons/Info.plist"],
minimum_os_version = "11.0",
watch_application = ":ButtonsWatch",
Expand Down Expand Up @@ -335,6 +336,7 @@ macos_framework(
macos_application(
name = "ButtonsMac",
bundle_id = "com.google.ButtonsMac",
features = ["exported_symbols"],
infoplists = ["ButtonsMac/Info.plist"],
minimum_os_version = "12.0",
deps = [
Expand Down