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

I need to apply a transition on a target defined by ios_extension rule #2558

Open
vakhidbetrakhmadov opened this issue Oct 18, 2024 · 2 comments · Fixed by revolut-mobile/rules_apple#9 · May be fixed by #2559
Open

I need to apply a transition on a target defined by ios_extension rule #2558

vakhidbetrakhmadov opened this issue Oct 18, 2024 · 2 comments · Fixed by revolut-mobile/rules_apple#9 · May be fixed by #2559

Comments

@vakhidbetrakhmadov
Copy link
Contributor

vakhidbetrakhmadov commented Oct 18, 2024

Hello,

I need to apply a transition on a target defined by ios_extension rule.

I have the following setup:

App -> Extension 
App -> Module_A -> Module_B -> Module_C -> ... -> Module_Z
Extension -> Module_B -> Module_C 
  • Modules are statically linked into top level targets: App, Extension.
  • Module_C is the largest module.

In order to reduce App size, i would like to flavour Module_C for Extension.

In order to flavour Module_C for Extension i need to propagate a custom build setting along the Extension -> ... dependency tree.

I have done some research and it looks like that at the moment there is no supported way of applying a transition on a target defined by a third party rule.

The most commonly proposed workaround that i found is to create a wrapper rule around the third party rule.
The wrapper rule can apply required transitions on the wrapped rule and propagate its providers.

I have pretty much done this with ios_extension, but there is an issue that i am facing.

The issue is that not all ios_extension's providers are accessible from outside of rules_apple, and without for example AppleDebugInfo no dSYMs for Extension are generated, or without _AppleSymbolsFileInfo no .symbols for Extension are generated.

I didn't find any difference in the output with/without _AppleCodesigningDossierInfo, AppleExtensionSafeValidationInfo, _AppleSwiftDylibsInfo.

load("//Bazel/flavour:flavour_transition.bzl", "flavour_transition")
load(
    "@build_bazel_rules_apple//apple:providers.bzl",
    "AppleBundleInfo",
    "AppleCodesigningDossierInfo",
    "AppleDsymBundleInfo",
    "AppleResourceInfo",
    "IosExtensionBundleInfo",
)
load(
    "@build_bazel_rules_apple//apple/internal/providers:embeddable_info.bzl",
    "AppleEmbeddableInfo",
)

def _flavoured_ios_extension_impl(ctx):
    ios_extension = ctx.attr.ios_extension[0]

    # The list of providers extracted from the `print(ios_extension)` output (unaccessible providers are commented out).
    ios_extension_providers = [
        DefaultInfo,
        apple_common.AppleExecutableBinary,
        IosExtensionBundleInfo,
        apple_common.AppleDebugOutputs,
        AppleBundleInfo,
        # _AppleCodesigningDossierInfo,
        AppleCodesigningDossierInfo,
        AppleDsymBundleInfo,
        # AppleDebugInfo,
        AppleEmbeddableInfo,
        # _AppleExtensionSafeValidationInfo,
        AppleResourceInfo,
        # _AppleSwiftDylibsInfo,
        # _AppleSymbolsFileInfo,
        OutputGroupInfo,
    ]

    return [
        ios_extension[provider]
        for provider in ios_extension_providers
        if provider in ios_extension
    ]

flavoured_ios_extension = rule(
    implementation = _flavoured_ios_extension_impl,
    doc = "ios_extension wrapper that applies flavour_transition",
    attrs = {
        "ios_extension": attr.label(mandatory = True, cfg = flavour_transition),
        "flavour": attr.string(mandatory = True),
        "_allowlist_function_transition": attr.label(default = "@bazel_tools//tools/allowlists/function_transition_allowlist"),
    },
)
vakhidbetrakhmadov added a commit to vakhidbetrakhmadov/rules_apple that referenced this issue Oct 18, 2024
vakhidbetrakhmadov added a commit to vakhidbetrakhmadov/rules_apple that referenced this issue Oct 18, 2024
vakhidbetrakhmadov added a commit to vakhidbetrakhmadov/rules_apple that referenced this issue Oct 18, 2024
acecilia pushed a commit to revolut-mobile/rules_apple that referenced this issue Oct 18, 2024
vakhidbetrakhmadov added a commit to vakhidbetrakhmadov/rules_apple that referenced this issue Oct 18, 2024
vakhidbetrakhmadov added a commit to vakhidbetrakhmadov/rules_apple that referenced this issue Oct 18, 2024
@brentleyjones
Copy link
Collaborator

@fmeum Do you know a way to forward providers in a transition without them being public? Ideally we wouldn't have to make the change that #2559 is proposing.

@fmeum
Copy link

fmeum commented Oct 25, 2024

I don't think that's possible at the moment. There's been some discussion about introducing a way to forward all but a select few providers, but the last time that came up was a year ago.

vakhidbetrakhmadov added a commit to vakhidbetrakhmadov/rules_apple that referenced this issue Oct 31, 2024
vakhidbetrakhmadov added a commit to vakhidbetrakhmadov/rules_apple that referenced this issue Nov 4, 2024
vakhidbetrakhmadov added a commit to vakhidbetrakhmadov/rules_apple that referenced this issue Nov 7, 2024
vakhidbetrakhmadov added a commit to vakhidbetrakhmadov/rules_apple that referenced this issue Nov 7, 2024
acecilia pushed a commit to revolut-mobile/rules_apple that referenced this issue Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants