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

Add requiresObjCLinking to Target #353

Merged
merged 2 commits into from
Jul 24, 2018
Merged

Add requiresObjCLinking to Target #353

merged 2 commits into from
Jul 24, 2018

Conversation

brentleyjones
Copy link
Collaborator

Child of #350. Addresses 2.ii.

if let string = buildSettings[otherLinkingFlags] as? String {
buildSettings["OTHER_LDFLAGS"] = "\(string) -ObjC"
} else {
buildSettings["OTHER_LDFLAGS"] = "$(inherited) -ObjC"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the new code in here. Lots of red and green since this section had to be moved below targetDependencies generation

@yonaskolb
Copy link
Owner

I'm not convinced all this complexity and performance hit is worth it. Is there a big downside to either just adding OTHER_LDFLAGS: "$(inherited) -ObjC" to every target by default, or at least to targets that have library.static target dependencies?

@@ -159,6 +162,63 @@ extension Target {
merged["targets"] = crossPlatformTargets
return merged
}

public var shouldEmbedDependencies: Bool {
return type.isApp || type.isTest
Copy link
Owner

Choose a reason for hiding this comment

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

This could be an extension on PBXProjectType like the getters it's using

}
}

private func getAllDependenciesPlusTransitiveNeedingEmbedding(project: Project) -> [Dependency] {
Copy link
Owner

Choose a reason for hiding this comment

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

I'd rather keep all this code out of the ProjectSpec module. Some people use ProjectSpec as a seperate library without XcodeGen's logic.
But mostly this also removes the ability to add caching across the project as there is no controller for this logic

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed that commit altogether, it's back in XcodeGenKit.

}

// objc linkage
let anyDependencyRequiresObjCLinking = targetDependencies.contains { dependency in
Copy link
Owner

Choose a reason for hiding this comment

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

This could be quite performance intensive

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All searching of sources was removed, and it now just sets a flag once as soon as anyDependencyRequiresObjCLinking would be true. Performance shouldn't be an issue anymore.

}
if anyDependencyRequiresObjCLinking {
let otherLinkingFlags = "OTHER_LDFLAGS"
if let string = buildSettings[otherLinkingFlags] as? String {
Copy link
Owner

Choose a reason for hiding this comment

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

The setting may also be a [String]. Perhaps a convenience somewhere that appends an item to a list style setting using $(inherited) would be good

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it to follow the pattern. I didn't add a convenience though.


func dependencySourceFiles() -> [SourceFile] {
// This is duplicative and should be cached
return (try? sourceGenerator.getAllSourceFiles(sources: dependencyTarget.sources)) ?? []
Copy link
Owner

Choose a reason for hiding this comment

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

This would generate duplicates wouldn't it?

- [ ] **dependencies**: **[[Dependency](#dependency)]** - Dependencies for the target
- [ ] **transitivelyLinkDependencies**: **Bool** - If this is not specified the value from the project set in [Options](#options)`.transitivelyLinkDependencies` will be used.
- [ ] **requiresObjCLinking**: **Bool** - If this is `true` any targets that link to this target will have `-ObjC` added to their `OTHER_LDFLAGS`. Defaults to `true` if `type` is `library.static` and [Sources](#sources) contain any `.swift`, `.m`, or `.mm` files.
Copy link
Owner

Choose a reason for hiding this comment

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

People would really have to have a deep understanding of what this means

@brentleyjones
Copy link
Collaborator Author

brentleyjones commented Jul 22, 2018

Great feedback. I’ll adjust it to not look at the sources and just default the value to true for static libraries. I’ll clean up the documentation so it’s bettter understandable by the average person (and why you would want to adjust the default). I’ll also move this back into their proper places. Finally I’ll make sure the changes are more performant in general.

I want to keep the property though, since I see it being added to the carthage and framework dependency types for static frameworks.

Ohh, and to answer your question about just putting this on targets: there is a very real binary size hit you take if you use this option without he need for it. I’ll make sure the documentation reflects this.

@brentleyjones
Copy link
Collaborator Author

@yonaskolb Addressed your feedback. Per the other PR's comments, I'll add new commits instead of amending next time.

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.

Approved. Feel free to merge when conflicts are resolved

Allows config to reference targer dependencies.
Allows a Target to indicate that any target that links to it needs to set `-ObjC` in `OTHER_LDFLAGS`.
@brentleyjones brentleyjones merged commit 6041e73 into master Jul 24, 2018
@yonaskolb yonaskolb deleted the objcLinking branch July 24, 2018 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants