Skip to content
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

Merged
merged 24 commits into from
Nov 7, 2019

Conversation

giginet
Copy link
Collaborator

@giginet giginet commented Oct 20, 2019

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.

targets:
  MyTarget:
    dependencies:
      - carthage: AStaticFramework
        linkType: static

Screen Shot 2019-10-20 at 15 02 10

With enabling this option, XcodeGen behaves like following:

  • Finding search path should beCarthage/Build/${Platform}/Static/${FrameworkName}.framework
  • Static frameworks aren't added to the copy-framework build phase

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)
Copy link
Collaborator Author

@giginet giginet Oct 20, 2019

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()
Copy link
Collaborator Author

@giginet giginet Oct 20, 2019

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]
Copy link
Collaborator Author

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.

@yonaskolb
Copy link
Owner

@brentleyjones were you looking at this work earlier?

@brentleyjones
Copy link
Collaborator

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.

Docs/ProjectSpec.md Outdated Show resolved Hide resolved
@@ -459,6 +459,15 @@ public class PBXProjGenerator {
}
return !linkingAttributes.isEmpty ? ["ATTRIBUTES": linkingAttributes] : nil
}

func isStaticDependency(for carthageDependency: Dependency) -> Bool {
Copy link
Collaborator

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?

Copy link
Collaborator Author

@giginet giginet Oct 28, 2019

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.

Sources/XcodeGenKit/PBXProjGenerator.swift Outdated Show resolved Hide resolved
Sources/ProjectSpec/Dependency.swift Outdated Show resolved Hide resolved
@giginet
Copy link
Collaborator Author

giginet commented Oct 29, 2019

@brentleyjones Thanks for your review!

I addressed your points. Could you review this again?

Copy link
Collaborator

@brentleyjones brentleyjones left a 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!

@giginet
Copy link
Collaborator Author

giginet commented Oct 29, 2019

@yonaskolb We need your eyes before merging. Could you check this in your spare time?

@@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. How do you feel about making this a linkType: LinkType enum with static and dynamic cases? I don't feel too strongly either way. I think we @brentleyjones was building this he mentioned a similar approach.
  2. 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

Copy link
Collaborator Author

@giginet giginet Nov 7, 2019

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...

Copy link
Owner

@yonaskolb yonaskolb left a 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 {
Copy link
Owner

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

@giginet
Copy link
Collaborator Author

giginet commented Nov 7, 2019

@yonaskolb @brentleyjones I modified spec interface from your comments. Could you review again?
705e351


public enum DependencyType: Equatable {
case target
case framework
case carthage(findFrameworks: Bool?)
case carthage(findFrameworks: Bool?, linkType: CarthageLinkType = .default)
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted. 14a249d

@brentleyjones brentleyjones merged commit 03076f4 into yonaskolb:master Nov 7, 2019
@giginet giginet deleted the static branch November 7, 2019 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants