Repository navigation
Expand file tree
/
Copy pathPackage.swift
More file actions
143 lines (120 loc) · 4.2 KB
/
Copy pathPackage.swift
File metadata and controls
143 lines (120 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// swift-tools-version: 5.10
import PackageDescription
import Foundation
let localPath = "XCFrameworks"
let hostingUrl = "https://api.github.com/repos/MyScript/interactive-ink-packages-ios/releases/assets/"
let hostingUrlSuffix = ""
// Map between the available frameworks and their zip package checksum
let frameworks = [
"libiinkC": "fce74dfdb292b03021266262c4187e5246cd9bd7a0ca5610f21b3909595ab61c",
] // end of: frameworks
let frameworksAssetIds = [
"libiinkC": "581082126",
] // end of: asset ids
// Debug logging helper (visible in terminal only)
func printout(_ message: String) {
let logMessage = "[Package.swift][INFO] \(message)\n"
if let data = logMessage.data(using: .utf8) {
FileHandle.standardError.write(data)
}
}
enum BinarySource {
case local, remote
init() {
// check user's home directory (Xcode developers)
if let homeDir = getenv("HOME") {
let homePath = String(cString: homeDir)
let markerPath = "\(homePath)/.iink-use-local-binaries"
if FileManager.default.fileExists(atPath: markerPath) {
printout("Found marker file at \(markerPath)")
self = .local
return
}
}
// Then check package directory (local development)
let configPath = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent()
.appendingPathComponent(".iink-use-local-binaries")
if FileManager.default.fileExists(atPath: configPath.path) {
printout("Found marker file at \(configPath.path)")
self = .local
return
}
// If none found, use remote binaries
self = .remote
}
}
let binarySource = BinarySource()
printout("Binary source mode: \(binarySource)")
func createTarget(framework: String, checksum: String) -> Target {
let fileName = framework == "libiinkC" ? "libiink" : framework
switch binarySource {
case .local:
let path = "\(localPath)/\(fileName).xcframework"
printout("using LOCAL binary: \(path)")
return .binaryTarget(
name: framework,
path: path
)
case .remote:
let assetId = frameworksAssetIds[framework]!
let url = "\(hostingUrl)\(assetId).zip"
printout("For library \(fileName) using REMOTE binary: \(url)")
return .binaryTarget(
name: framework,
url: url,
checksum: checksum
)
}
}
func createTargets() -> [Target] {
var targets: [Target]
// Create binary targets for each framework
targets = frameworks.map { framework, checksum in
createTarget(framework: framework, checksum: checksum)
}
// Create wrapper targets
targets.append(
.target(
name: "libiink",
dependencies: ["libiinkC"],
path: "Sources/libiink",
publicHeadersPath: "include"))
targets.append(
.target(
name: "libiinkSwift",
dependencies: ["libiink"],
path: "Sources/libiinkSwift",
cSettings: [
.headerSearchPath("Sources/libiink/include")
]))
// Create dependencies from framework names
let frameworkDependencies = frameworks.keys.map { Target.Dependency.byName(name: $0) }
// Create dependencies from wrapper targets
let wrapperDependencies: [Target.Dependency] = ["libiink", "libiinkSwift"]
// Create main libiink target depending on all frameworks and wrappers targets
targets.append(
.target(
name: "libiinkTarget",
dependencies: frameworkDependencies + wrapperDependencies,
linkerSettings: [
.linkedFramework("Foundation"),
.linkedFramework("Security"),
.linkedFramework("SystemConfiguration")
]))
return targets
}
let targets = createTargets()
let package = Package(
name: "MyScript iink SDK",
platforms: [
.iOS("15.0"),
.macCatalyst("17.0")
],
products: [
.library(
name: "libiink",
targets: ["libiinkTarget"])
],
targets: targets
)