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 -install_name linker flag from the {ios,tvos}_framework macro into the rule implementation. #1207

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
65 changes: 38 additions & 27 deletions apple/internal/ios_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -632,21 +632,6 @@ def _ios_app_clip_impl(ctx):

def _ios_framework_impl(ctx):
"""Experimental implementation of ios_framework."""

# TODO(kaipi): Add support for packaging headers.
extra_linkopts = ["-dynamiclib"]
if ctx.attr.extension_safe:
extra_linkopts.append("-fapplication-extension")

link_result = linking_support.register_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
extra_linkopts = extra_linkopts,
stamp = ctx.attr.stamp,
)
binary_artifact = link_result.binary
debug_outputs_provider = link_result.debug_outputs_provider

actions = ctx.actions
apple_toolchain_info = ctx.attr._toolchain[AppleSupportToolchainInfo]
bin_root_path = ctx.bin_dir.path
Expand Down Expand Up @@ -680,6 +665,25 @@ def _ios_framework_impl(ctx):
res_attrs = ["resources"],
)

extra_linkopts = [
"-dynamiclib",
"-Wl,-install_name,@rpath/{name}{extension}/{name}".format(
Copy link
Collaborator

@brentleyjones brentleyjones Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this version to work around https://github.com/bazelbuild/bazel/blob/1c3a2456c95fd19974a5b2bd33c5ebdb2b2277e4/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java#L295 causing an issue. Think this is bug worthy?

One nice thing about doing it this way: it's the same argument that was being sent before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Yes I think we should report it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extension = bundle_extension,
name = bundle_name,
),
]
if ctx.attr.extension_safe:
extra_linkopts.append("-fapplication-extension")

link_result = linking_support.register_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
extra_linkopts = extra_linkopts,
stamp = ctx.attr.stamp,
)
binary_artifact = link_result.binary
debug_outputs_provider = link_result.debug_outputs_provider

archive_for_embedding = outputs.archive_for_embedding(
actions = actions,
bundle_name = bundle_name,
Expand Down Expand Up @@ -1078,18 +1082,6 @@ def _ios_dynamic_framework_impl(ctx):
)

binary_target = ctx.attr.deps[0]
extra_linkopts = ["-dynamiclib"]
if ctx.attr.extension_safe:
extra_linkopts.append("-fapplication-extension")

link_result = linking_support.register_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
extra_linkopts = extra_linkopts,
stamp = ctx.attr.stamp,
)
binary_artifact = link_result.binary
debug_outputs_provider = link_result.debug_outputs_provider

actions = ctx.actions
apple_toolchain_info = ctx.attr._toolchain[AppleSupportToolchainInfo]
Expand Down Expand Up @@ -1131,6 +1123,25 @@ def _ios_dynamic_framework_impl(ctx):
bundle_name + rule_descriptor.bundle_extension,
]

extra_linkopts = [
"-dynamiclib",
"-Wl,-install_name,@rpath/{name}{extension}/{name}".format(
extension = bundle_extension,
name = bundle_name,
),
]
if ctx.attr.extension_safe:
extra_linkopts.append("-fapplication-extension")

link_result = linking_support.register_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
extra_linkopts = extra_linkopts,
stamp = ctx.attr.stamp,
)
binary_artifact = link_result.binary
debug_outputs_provider = link_result.debug_outputs_provider

archive_for_embedding = outputs.archive_for_embedding(
actions = actions,
bundle_name = bundle_name,
Expand Down
47 changes: 30 additions & 17 deletions apple/internal/tvos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,6 @@ def _tvos_dynamic_framework_impl(ctx):
)

binary_target = ctx.attr.deps[0]
link_result = linking_support.register_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
extra_linkopts = ["-dynamiclib"],
stamp = ctx.attr.stamp,
)
binary_artifact = link_result.binary
debug_outputs_provider = link_result.debug_outputs_provider

actions = ctx.actions
apple_toolchain_info = ctx.attr._toolchain[AppleSupportToolchainInfo]
Expand Down Expand Up @@ -381,6 +373,21 @@ def _tvos_dynamic_framework_impl(ctx):
bundle_name + rule_descriptor.bundle_extension,
]

