-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackage.swift
More file actions
158 lines (148 loc) · 5.67 KB
/
Copy pathPackage.swift
File metadata and controls
158 lines (148 loc) · 5.67 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// swift-tools-version: 6.3
import Foundation
import CompilerPluginSupport
import PackageDescription
// MARK: - Binary Targets
/// XCFrameworks compiled from OpenSwiftUI 0.21.0.
let openSwiftUIVersion = "0.21.0"
let openSwiftUIReleaseBaseURL = "https://github.com/OpenSwiftUIProject/OpenSwiftUI/releases/download/\(openSwiftUIVersion)"
let packageDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
let localXCFrameworksDirectory = Context.environment["OPENSWIFTUI_LOCAL_XCFRAMEWORKS_PATH"].flatMap { path in
path.isEmpty ? nil : URL(fileURLWithPath: path, relativeTo: packageDirectory).standardizedFileURL
}
func relativePath(from directory: URL, to file: URL) -> String {
let directoryComponents = directory.standardizedFileURL.pathComponents
let fileComponents = file.standardizedFileURL.pathComponents
var commonComponentCount = 0
while commonComponentCount < directoryComponents.count &&
commonComponentCount < fileComponents.count &&
directoryComponents[commonComponentCount] == fileComponents[commonComponentCount] {
commonComponentCount += 1
}
let parentComponents = Array(repeating: "..", count: directoryComponents.count - commonComponentCount)
return (parentComponents + fileComponents.dropFirst(commonComponentCount)).joined(separator: "/")
}
func openSwiftUIBinaryTarget(name: String, checksum: String) -> Target {
if let localXCFrameworksDirectory {
let localXCFramework = localXCFrameworksDirectory.appendingPathComponent("\(name).xcframework")
if FileManager.default.fileExists(atPath: localXCFramework.path) {
return .binaryTarget(
name: name,
path: relativePath(from: packageDirectory, to: localXCFramework)
)
}
}
return .binaryTarget(
name: name,
url: "\(openSwiftUIReleaseBaseURL)/\(name).xcframework.zip",
checksum: checksum
)
}
let openSwiftUI = openSwiftUIBinaryTarget(
name: "OpenSwiftUI",
checksum: "e2235473e24af0fac6b74e13b26d1151aad286150dbe317350640cee03ca14df"
)
let openSwiftUICore = openSwiftUIBinaryTarget(
name: "OpenSwiftUICore",
checksum: "8d9e83e306955b5dad63f2beeeca616cf1b06fee2c84aef9c6fa06336593dfd7"
)
let openAttributeGraphShims = openSwiftUIBinaryTarget(
name: "OpenAttributeGraphShims",
checksum: "88496f77d77393f8b650b5142c6138b1ee1d2df2f3453a7e8538cb992559fcfd"
)
let openCoreGraphicsShims = openSwiftUIBinaryTarget(
name: "OpenCoreGraphicsShims",
checksum: "8794c4b1375350e19fb06170b35367a02924e476ef8cf2db2cd5165933a70099"
)
let openObservation = openSwiftUIBinaryTarget(
name: "OpenObservation",
checksum: "27d9eed2c53a4c3d26cb784d0334cd11ed60f4cd7f5e096d6648d9aed2da4ede"
)
let openQuartzCoreShims = openSwiftUIBinaryTarget(
name: "OpenQuartzCoreShims",
checksum: "9cc113fed375e46a7730471c991c0b1107ad140e71126825348956dc9d2410f1"
)
let openRenderBoxShims = openSwiftUIBinaryTarget(
name: "OpenRenderBoxShims",
checksum: "a5b76db139e42192a92233523356d508c1748af1f194c66c5e0adc668569e4a4"
)
// MARK: - Host Macro Target
// Mirrored from the matching OpenSwiftUI release by its release workflow.
let openSwiftUIMacros = Target.macro(
name: "OpenSwiftUIMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
],
swiftSettings: [
.enableUpcomingFeature("InternalImportsByDefault"),
]
)
// MARK: - Package
let package = Package(
name: "OpenSwiftUI",
/*
* If we add this correct information, many SUI package can't add this to their Package.swift to adapt for OSUI
* as we can't conditional change platforms for trait. So keep leave this for now.
* And the final MachO target must match the OS version to successfully link the framework.
*/
// platforms: [.iOS(.v18), .macOS(.v15)],
platforms: [.iOS(.v15), .macOS(.v12)],
products: [
.library(
name: "OpenSwiftUI",
targets: [
"OpenSwiftUI",
"OpenSwiftUICore",
"OpenCoreGraphicsShims",
"OpenObservation",
"OpenQuartzCoreShims",
"OpenRenderBoxShims",
"OpenSwiftUIMacros",
]
),
.library(name: "OpenSwiftUIPlayground", targets: ["OpenSwiftUIPlayground"]),
.library(name: "SwiftUIPlayground", targets: ["SwiftUIPlayground"]),
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "603.0.0"),
],
targets: [
openSwiftUI,
openSwiftUICore,
openAttributeGraphShims,
openCoreGraphicsShims,
openObservation,
openQuartzCoreShims,
openRenderBoxShims,
openSwiftUIMacros,
.target(
name: "OpenSwiftUIPlayground",
dependencies: [
"OpenSwiftUI",
"OpenSwiftUICore",
"OpenAttributeGraphShims",
"OpenCoreGraphicsShims",
"OpenObservation",
"OpenQuartzCoreShims",
"OpenRenderBoxShims",
"OpenSwiftUIMacros",
],
),
.target(name: "SwiftUIPlayground"),
.testTarget(
name: "OpenSwiftUITests",
dependencies: [
"OpenSwiftUI",
"OpenSwiftUICore",
"OpenAttributeGraphShims",
"OpenCoreGraphicsShims",
"OpenObservation",
"OpenQuartzCoreShims",
"OpenRenderBoxShims",
"OpenSwiftUIMacros",
],
path: "Tests"
),
]
)