Skip to content

Commit 3dba37b

Browse files
author
Karim Alweheshy
committed
Generate non recursive LIBRARY_SEARCH_PATHS paths
Only for transitive deps with a .a output file Signed-off-by: Karim Alweheshy <[email protected]>
1 parent d78f143 commit 3dba37b

10 files changed

+71
-5
lines changed

tools/generators/pbxnativetargets/src/Generator/CalculatePlatformVariantBuildSettings.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ extension Generator.CalculatePlatformVariantBuildSettings {
183183
)
184184
}
185185

186+
buildSettings.append(
187+
.init(
188+
key: "LIBRARY_SEARCH_PATHS",
189+
value: platformVariant.librarySearchPaths
190+
.map { $0.path.quoteIfNeeded }
191+
// TODO: See if we can not sort, or sort earlier
192+
.sorted()
193+
.joined(separator: " ")
194+
.pbxProjEscaped
195+
)
196+
)
197+
186198
buildSettings.append(contentsOf: platformVariant.buildSettingsFromFile)
187199

188200
return buildSettings

tools/generators/pbxnativetargets/src/Generator/CalculatePlatformVariants.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ extension Generator.CalculatePlatformVariants {
134134
.flatMap { unitTestHosts[$0] },
135135
dSYMPathsBuildSetting:
136136
targetArguments.dSYMPathsBuildSetting.isEmpty ?
137-
nil : targetArguments.dSYMPathsBuildSetting
137+
nil : targetArguments.dSYMPathsBuildSetting,
138+
librarySearchPaths: Set(targetArguments.librarySearchPaths)
138139
)
139140
)
140141
}

tools/generators/pbxnativetargets/src/Generator/CalculateXcodeConfigurationBuildSettings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private extension Platform {
236236
}
237237
}
238238

