Skip to content

Commit

Permalink
Only link static libraries to executables
Browse files Browse the repository at this point in the history
  • Loading branch information
brentleyjones committed Jul 23, 2018
1 parent 6cf3359 commit 0afd705
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Docs/ProjectSpec.md
Expand Up @@ -296,7 +296,7 @@ A dependency can be one of a 3 types:
These only applied to `target` and `framework` dependencies.

- [ ] **embed**: **Bool** - Whether to embed the dependency. Defaults to true for application target and false for non application targets.
- [ ] **link**: **Bool** - Whether to link the dependency. Defaults to true but only static library and dynamic frameworks are linked. This only applies for target dependencies.
- [ ] **link**: **Bool** - Whether to link the dependency. Defaults to `true` depending on the type of the dependency and the type of the target (e.g. static libraries will only link to executables by default).
- [ ] **codeSign**: **Bool** - Whether the `codeSignOnCopy` setting is applied when embedding framework. Defaults to true
- [ ] **removeHeaders**: **Bool** - Whether the `removeHeadersOnCopy` setting is applied when embedding the framework. Defaults to true

Expand Down
10 changes: 4 additions & 6 deletions Sources/ProjectSpec/Dependency.swift
Expand Up @@ -9,15 +9,15 @@ public struct Dependency: Equatable {
public var embed: Bool?
public var codeSign: Bool?
public var removeHeaders: Bool = true
public var link: Bool = true
public var link: Bool?
public var implicit: Bool = false

public init(
type: DependencyType,
reference: String,
embed: Bool? = nil,
codeSign: Bool? = nil,
link: Bool = true,
link: Bool? = nil,
implicit: Bool = false
) {
self.type = type
Expand Down Expand Up @@ -53,10 +53,8 @@ extension Dependency: JSONObjectConvertible {

embed = jsonDictionary.json(atKeyPath: "embed")
codeSign = jsonDictionary.json(atKeyPath: "codeSign")

if let bool: Bool = jsonDictionary.json(atKeyPath: "link") {
link = bool
}
link = jsonDictionary.json(atKeyPath: "link")

if let bool: Bool = jsonDictionary.json(atKeyPath: "removeHeaders") {
removeHeaders = bool
}
Expand Down
41 changes: 41 additions & 0 deletions Sources/ProjectSpec/Linkage.swift
@@ -0,0 +1,41 @@
import Foundation

public enum Linkage {
case dynamic
case `static`
case none
}

extension Target {

public var defaultLinkage: Linkage {
switch type {
case .none,
.appExtension,
.application,
.bundle,
.commandLineTool,
.messagesApplication,
.messagesExtension,
.ocUnitTestBundle,
.stickerPack,
.tvExtension,
.uiTestBundle,
.unitTestBundle,
.watchApp,
.watchExtension,
.watch2App,
.watch2Extension,
.xcodeExtension,
.xpcService:
return .none
case .framework:
// TODO: This should check `MACH_O_TYPE` in case this is a "Static Framework"
return .dynamic
case .dynamicLibrary:
return .dynamic
case .staticLibrary:
return .static
}
}
}
5 changes: 4 additions & 1 deletion Sources/XcodeGenKit/PBXProjGenerator.swift
Expand Up @@ -435,7 +435,10 @@ public class PBXProjGenerator {

dependencies.append(targetDependency.reference)

if (dependencyTarget.type.isLibrary || dependencyTarget.type.isFramework) && dependency.link {
let dependecyLinkage = dependencyTarget.defaultLinkage
let shouldLink = dependecyLinkage == .dynamic
|| (dependecyLinkage == .static && target.type.isExecutable)
if dependency.link ?? shouldLink {
let dependencyBuildFile = targetBuildFiles[dependencyTargetName]!
let buildFile = createObject(
id: dependencyBuildFile.reference + target.name,
Expand Down

0 comments on commit 0afd705

Please sign in to comment.