Skip to content

Commit

Permalink
Get dynamic linking working
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 committed May 2, 2024
1 parent b4ff392 commit 292f4f0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 44 deletions.
46 changes: 4 additions & 42 deletions ReleaseTooling/Sources/ZipBuilder/FrameworkBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,14 @@ struct FrameworkBuilder {
logsDir: URL) -> [URL] {
// xcframework doesn't lipo things together but accepts fat frameworks for one target.
// We group architectures here to deal with this fact.
var thinFrameworks = [URL]()
for targetPlatform in TargetPlatform.allCases {
let buildDir = projectDir.appendingPathComponent(targetPlatform.buildName)
let slicedFramework = buildSlicedFramework(
withName: FrameworkBuilder.frameworkBuildName(framework),
return targetPlatforms.map { targetPlatform in
buildSlicedFramework(
withName: framework,
targetPlatform: targetPlatform,
buildDir: buildDir,
buildDir: projectDir.appendingPathComponent(targetPlatform.buildName),
logRoot: logsDir
)
thinFrameworks.append(slicedFramework)
}
return thinFrameworks
}

/// Compiles the specified framework in a temporary directory and writes the build logs to file.
Expand Down Expand Up @@ -565,17 +561,6 @@ struct FrameworkBuilder {
"\(framework): \(error)")
}

// CocoaPods creates a `_CodeSignature` directory. Delete it.
// Note that the build only produces a `_CodeSignature` directory for
// macOS and macCatalyst, but we try to delete it for other platforms
// just in case it were to appear.
let codeSignatureDir = platformFrameworkDir
.appendingPathComponent(
platform == .catalyst || platform == .macOS ? "Versions/A/" : ""
)
.appendingPathComponent("_CodeSignature")
try? fileManager.removeItem(at: codeSignatureDir)

// The minimum OS version is set to 100.0 to work around b/327020913.
// TODO(ncooke3): Revert this logic once b/327020913 is fixed.
// TODO(ncooke3): Does this need to happen on macOS?
Expand Down Expand Up @@ -604,23 +589,6 @@ struct FrameworkBuilder {
)
}

// The macOS slice's `PrivateHeaders` directory may have a
// `PrivateHeaders` file in it that symbolically links to nowhere. Delete
// it here to avoid putting it in the zip or crashing the Carthage hash
// generation. Because this will throw an error for cases where the file
// does not exist, the error is ignored.
let privateHeadersDir = platformFrameworkDir.appendingPathComponent("PrivateHeaders")
if fileManager.directoryExists(at: privateHeadersDir.resolvingSymlinksInPath()) {
try? fileManager
.removeItem(at: privateHeadersDir.resolvingSymlinksInPath()
.appendingPathComponent("PrivateHeaders"))
} else {
try? fileManager.removeItem(at: privateHeadersDir)
}
let headersDir = platformFrameworkDir.appendingPathComponent("Headers")
.resolvingSymlinksInPath()
try? fileManager.removeItem(at: headersDir.appendingPathComponent("Headers"))

// Move privacy manifest containing resource bundles into the framework.
let resourceDir = platformFrameworkDir
.appendingPathComponent(
Expand All @@ -638,12 +606,6 @@ struct FrameworkBuilder {
// Bundles are moved rather than copied to prevent them from being
// packaged in a `Resources` directory at the root of the xcframework.
.forEach {
// Delete `gRPCCertificates-Cpp.bundle` since it is not needed (#9184).
guard $0.lastPathComponent != "gRPCCertificates-Cpp.bundle" else {
try fileManager.removeItem(at: $0)
return
}

try fileManager.moveItem(
at: $0,
to: resourceDir.appendingPathComponent($0.lastPathComponent)
Expand Down
52 changes: 50 additions & 2 deletions ReleaseTooling/Sources/ZipBuilder/ZipBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ struct ZipBuilder {
for groupedFramework in groupedFrameworks {
let name = groupedFramework.key
let xcframework = FrameworkBuilder.makeXCFramework(withName: name,
frameworks: groupedFramework.value,
frameworks: postProcessFrameworks(groupedFramework
.value),
xcframeworksDir: xcframeworksDir,
resourceContents: resources[name])
xcframeworks[name] = [xcframework]
Expand All @@ -299,13 +300,60 @@ struct ZipBuilder {

let carthageGoogleUtilitiesXcframework = FrameworkBuilder.makeXCFramework(
withName: "GoogleUtilities",
frameworks: carthageGoogleUtilitiesFrameworks,
frameworks: postProcessFrameworks(carthageGoogleUtilitiesFrameworks),
xcframeworksDir: xcframeworksCarthageDir,
resourceContents: nil
)
return (podsBuilt, xcframeworks, carthageGoogleUtilitiesXcframework)
}

func postProcessFrameworks(_ frameworks: [URL]) -> [URL] {
for framework in frameworks {
// CocoaPods creates a `_CodeSignature` directory. Delete it.
// Note that the build only produces a `_CodeSignature` directory for
// macOS and macCatalyst (`Versions/A/`), but we try to delete it for
// other platforms just in case it were to appear.
for path in ["", "Versions/A/"] {
let codeSignatureDir = framework
.appendingPathComponent(path)
.appendingPathComponent("_CodeSignature")
.resolvingSymlinksInPath()
try? FileManager.default.removeItem(at: codeSignatureDir)
}

// Delete `gRPCCertificates-Cpp.bundle` since it is not needed (#9184).
// Depending on the platform, it may be at the root of the framework or
// in a symlinked `Resources` directory (for macOS, macCatalyst). Attempt
// to delete at either patch for each framework.
for path in ["", "Resources"] {
let grpcCertsBundle = framework
.appendingPathComponent(path)
.appendingPathComponent("gRPCCertificates-Cpp.bundle")
.resolvingSymlinksInPath()
try? FileManager.default.removeItem(at: grpcCertsBundle)
}

// The macOS slice's `PrivateHeaders` directory may have a
// `PrivateHeaders` file in it that symbolically links to nowhere. Delete
// it here to avoid putting it in the zip or crashing the Carthage hash
// generation. Because this will throw an error for cases where the file
// does not exist, the error is ignored.
let privateHeadersDir = framework.appendingPathComponent("PrivateHeaders")
if !FileManager.default.directoryExists(at: privateHeadersDir.resolvingSymlinksInPath()) {
try? FileManager.default.removeItem(at: privateHeadersDir)
}

// The `Headers` and `PrivateHeaders` directories may contain a symlink
// of the same name. Delete it here to avoid putting it in the zip or
// crashing the Carthage hash generation.
for path in ["Headers", "PrivateHeaders"] {
let headersDir = framework.appendingPathComponent(path).resolvingSymlinksInPath()
try? FileManager.default.removeItem(at: headersDir.appendingPathComponent(path))
}
}
return frameworks
}

/// Try to build and package the contents of the Zip file. This will throw an error as soon as it
/// encounters an error, or will quit due to a fatal error with the appropriate log.
///
Expand Down

0 comments on commit 292f4f0

Please sign in to comment.