link_result = linking_support.register_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
extra_linkopts = [
"-dynamiclib",
"-Wl,-install_name,@rpath/{name}{extension}/{name}".format(
extension = bundle_extension,
name = bundle_name,
),
],
stamp = ctx.attr.stamp,
)
binary_artifact = link_result.binary
debug_outputs_provider = link_result.debug_outputs_provider

archive = outputs.archive(
actions = actions,
bundle_extension = bundle_extension,
Expand Down Expand Up @@ -538,15 +545,6 @@ def _tvos_dynamic_framework_impl(ctx):

def _tvos_framework_impl(ctx):
"""Experimental implementation of tvos_framework."""
link_result = linking_support.register_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
extra_linkopts = ["-dynamiclib"],
stamp = ctx.attr.stamp,
)
binary_artifact = link_result.binary
debug_outputs_provider = link_result.debug_outputs_provider

actions = ctx.actions
apple_toolchain_info = ctx.attr._toolchain[AppleSupportToolchainInfo]
bin_root_path = ctx.bin_dir.path
Expand Down Expand Up @@ -580,6 +578,21 @@ def _tvos_framework_impl(ctx):
res_attrs = ["resources"],
)

link_result = linking_support.register_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
extra_linkopts = [
"-dynamiclib",
"-Wl,-install_name,@rpath/{name}{extension}/{name}".format(
extension = bundle_extension,
name = bundle_name,
),
],
stamp = ctx.attr.stamp,
)
binary_artifact = link_result.binary
debug_outputs_provider = link_result.debug_outputs_provider

archive = outputs.archive(
actions = actions,
bundle_extension = bundle_extension,
Expand Down
31 changes: 19 additions & 12 deletions apple/internal/watchos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,6 @@ def _watchos_dynamic_framework_impl(ctx):
)

binary_target = ctx.attr.deps[0]
extra_linkopts = ["-dynamiclib"]
if ctx.attr.extension_safe:
extra_linkopts.append("-fapplication-extension")

link_result = linking_support.register_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
extra_linkopts = extra_linkopts,
stamp = ctx.attr.stamp,
)
binary_artifact = link_result.binary
debug_outputs_provider = link_result.debug_outputs_provider

actions = ctx.actions
apple_toolchain_info = ctx.attr._toolchain[AppleSupportToolchainInfo]
Expand Down Expand Up @@ -160,6 +148,25 @@ def _watchos_dynamic_framework_impl(ctx):
bundle_name + rule_descriptor.bundle_extension,
]

extra_linkopts = [
"-dynamiclib",
"-Wl,-install_name,@rpath/{name}{extension}/{name}".format(
extension = bundle_extension,
name = bundle_name,
),
]
if ctx.attr.extension_safe:
extra_linkopts.append("-fapplication-extension")

link_result = linking_support.register_linking_action(
ctx,
avoid_deps = ctx.attr.frameworks,
extra_linkopts = extra_linkopts,
stamp = ctx.attr.stamp,
)
binary_artifact = link_result.binary
debug_outputs_provider = link_result.debug_outputs_provider