239-
private extension String {
239+
extension String {
240240
var quoteIfNeeded: String {
241241
guard !contains(" ") else {
242242
return #""\#(self)""#

tools/generators/pbxnativetargets/src/Generator/Target.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ enum Target {
3333
let linkParams: String?
3434
let unitTestHost: UnitTestHost?
3535
let dSYMPathsBuildSetting: String?
36+
let librarySearchPaths: Set<BazelPath>
3637
}
3738

3839
struct UnitTestHost: Equatable {

tools/generators/pbxnativetargets/src/Generator/TargetArguments.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct TargetArguments: Equatable {
2929
let nonArcSrcs: [BazelPath]
3030

3131
let dSYMPathsBuildSetting: String
32+
let librarySearchPaths: [BazelPath]
3233
}
3334

3435
extension Dictionary<TargetID, TargetArguments> {
@@ -92,6 +93,11 @@ extension Dictionary<TargetID, TargetArguments> {
9293
"xcode-configurations",
9394
in: url
9495
)
96+
let librarySearchPaths = try rawArgs.consumeArgs(
97+
"library-search-paths",
98+
as: BazelPath.self,
99+
in: url
100+
)
95101

96102
var buildSettings: [PlatformVariantBuildSetting] = []
97103
if let buildSettingsFile {
@@ -130,7 +136,8 @@ extension Dictionary<TargetID, TargetArguments> {
130136
hasCxxParams: hasCxxParams,
131137
srcs: srcs,
132138
nonArcSrcs: nonArcSrcs,
133-
dSYMPathsBuildSetting: dSYMPathsBuildSetting
139+
dSYMPathsBuildSetting: dSYMPathsBuildSetting,
140+
librarySearchPaths: librarySearchPaths
134141
)
135142
)
136143
)

xcodeproj/internal/files/linker_input_files.bzl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,44 @@ def _collect_linker_inputs(
6363
)
6464
top_level_values = None
6565

66+
all_libs = objc_libraries + [
67+
lib.static_library if lib.static_library else lib.dynamic_library
68+
for linker_input in cc_linker_inputs
69+
for lib in linker_input.libraries
70+
]
71+
72+
libraries = [
73+
lib
74+
for lib in all_libs
75+
if lib.basename.endswith(".a")
76+
]
77+
78+
linker_inputs_for_libs_search_paths = depset([
79+
lib.dirname
80+
for lib in libraries
81+
])
82+
83+
_framework_files = depset([
84+
lib.basename
85+
for lib in libraries
86+
])
87+
6688
return struct(
6789
_cc_linker_inputs = tuple(cc_linker_inputs),
6890
_compilation_providers = compilation_providers,
6991
_objc_libraries = tuple(objc_libraries),
7092
_primary_static_library = primary_static_library,
7193
_top_level_values = top_level_values,
94+
_linker_inputs_for_libs_search_paths = linker_inputs_for_libs_search_paths,
95+
_framework_files = _framework_files,
7296
)
7397

98+
def _extract_linker_inputs_for_libs_search_paths(linker_inputs):
99+
return linker_inputs._linker_inputs_for_libs_search_paths
100+
101+
def _extract_framework_file_names(linker_inputs):
102+
return linker_inputs._framework_files
103+
74104
def _merge_linker_inputs(*, compilation_providers):
75105
return _collect_linker_inputs(
76106
target = None,
@@ -386,4 +416,6 @@ linker_input_files = struct(
386416
_get_transitive_static_libraries_for_bwx
387417
),
388418
to_input_files = _to_input_files,
419+
get_linker_inputs_for_libs_search_paths = _extract_linker_inputs_for_libs_search_paths,
420+
get_framework_file_names = _extract_framework_file_names,
389421
)

xcodeproj/internal/incremental_xcode_targets.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ def _make_incremental_xcode_target(
8383
test_host = None,
8484
transitive_dependencies,
8585
unfocus_if_not_test_host = False,
86-
watchkit_extension = None):
86+
watchkit_extension = None,
87+
linker_inputs_for_libs_search_paths):
8788
"""Creates the internal data structure of the `xcode_targets` module.
8889
8990
Args:
@@ -167,6 +168,7 @@ def _make_incremental_xcode_target(
167168
test_host = test_host,
168169
watchkit_extension = watchkit_extension,
169170
transitive_dependencies = transitive_dependencies,
171+
linker_inputs_for_libs_search_paths = linker_inputs_for_libs_search_paths,
170172
)
171173

172174
def _merge_xcode_inputs(*, dest_inputs, mergeable_info):

xcodeproj/internal/pbxproj_partials.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ def _write_consolidation_map_targets(
316316
terminate_with = "",
317317
)
318318

319+
targets_args.add_all(
320+
xcode_target.linker_inputs_for_libs_search_paths.to_list(),
321+
omit_if_empty = False,
322+
terminate_with = "",
323+
)
324+
319325
# `outputs.product_path` is only set for top-level targets
320326
if xcode_target.outputs.product_path:
321327
top_level_targets_args.add(xcode_target.id)
@@ -1095,7 +1101,8 @@ def _write_target_build_settings(
10951101
swift_args,
10961102
swift_debug_settings_to_merge = EMPTY_DEPSET,
10971103
team_id = None,
1098-
tool):
1104+
tool,
1105+
linker_inputs_for_libs_search_paths = EMPTY_DEPSET):
10991106
"""Creates the `OTHER_SWIFT_FLAGS` build setting string file for a target.
11001107
11011108
Args:

xcodeproj/internal/processed_targets/incremental_library_targets.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ def _process_incremental_library_target(
231231
platform = platform,
232232
product = product.xcode_product,
233233
transitive_dependencies = transitive_dependencies,
234+
linker_inputs_for_libs_search_paths = linker_input_files
235+
.get_linker_inputs_for_libs_search_paths(linker_inputs),
234236
)
235237
else:
236238
mergeable_infos = depset(

xcodeproj/internal/processed_targets/incremental_top_level_targets.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ def _process_focused_top_level_target(
628628
transitive_dependencies = transitive_dependencies,
629629
unfocus_if_not_test_host = unfocus_if_not_test_host,
630630
watchkit_extension = watchkit_extension,
631+
linker_inputs_for_libs_search_paths = linker_input_files
632+
.get_linker_inputs_for_libs_search_paths(linker_inputs),
631633
),
632634
)
633635

0 commit comments

Comments
 (0)