Skip to content

Generate non recursive LIBRARY_SEARCH_PATHS paths #3135

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension Generator.CreateBuildFileObject {
settings = #"settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; "#
case .compileStub, .source:
settings = ""
case .product, .watchKitExtension:
case .product, .watchKitExtension, .framework:
// Handled in `CreateProductBuildFileObject` and
// `CreateProductObject`
preconditionFailure()
Expand Down
2 changes: 0 additions & 2 deletions tools/generators/legacy/src/Generator/CreateProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ $(PROJECT_TEMP_DIR)/$(BAZEL_PACKAGE_BIN_DIR)/$(COMPILE_TARGET_NAME)
"LD": "$(BAZEL_INTEGRATION_DIR)/ld",
"LDPLUSPLUS": "$(BAZEL_INTEGRATION_DIR)/ld",
"LIBTOOL": "$(BAZEL_INTEGRATION_DIR)/libtool",
"SWIFT_EXEC": "$(BAZEL_INTEGRATION_DIR)/swiftc",
"SWIFT_USE_INTEGRATED_DRIVER": false,
"TAPI_EXEC": "/usr/bin/true",
], uniquingKeysWith: { _, r in r })
} else {
Expand Down
2 changes: 0 additions & 2 deletions tools/generators/legacy/test/CreateProjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,9 @@ $(BUILD_DIR)/$(BAZEL_PACKAGE_BIN_DIR)
"RULES_XCODEPROJ_BUILD_MODE": "bazel",
"SRCROOT": directories.workspace.string,
"SUPPORTS_MACCATALYST": false,
"SWIFT_EXEC": "$(BAZEL_INTEGRATION_DIR)/swiftc",
"TAPI_EXEC": "/usr/bin/true",
"SWIFT_OBJC_INTERFACE_HEADER_NAME": "",
"SWIFT_OPTIMIZATION_LEVEL": "-Onone",
"SWIFT_USE_INTEGRATED_DRIVER": false,
"SWIFT_VERSION": "5.0",
"TARGET_TEMP_DIR": """
$(PROJECT_TEMP_DIR)/$(BAZEL_PACKAGE_BIN_DIR)/$(COMPILE_TARGET_NAME)
Expand Down
2 changes: 2 additions & 0 deletions tools/generators/lib/PBXProj/src/BuildPhase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum BuildPhase {
case sources
case copySwiftGeneratedHeader
case embedAppExtensions
case linkBinaryWithLibraries

public var name: String {
switch self {
Expand All @@ -16,6 +17,7 @@ Copy Bazel Outputs / Generate Bazel Dependencies (Index Build)
case .sources: return "Sources"
case .copySwiftGeneratedHeader: return "Copy Swift Generated Header"
case .embedAppExtensions: return "Embed App Extensions"
case .linkBinaryWithLibraries: return "Frameworks"
}
}
}
13 changes: 13 additions & 0 deletions tools/generators/lib/PBXProj/src/Identifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ FF01000000000000000001\#(byteHexStrings[index]!) \#
/// The product reference for a target.
case product = "P"

/// The framework reference for a target in libraries to link build phase.
case framework = "f"

/// A normal file referenced in a `BuildPhase.sources` build phase.
case source = "0"

Expand Down Expand Up @@ -186,6 +189,14 @@ FF01000000000000000001\#(byteHexStrings[index]!) \#
return #"""
\#(subIdentifier.shard)00\#(subIdentifier.hash)0000000000FF \#
/* \#(subIdentifier.path.path) */
"""#

case .framework:
let basename = subIdentifier.path.path
.split(separator: "/").last!
return #"""
\#(subIdentifier.shard)A8\#(subIdentifier.hash) \#
/* \#(basename) in Frameworks */
"""#

case .compileStub:
Expand Down Expand Up @@ -535,6 +546,7 @@ private extension Identifiers.BuildFiles.FileType {
var buildPhase: BuildPhase {
switch self {
case .product: preconditionFailure() // product reference used as build file
case .framework: return .linkBinaryWithLibraries
case .source: return .sources
case .nonArcSource: return .sources
case .compileStub: return .sources
Expand Down Expand Up @@ -566,6 +578,7 @@ extension BuildPhase {
case .sources: return "06"
case .copySwiftGeneratedHeader: return "07"
case .embedAppExtensions: return "08"
case .linkBinaryWithLibraries: return "09"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ extension Generator.CalculatePlatformVariantBuildSettings {
)
}

buildSettings.append(
.init(
key: "LIBRARY_SEARCH_PATHS",
value: platformVariant.librarySearchPaths
.map {
let path = $0.path.split(separator: "/").dropFirst().joined(separator: "/")
return "\"$(BAZEL_OUT)/\(path)\""
}
.sorted()
.joined(separator: " ")
.pbxProjEscaped
)
)

buildSettings.append(contentsOf: platformVariant.buildSettingsFromFile)

return buildSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extension Generator.CalculatePlatformVariants {
) {
var srcs: [[BazelPath]] = []
var nonArcSrcs: [[BazelPath]] = []
var librariesToLinkPaths: [[BazelPath]] = []
var excludableFilesKeysWithValues: [(TargetID, Set<BazelPath>)] = []
for id in ids {
let targetArguments = try targetArguments.value(
Expand All @@ -68,6 +69,7 @@ extension Generator.CalculatePlatformVariants {

srcs.append(targetArguments.srcs)
nonArcSrcs.append(targetArguments.nonArcSrcs)
librariesToLinkPaths.append(targetArguments.librariesToLinkPaths)

excludableFilesKeysWithValues.append(
(
Expand Down Expand Up @@ -134,14 +136,16 @@ extension Generator.CalculatePlatformVariants {
.flatMap { unitTestHosts[$0] },
dSYMPathsBuildSetting:
targetArguments.dSYMPathsBuildSetting.isEmpty ?
nil : targetArguments.dSYMPathsBuildSetting
nil : targetArguments.dSYMPathsBuildSetting,
librarySearchPaths: Set(targetArguments.librarySearchPaths)
)
)
}

let consolidatedInputs = Target.ConsolidatedInputs(
srcs: consolidatePaths(srcs),
nonArcSrcs: consolidatePaths(nonArcSrcs)
nonArcSrcs: consolidatePaths(nonArcSrcs),
librariesToLinkPaths: consolidatePaths(librariesToLinkPaths)
)

return (platformVariants, allConditionalFiles, consolidatedInputs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private extension Platform {
}
}

private extension String {
extension String {
var quoteIfNeeded: String {
guard !contains(" ") else {
return #""\#(self)""#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ extension Generator {
CreateEmbedAppExtensionsBuildPhaseObject
private let createProductBuildFileObject: CreateProductBuildFileObject
private let createSourcesBuildPhaseObject: CreateSourcesBuildPhaseObject
private let createLinkBinaryWithLibrariesBuildPhaseObject:
CreateLinkBinaryWithLibrariesBuildPhaseObject
private let createFrameworkObject: CreateFrameworkObject
private let createFrameworkBuildFileObject: CreateFrameworkBuildFileObject

private let callable: Callable

Expand All @@ -31,6 +35,10 @@ extension Generator {
CreateEmbedAppExtensionsBuildPhaseObject,
createProductBuildFileObject: CreateProductBuildFileObject,
createSourcesBuildPhaseObject: CreateSourcesBuildPhaseObject,
createLinkBinaryWithLibrariesBuildPhaseObject:
CreateLinkBinaryWithLibrariesBuildPhaseObject,
createFrameworkObject: CreateFrameworkObject,
createFrameworkBuildFileObject: CreateFrameworkBuildFileObject,
callable: @escaping Callable = Self.defaultCallable
) {
self.createBazelIntegrationBuildPhaseObject =
Expand All @@ -44,6 +52,9 @@ extension Generator {
createEmbedAppExtensionsBuildPhaseObject
self.createProductBuildFileObject = createProductBuildFileObject
self.createSourcesBuildPhaseObject = createSourcesBuildPhaseObject
self.createLinkBinaryWithLibrariesBuildPhaseObject = createLinkBinaryWithLibrariesBuildPhaseObject
self.createFrameworkObject = createFrameworkObject
self.createFrameworkBuildFileObject = createFrameworkBuildFileObject

self.callable = callable
}
Expand Down Expand Up @@ -86,7 +97,10 @@ extension Generator {
/*createEmbedAppExtensionsBuildPhaseObject:*/
createEmbedAppExtensionsBuildPhaseObject,
/*createProductBuildFileObject:*/ createProductBuildFileObject,
/*createSourcesBuildPhaseObject:*/ createSourcesBuildPhaseObject
/*createSourcesBuildPhaseObject:*/ createSourcesBuildPhaseObject,
/*createLinkBinaryWithLibrariesBuildPhaseObject:*/ createLinkBinaryWithLibrariesBuildPhaseObject,
/*createFrameworkObject:*/ createFrameworkObject,
/*createFrameworkBuildFileObject:*/ createFrameworkBuildFileObject
)
}
}
Expand Down Expand Up @@ -116,7 +130,11 @@ extension Generator.CreateBuildPhases {
_ createEmbedAppExtensionsBuildPhaseObject:
Generator.CreateEmbedAppExtensionsBuildPhaseObject,
_ createProductBuildFileObject: Generator.CreateProductBuildFileObject,
_ createSourcesBuildPhaseObject: Generator.CreateSourcesBuildPhaseObject
_ createSourcesBuildPhaseObject: Generator.CreateSourcesBuildPhaseObject,
_ createLinkBinaryWithLibrariesBuildPhaseObject:
Generator.CreateLinkBinaryWithLibrariesBuildPhaseObject,
_ createFrameworkObject: Generator.CreateFrameworkObject,
_ createFrameworkBuildFileObject: Generator.CreateFrameworkBuildFileObject
) -> (
buildPhases: [Object],
buildFileObjects: [Object],
Expand Down Expand Up @@ -144,7 +162,11 @@ extension Generator.CreateBuildPhases {
createEmbedAppExtensionsBuildPhaseObject:
Generator.CreateEmbedAppExtensionsBuildPhaseObject,
createProductBuildFileObject: Generator.CreateProductBuildFileObject,
createSourcesBuildPhaseObject: Generator.CreateSourcesBuildPhaseObject
createSourcesBuildPhaseObject: Generator.CreateSourcesBuildPhaseObject,
createLinkBinaryWithLibrariesBuildPhaseObject:
Generator.CreateLinkBinaryWithLibrariesBuildPhaseObject,
createFrameworkObject: Generator.CreateFrameworkObject,
createFrameworkBuildFileObject: Generator.CreateFrameworkBuildFileObject
) -> (
buildPhases: [Object],
buildFileObjects: [Object],
Expand Down Expand Up @@ -259,6 +281,45 @@ extension Generator.CreateBuildPhases {
)
}

let librariesToLinkSubIdentifiers = consolidatedInputs.librariesToLinkPaths.map { bazelPath in
return (
bazelPath,
createBuildFileSubIdentifier(
BazelPath(bazelPath.path.split(separator: "/").last.map(String.init)!),
type: .framework,
shard: shard
),
createBuildFileSubIdentifier(
bazelPath,
type: .framework,
shard: shard
)
)
}
librariesToLinkSubIdentifiers
.forEach { bazelPath, buildSubIdentifier, frameworkSubIdentifier in
buildFileObjects.append(
createFrameworkBuildFileObject(
frameworkSubIdentifier: frameworkSubIdentifier,
subIdentifier: buildSubIdentifier
)
)
buildFileObjects.append(
createFrameworkObject(
frameworkPath: bazelPath,
subIdentifier: frameworkSubIdentifier
)
)
}
buildPhases.append(
createLinkBinaryWithLibrariesBuildPhaseObject(
subIdentifier: identifier.subIdentifier,
librariesToLinkIdentifiers: librariesToLinkSubIdentifiers
.map { $0.1 }
.map { Identifiers.BuildFiles.id(subIdentifier: $0) }
)
)

return (buildPhases, buildFileObjects, buildFileSubIdentifiers)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import PBXProj

extension Generator {
struct CreateFrameworkBuildFileObject {
private let callable: Callable

/// - Parameters:
/// - callable: The function that will be called in
/// `callAsFunction()`.
init(callable: @escaping Callable = Self.defaultCallable) {
self.callable = callable
}

/// Creates a `PBXBuildFile` element.
func callAsFunction(
frameworkSubIdentifier: Identifiers.BuildFiles.SubIdentifier,
subIdentifier: Identifiers.BuildFiles.SubIdentifier
) -> Object {
return callable(
/*frameworkSubIdentifier:*/ frameworkSubIdentifier,
/*subIdentifier:*/ subIdentifier
)
}
}
}

// MARK: - CreateFrameworkBuildFileObject.Callable

extension Generator.CreateFrameworkBuildFileObject {
typealias Callable = (
_ frameworkSubIdentifier: Identifiers.BuildFiles.SubIdentifier,
_ subIdentifier: Identifiers.BuildFiles.SubIdentifier
) -> Object

static func defaultCallable(
frameworkSubIdentifier: Identifiers.BuildFiles.SubIdentifier,
subIdentifier: Identifiers.BuildFiles.SubIdentifier
) -> Object {
let fileRef = Identifiers.BuildFiles
.id(subIdentifier: frameworkSubIdentifier)
let content = #"""
{isa = PBXBuildFile; fileRef = \#(fileRef); }
"""#

return Object(
identifier: Identifiers.BuildFiles.id(subIdentifier: subIdentifier),
content: content
)
}
}
Loading