archive_for_embedding = outputs.archive_for_embedding(
actions = actions,
bundle_name = bundle_name,
Expand Down
27 changes: 3 additions & 24 deletions apple/ios.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,12 @@ def ios_extension(name, **kwargs):
def ios_framework(name, **kwargs):
# buildifier: disable=function-docstring-args
"""Builds and bundles an iOS dynamic framework."""
binary_args = dict(kwargs)

# TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking
# API does not accept extra linkopts and link inputs. With those, it will be possible to merge
# these workarounds into the rule implementations.
bundle_name = binary_args.get("bundle_name", name)
binary_args["linkopts"] = binary_args.pop("linkopts", []) + [
"-install_name,@rpath/%s.framework/%s" % (bundle_name, bundle_name),
]

bundling_args = binary_support.add_entitlements(
name,
include_entitlements = False,
platform_type = str(apple_common.platform_type.ios),
product_type = apple_product_type.framework,
**binary_args
**kwargs
)

# Remove any kwargs that shouldn't be passed to the underlying rule.
Expand All @@ -124,24 +114,13 @@ def ios_framework(name, **kwargs):
def ios_dynamic_framework(name, **kwargs):
# buildifier: disable=function-docstring-args
"""Builds and bundles an iOS dynamic framework that is consumable by Xcode."""

binary_args = dict(kwargs)

# TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking
# API does not accept extra linkopts and link inputs. With those, it will be possible to merge
# these workarounds into the rule implementations.
bundle_name = binary_args.get("bundle_name", name)
binary_args["linkopts"] = binary_args.pop("linkopts", []) + [
"-install_name",
"@rpath/%s.framework/%s" % (bundle_name, bundle_name),
]
bundling_args = binary_support.add_entitlements(
name,
include_entitlements = False,
platform_type = str(apple_common.platform_type.ios),
product_type = apple_product_type.framework,
exported_symbols_lists = binary_args.pop("exported_symbols_lists", None),
**binary_args
exported_symbols_lists = kwargs.pop("exported_symbols_lists", None),
**kwargs
)

# Remove any kwargs that shouldn't be passed to the underlying rule.
Expand Down
27 changes: 3 additions & 24 deletions apple/tvos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,11 @@ def tvos_extension(name, **kwargs):
def tvos_framework(name, **kwargs):
# buildifier: disable=function-docstring-args
"""Builds and bundles a tvOS dynamic framework."""
binary_args = dict(kwargs)

# TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking
# API does not accept extra linkopts and link inputs. With those, it will be possible to merge
# these workarounds into the rule implementations.
bundle_name = binary_args.get("bundle_name", name)
binary_args["linkopts"] = binary_args.pop("linkopts", []) + [
"-install_name,@rpath/%s.framework/%s" % (bundle_name, bundle_name),
]

bundling_args = binary_support.add_entitlements(
name,
platform_type = str(apple_common.platform_type.tvos),
product_type = apple_product_type.framework,
**binary_args
**kwargs
)

# Remove any kwargs that shouldn't be passed to the underlying rule.
Expand Down Expand Up @@ -156,24 +146,13 @@ def tvos_ui_test(name, **kwargs):
def tvos_dynamic_framework(name, **kwargs):
# buildifier: disable=function-docstring-args
"""Builds and bundles a tvOS dynamic framework that is consumable by Xcode."""

binary_args = dict(kwargs)

# TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking
# API does not accept extra linkopts and link inputs. With those, it will be possible to merge
# these workarounds into the rule implementations.
bundle_name = binary_args.get("bundle_name", name)
binary_args["linkopts"] = binary_args.pop("linkopts", []) + [
"-install_name",
"@rpath/%s.framework/%s" % (bundle_name, bundle_name),
]
bundling_args = binary_support.add_entitlements(
name,
include_entitlements = False,
platform_type = str(apple_common.platform_type.watchos),
product_type = apple_product_type.framework,
exported_symbols_lists = binary_args.pop("exported_symbols_lists", None),
**binary_args
exported_symbols_lists = kwargs.pop("exported_symbols_lists", None),
**kwargs
)

# Remove any kwargs that shouldn't be passed to the underlying rule.
Expand Down
15 changes: 2 additions & 13 deletions apple/watchos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,13 @@ def watchos_extension(name, **kwargs):
def watchos_dynamic_framework(name, **kwargs):
# buildifier: disable=function-docstring-args
"""Builds and bundles a watchOS dynamic framework that is consumable by Xcode."""

binary_args = dict(kwargs)

# TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking
# API does not accept extra linkopts and link inputs. With those, it will be possible to merge
# these workarounds into the rule implementations.
bundle_name = binary_args.get("bundle_name", name)
binary_args["linkopts"] = binary_args.pop("linkopts", []) + [
"-install_name",
"@rpath/%s.framework/%s" % (bundle_name, bundle_name),
]
bundling_args = binary_support.add_entitlements(
name,
include_entitlements = False,
platform_type = str(apple_common.platform_type.watchos),
product_type = apple_product_type.framework,
exported_symbols_lists = binary_args.pop("exported_symbols_lists", None),
**binary_args
exported_symbols_lists = kwargs.pop("exported_symbols_lists", None),
**kwargs
)

# Remove any kwargs that shouldn't be passed to the underlying rule.
Expand Down