-
Notifications
You must be signed in to change notification settings - Fork 822
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
Support Static Frameworks for Carthage dependencies #688
Conversation
configFrameworkBuildPaths = [carthagePlatformBuildPath] + frameworkBuildPaths.sorted() | ||
var carthagePlatformBuildPaths: [String] = [] | ||
if carthageDependencies.contains(where: { isStaticDependency(for: $0) }) { | ||
let carthagePlatformBuildPath = "$(PROJECT_DIR)/" + carthageResolver.buildPath(for: target.platform, isStatic: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If targets have any static frameworks, the static framework search path will be added before dynamic one.
} | ||
try expect(file.file?.nameOrPath) == "MyStaticFramework.framework" | ||
|
||
try expect(target.carthageCopyFrameworkBuildPhase()).beNil() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a target contains only static dependencies, then Carthage
build phase should not be added.
guard let copyCarthagePhase = target.carthageCopyFrameworkBuildPhase() else { | ||
return XCTFail("Carthage Build Phase should be exist") | ||
} | ||
try expect(copyCarthagePhase.inputPaths) == [dynamicFramework.file?.fullPath(sourceRoot: Path("$(SRCROOT)"))?.string] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static Framework should not be copied.
@brentleyjones were you looking at this work earlier? |
@yonaskolb I was, but have since long abandoned that branch, and currently don't have strong opinions about static linking. I'll give this a once over though. |
@@ -459,6 +459,15 @@ public class PBXProjGenerator { | |||
} | |||
return !linkingAttributes.isEmpty ? ["ATTRIBUTES": linkingAttributes] : nil | |||
} | |||
|
|||
func isStaticDependency(for carthageDependency: Dependency) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this instead be an extension on Dependency
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a local function inside generateTarget
function. So it has a narrower scope than fileprivate extension
. This is why I use function instead of extension.
@brentleyjones Thanks for your review! I addressed your points. Could you review this again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Thanks @giginet!
@yonaskolb We need your eyes before merging. Could you check this in your spare time? |
Sources/ProjectSpec/Dependency.swift
Outdated
@@ -36,7 +36,7 @@ public struct Dependency: Equatable { | |||
public enum DependencyType: Equatable { | |||
case target | |||
case framework | |||
case carthage(findFrameworks: Bool?) | |||
case carthage(findFrameworks: Bool?, static: Bool) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- How do you feel about making this a
linkType: LinkType
enum withstatic
anddynamic
cases? I don't feel too strongly either way. I think we @brentleyjones was building this he mentioned a similar approach. - Are there other dependency types that we might want use this on? If so we could move this property into the Dependency itself, as opposed to the enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
I feel good linkType
than the current implementation 👍
2
Are there other dependency types that we might want use this on?
No. I think it's easier to read Dependency
has linkType property than using associated value.
But using associated value is more right to express structures.
That's difficult choices...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can rebase off master to fix CI
@@ -463,6 +463,15 @@ public class PBXProjGenerator { | |||
} | |||
return !linkingAttributes.isEmpty ? ["ATTRIBUTES": linkingAttributes] : nil | |||
} | |||
|
|||
func isStaticDependency(for carthageDependency: Dependency) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree about moving this to an extension. If we move static/linkType to Dependency itself like in the other comment we don't even need this function.
Otherwise if this crashes when used with other types it should be called carthageDependencyIsStatic
, otherwise it should probably just return false for other cases
@yonaskolb @brentleyjones I modified spec interface from your comments. Could you review again? |
Sources/ProjectSpec/Dependency.swift
Outdated
|
||
public enum DependencyType: Equatable { | ||
case target | ||
case framework | ||
case carthage(findFrameworks: Bool?) | ||
case carthage(findFrameworks: Bool?, linkType: CarthageLinkType = .default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we are dropping lower Swift compiler versions here yet, so we shouldn't use a default associated value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted. 14a249d
This reverts commit 7590523.
Motivation and Context
Carthage officially supports Static Frameworks.
https://github.com/Carthage/Carthage#build-static-frameworks-to-speed-up-your-apps-launch-times
These frameworks are built to different directory with dynamic ones. So we can't integrate static frameworks automatically by
carthage
dependency.Description
This PR makes it enable to integrate Carthage static framework easily.
With enabling this option, XcodeGen behaves like following:
Carthage/Build/${Platform}/Static/${FrameworkName}.framework
copy-framework
build phase