Skip to content

Commit

Permalink
add apple_test rpaths
Browse files Browse the repository at this point in the history
Summary: Add rpaths for apple_test targets when `prelude_rpaths=True`.

Reviewed By: d16r

Differential Revision: D68902729

fbshipit-source-id: 64f57c5c4ae20f752884e417f487c74b4d976114
  • Loading branch information
rmaz authored and facebook-github-bot committed Jan 30, 2025
1 parent 3e7c248 commit 20cd2fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions apple/apple_rpaths.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ _MACOS_LIBRARY_RPATHS = _rpath_flags_for_paths([
"@loader_path/Frameworks",
])

_MACOS_TEST_RPATHS = _rpath_flags_for_paths([
# loader_path = MyApp.app/Contents/PlugIns/TestBundle.xctest/Contents/MacOS
"@loader_path/../Frameworks",
# executable_path = MyApp.app/Contents/MacOS
"@executable_path/../Frameworks",
])

_IOS_BINARY_RPATHS = _rpath_flags_for_paths([
# @executable_path = MyApp.app
"@executable_path/Frameworks",
Expand All @@ -45,6 +52,13 @@ _IOS_LIBRARY_RPATHS = _rpath_flags_for_paths([
"@loader_path/Frameworks",
])

_IOS_TEST_RPATHS = _rpath_flags_for_paths([
# loader_path = MyApp.app/PlugIns/TestBundle.xctest
"@loader_path/Frameworks",
# executable_path = MyApp.app
"@executable_path/Frameworks",
])

def _is_mac_binary(ctx: AnalysisContext) -> bool:
return get_apple_sdk_name(ctx).startswith("mac")

Expand All @@ -70,3 +84,12 @@ def get_rpath_flags_for_library(ctx: AnalysisContext) -> list[str]:
return _MACOS_LIBRARY_RPATHS
else:
return _IOS_LIBRARY_RPATHS

def get_rpath_flags_for_tests(ctx: AnalysisContext) -> list[str]:
if not ctx.attrs._apple_toolchain[AppleToolchainInfo].prelude_rpaths:
return []

if _is_mac_binary(ctx):
return _MACOS_TEST_RPATHS
else:
return _IOS_TEST_RPATHS
3 changes: 2 additions & 1 deletion apple/apple_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ load(":apple_bundle_types.bzl", "AppleBundleInfo")
load(":apple_bundle_utility.bzl", "get_product_name")
load(":apple_dsym.bzl", "DSYM_SUBTARGET", "DWARF_AND_DSYM_SUBTARGET", "get_apple_dsym")
load(":apple_entitlements.bzl", "entitlements_link_flags")
load(":apple_rpaths.bzl", "get_rpath_flags_for_tests")
load(":apple_sdk.bzl", "get_apple_sdk_name")
load(
":apple_sdk_metadata.bzl",
Expand Down Expand Up @@ -72,7 +73,7 @@ def apple_test_impl(ctx: AnalysisContext) -> [list[Provider], Promise]:

# Embedding entitlements (if present) means that we can skip adhoc codesigning
# any xctests altogether, provided the test dylib is adhoc signed
shared_library_flags += entitlements_link_flags(ctx)
shared_library_flags += entitlements_link_flags(ctx) + get_rpath_flags_for_tests(ctx)

# The linker will include adhoc signature for ARM64 by default, lets
# ensure we always have an adhoc signature regardless of arch/linker logic.
Expand Down

0 comments on commit 20cd2fa

Please sign in to comment.