Skip to content

Commit 46d6c2a

Browse files
authored
Add @loader_path/Frameworks rpath when building frameworks, as Xcode does (#2850)
1 parent 1362207 commit 46d6c2a

6 files changed

Lines changed: 99 additions & 1 deletion

File tree

apple/internal/rule_support.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ _RULE_TYPE_DESCRIPTORS = {
218218
# Frameworks are packaged in Application.app/Frameworks or
219219
# Application.app/PlugIns/Extension.appex/Frameworks
220220
"@executable_path/Frameworks",
221+
# Xcode also adds this path when building frameworks.
222+
"@loader_path/Frameworks",
221223
],
222224
),
223225
# ios_imessage_application
@@ -540,6 +542,8 @@ _RULE_TYPE_DESCRIPTORS = {
540542
# Frameworks are packaged in Application.app/Frameworks or
541543
# Application.app/PlugIns/Extension.appex/Frameworks
542544
"@executable_path/Frameworks",
545+
# Xcode also adds this path when building frameworks.
546+
"@loader_path/Frameworks",
543547
],
544548
),
545549
# tvos_static_framework
@@ -626,6 +630,8 @@ _RULE_TYPE_DESCRIPTORS = {
626630
# Frameworks are packaged in Application.app/Frameworks or
627631
# Application.app/PlugIns/Extension.appex/Frameworks
628632
"@executable_path/Frameworks",
633+
# Xcode also adds this path when building frameworks.
634+
"@loader_path/Frameworks",
629635
],
630636
),
631637
# visionos_static_framework
@@ -723,6 +729,8 @@ _RULE_TYPE_DESCRIPTORS = {
723729
# Frameworks are packaged in Application.app/Frameworks or
724730
# Application.app/PlugIns/Extension.appex/Frameworks
725731
"@executable_path/Frameworks",
732+
# Xcode also adds this path when building frameworks.
733+
"@loader_path/Frameworks",
726734
],
727735
),
728736
# watchos_static_framework

test/starlark_tests/common.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ _min_os_watchos = struct(
7575
icon_bundle_required = "26.0",
7676
requires_single_target_app = "9.0",
7777
single_target_app = "7.0",
78+
requires_single_target_app_nplus1 = "10.0",
7879
stable_swift_abi = "6.0",
7980
test_runner_support = "7.4",
8081
)

test/starlark_tests/ios_framework_tests.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ def ios_framework_test_suite(name):
8585
build_type = "simulator",
8686
target_under_test = "//test/starlark_tests/targets_under_test/ios:fmwk",
8787
binary_test_file = "$BUNDLE_ROOT/fmwk",
88-
macho_load_commands_contain = ["name @rpath/fmwk.framework/fmwk (offset 24)"],
88+
macho_load_commands_contain = [
89+
"name @rpath/fmwk.framework/fmwk (offset 24)",
90+
"path @executable_path/Frameworks (offset 12)",
91+
"path @loader_path/Frameworks (offset 12)",
92+
],
8993
contains = [
9094
"$BUNDLE_ROOT/fmwk",
9195
"$BUNDLE_ROOT/Headers/common.h",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
load("//apple:watchos.bzl", "watchos_framework")
2+
load(
3+
"//test/starlark_tests:common.bzl",
4+
"common",
5+
)
6+
7+
licenses(["notice"])
8+
9+
package(
10+
default_testonly = True,
11+
default_visibility = ["//test/starlark_tests:__subpackages__"],
12+
)
13+
14+
watchos_framework(
15+
name = "fmwk",
16+
bundle_id = "com.google.example.framework",
17+
extension_safe = True,
18+
infoplists = [
19+
"//test/starlark_tests/resources:Info.plist",
20+
"//test/starlark_tests/resources:Another.plist",
21+
],
22+
minimum_os_version = common.min_os_watchos.requires_single_target_app,
23+
tags = common.fixture_tags,
24+
deps = [
25+
"//test/starlark_tests/resources:objc_shared_lib_with_transitive_resources",
26+
],
27+
)
28+
29+
watchos_framework(
30+
name = "fmwk_with_no_version",
31+
bundle_id = "com.google.example.framework",
32+
infoplists = [
33+
"//test/starlark_tests/resources:Info-noversion.plist",
34+
],
35+
minimum_os_version = common.min_os_watchos.requires_single_target_app,
36+
tags = common.fixture_tags,
37+
deps = [
38+
"//test/starlark_tests/resources:objc_shared_lib",
39+
],
40+
)

test/starlark_tests/tvos_framework_tests.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ def tvos_framework_test_suite(name):
9393
binary_test_file = "$BUNDLE_ROOT/fmwk",
9494
macho_load_commands_contain = [
9595
"name @rpath/fmwk.framework/fmwk (offset 24)",
96+
"path @executable_path/Frameworks (offset 12)",
97+
"path @loader_path/Frameworks (offset 12)",
9698
],
9799
tags = [name],
98100
)

test/starlark_tests/watchos_framework_tests.bzl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,49 @@ def watchos_framework_test_suite(name):
5454
tags = [name],
5555
)
5656

57+
# Tests that the bundled .framework contains the expected files.
58+
archive_contents_test(
59+
name = "{}_contains_expected_files".format(name),
60+
build_type = "simulator",
61+
target_under_test = "//test/starlark_tests/targets_under_test/watchos/frameworks:fmwk",
62+
contains = [
63+
"$BUNDLE_ROOT/fmwk",
64+
"$BUNDLE_ROOT/Info.plist",
65+
],
66+
tags = [name],
67+
)
68+
69+
# Tests that the correct rpath was added at link-time to the framework's binary.
70+
# The rpath should match the framework bundle name.
71+
archive_contents_test(
72+
name = "{}_binary_has_correct_rpath".format(name),
73+
build_type = "simulator",
74+
target_under_test = "//test/starlark_tests/targets_under_test/watchos/frameworks:fmwk",
75+
contains = [
76+
"$BUNDLE_ROOT/fmwk",
77+
"$BUNDLE_ROOT/Info.plist",
78+
],
79+
binary_test_file = "$BUNDLE_ROOT/fmwk",
80+
macho_load_commands_contain = [
81+
"name @rpath/fmwk.framework/fmwk (offset 24)",
82+
"path @executable_path/Frameworks (offset 12)",
83+
"path @loader_path/Frameworks (offset 12)",
84+
],
85+
tags = [name],
86+
)
87+
88+
# Tests that a watchos_framework builds fine without any version info
89+
# since it isn't required.
90+
infoplist_contents_test(
91+
name = "{}_plist_test_with_no_version".format(name),
92+
target_under_test = "//test/starlark_tests/targets_under_test/watchos/frameworks:fmwk_with_no_version",
93+
not_expected_keys = [
94+
"CFBundleVersion",
95+
"CFBundleShortVersionString",
96+
],
97+
tags = [name],
98+
)
99+
57100
archive_contents_test(
58101
name = "{}_exported_symbols_list_test".format(name),
59102
build_type = "simulator",

0 commit comments

Comments
 (0)