Skip to content

Commit

Permalink
add application_extension attribute to apple_binary
Browse files Browse the repository at this point in the history
Summary: We need a way to determine between extension binaries and app binaries. Add a boolean attribute that we can set on `apple_binary`.

Reviewed By: d16r

Differential Revision: D68783951

fbshipit-source-id: a259e26910aa4eb5ba829a6d039f4188335be60e
  • Loading branch information
rmaz authored and facebook-github-bot committed Jan 28, 2025
1 parent 5a87c1d commit 5a7e5f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion prelude/apple/apple_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ def apple_binary_impl(ctx: AnalysisContext) -> [list[Provider], Promise]:
swift_preprocessor = [swift_compile.pre] if swift_compile else []
extra_link_flags = entitlements_link_flags(ctx)

# Extensions have custom entry points and API restrictions
extension_compiler_flags = []
if ctx.attrs.application_extension:
extra_link_flags += [
"-fapplication-extension",
"-e",
"_NSExtensionMain",
]
extension_compiler_flags = ["-fapplication-extension"]

framework_search_path_pre = CPreprocessor(
args = CPreprocessorArgs(args = [framework_search_path_flags]),
)
Expand Down Expand Up @@ -153,7 +163,7 @@ def apple_binary_impl(ctx: AnalysisContext) -> [list[Provider], Promise]:
# Some apple rules rely on `static` libs *not* following dependents.
link_groups_force_static_follows_dependents = False,
swiftmodule_linkable = get_swiftmodule_linkable(swift_compile),
compiler_flags = ctx.attrs.compiler_flags,
compiler_flags = ctx.attrs.compiler_flags + extension_compiler_flags,
lang_compiler_flags = ctx.attrs.lang_compiler_flags,
platform_compiler_flags = ctx.attrs.platform_compiler_flags,
lang_platform_compiler_flags = ctx.attrs.lang_platform_compiler_flags,
Expand Down
1 change: 1 addition & 0 deletions prelude/apple/apple_rules_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ _APPLE_TOOLCHAIN_ATTR = get_apple_toolchain_attr()

def _apple_binary_extra_attrs():
attribs = {
"application_extension": attrs.bool(default = False),
"binary_linker_flags": attrs.list(attrs.arg(), default = []),
"dist_thin_lto_codegen_flags": attrs.list(attrs.arg(), default = []),
"enable_distributed_thinlto": attrs.bool(default = False),
Expand Down
3 changes: 3 additions & 0 deletions prelude/apple/swift/swift_compilation.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,9 @@ def _get_shared_flags(
if ctx.attrs._swift_enable_testing:
cmd.add("-enable-testing")

if getattr(ctx.attrs, "application_extension", False):
cmd.add("-application-extension")

pcm_deps_tset = get_compiled_pcm_deps_tset(ctx, deps_providers)

# If Swift Explicit Modules are enabled, a few things must be provided to a compilation job:
Expand Down

0 comments on commit 5a7e5f6

Please sign in to comment.