-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathPackage.swift
259 lines (246 loc) · 8.66 KB
/
Package.swift
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// swift-tools-version:5.9
import CompilerPluginSupport
import Foundation
import PackageDescription
// In Gtk 4.10 some breaking changes were made, so the GtkBackend code needs to know
// which version is in use.
var gtkSwiftSettings: [SwiftSetting] = []
if let version = getGtk4MinorVersion(), version >= 10 {
gtkSwiftSettings.append(.define("GTK_4_10_PLUS"))
}
var swift510Dependencies: [Package.Dependency] = []
var swift510Targets: [Target] = []
var swift510Products: [Product] = []
#if swift(>=5.10)
swift510Dependencies = [
.package(
url: "https://github.com/thebrowsercompany/swift-windowsappsdk",
branch: "main"
),
.package(
url: "https://github.com/thebrowsercompany/swift-windowsfoundation",
branch: "main"
),
.package(
url: "https://github.com/thebrowsercompany/swift-winui",
branch: "main"
),
]
swift510Products = [
.library(name: "WinUIBackend", targets: ["WinUIBackend"])
]
swift510Targets = [
.target(
name: "WinUIBackend",
dependencies: [
"SwiftCrossUI",
.product(name: "WinUI", package: "swift-winui"),
.product(name: "WinAppSDK", package: "swift-windowsappsdk"),
.product(name: "WindowsFoundation", package: "swift-windowsfoundation"),
]
)
]
#endif
let defaultBackend: String
if let backend = ProcessInfo.processInfo.environment["SCUI_DEFAULT_BACKEND"] {
defaultBackend = backend
} else {
#if os(macOS)
defaultBackend = "AppKitBackend"
#elseif os(Windows)
defaultBackend = "WinUIBackend"
#else
defaultBackend = "GtkBackend"
#endif
}
let hotReloadingEnabled: Bool
#if os(Windows)
hotReloadingEnabled = false
#else
hotReloadingEnabled =
ProcessInfo.processInfo.environment["SWIFT_BUNDLER_HOT_RELOADING"] != nil
|| ProcessInfo.processInfo.environment["SCUI_HOT_RELOADING"] != nil
#endif
var swiftSettings: [SwiftSetting] = []
if hotReloadingEnabled {
swiftSettings += [
.define("HOT_RELOADING_ENABLED")
]
}
var libraryType: Product.Library.LibraryType?
switch ProcessInfo.processInfo.environment["SCUI_LIBRARY_TYPE"] {
case "static":
libraryType = .static
case "dynamic":
libraryType = .dynamic
case "auto":
libraryType = nil
case .some:
print("Invalid SCUI_LIBRARY_TYPE, expected static, dynamic, or auto")
libraryType = nil
case nil:
if hotReloadingEnabled {
libraryType = .dynamic
} else {
libraryType = nil
}
}
let package = Package(
name: "swift-cross-ui",
platforms: [.macOS(.v10_15)],
products: [
.library(name: "SwiftCrossUI", type: libraryType, targets: ["SwiftCrossUI"]),
.library(name: "AppKitBackend", type: libraryType, targets: ["AppKitBackend"]),
.library(name: "CursesBackend", type: libraryType, targets: ["CursesBackend"]),
.library(name: "QtBackend", type: libraryType, targets: ["QtBackend"]),
.library(name: "GtkBackend", type: libraryType, targets: ["GtkBackend"]),
.library(name: "DefaultBackend", type: libraryType, targets: ["DefaultBackend"]),
.library(name: "Gtk", type: libraryType, targets: ["Gtk"]),
.executable(name: "GtkExample", targets: ["GtkExample"]),
// .library(name: "LVGLBackend", type: libraryType, targets: ["LVGLBackend"]),
] + swift510Products,
dependencies: [
.package(
url: "https://github.com/CoreOffice/XMLCoder",
from: "0.17.1"
),
.package(
url: "https://github.com/stackotter/TermKit",
revision: "163afa64f1257a0c026cc83ed8bc47a5f8fc9704"
),
// .package(
// url: "https://github.com/PADL/LVGLSwift",
// revision: "19c19a942153b50d61486faf1d0d45daf79e7be5"
// ),
.package(
url: "https://github.com/Longhanks/qlift",
revision: "ddab1f1ecc113ad4f8e05d2999c2734cdf706210"
),
.package(
url: "https://github.com/apple/swift-docc-plugin",
from: "1.0.0"
),
.package(
url: "https://github.com/apple/swift-syntax.git",
from: "510.0.0"
),
.package(
url: "https://github.com/stackotter/swift-macro-toolkit",
from: "0.4.0"
),
] + swift510Dependencies,
targets: [
.target(
name: "SwiftCrossUI",
dependencies: [
"HotReloadingMacrosPlugin"
],
exclude: [
"Builders/ViewBuilder.swift.gyb",
"ViewGraph/ViewGraphNodeChildren.swift.gyb",
"Views/VariadicView.swift.gyb",
]
),
.testTarget(
name: "SwiftCrossUITests",
dependencies: ["SwiftCrossUI"]
),
.target(
name: "DefaultBackend",
dependencies: [
.target(name: defaultBackend)
]
),
.target(name: "AppKitBackend", dependencies: ["SwiftCrossUI"]),
.target(
name: "QtBackend",
dependencies: ["SwiftCrossUI", .product(name: "Qlift", package: "qlift")]
),
.target(
name: "CursesBackend",
dependencies: ["SwiftCrossUI", "TermKit"]
),
// .target(
// name: "LVGLBackend",
// dependencies: [
// "SwiftCrossUI",
// .product(name: "LVGL", package: "LVGLSwift"),
// .product(name: "CLVGL", package: "LVGLSwift"),
// ]
// ),
.target(
name: "GtkBackend",
dependencies: ["SwiftCrossUI", "Gtk", "CGtk"]
),
.systemLibrary(
name: "CGtk",
pkgConfig: "gtk4",
providers: [
.brew(["gtk4"]),
.apt(["libgtk-4-dev clang"]),
]
),
.target(name: "Gtk", dependencies: ["CGtk"], swiftSettings: gtkSwiftSettings),
.executableTarget(
name: "GtkExample",
dependencies: ["Gtk"],
resources: [.copy("GTK.png")]
),
.executableTarget(
name: "GtkCodeGen",
dependencies: [
"XMLCoder", .product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
]
),
.macro(
name: "HotReloadingMacrosPlugin",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "MacroToolkit", package: "swift-macro-toolkit"),
],
swiftSettings: swiftSettings
),
] + swift510Targets
)
func getGtk4MinorVersion() -> Int? {
#if os(Windows)
guard let pkgConfigPath = ProcessInfo.processInfo.environment["PKG_CONFIG_PATH"],
case let tripletRoot = URL(fileURLWithPath: pkgConfigPath, isDirectory: true)
.deletingLastPathComponent().deletingLastPathComponent(),
case let vcpkgInfoDirectory = tripletRoot.deletingLastPathComponent()
.appendingPathComponent("vcpkg").appendingPathComponent("info"),
let installedList = try? FileManager.default.contentsOfDirectory(
at: vcpkgInfoDirectory, includingPropertiesForKeys: nil
)
.map({ $0.deletingPathExtension().lastPathComponent }),
let packageName = installedList.first(where: {
$0.hasPrefix("gtk_") && $0.hasSuffix("_\(tripletRoot.lastPathComponent)")
})
else {
print("We only support installing gtk through vcpkg on Windows.")
return nil
}
let version = packageName.split(separator: "_")[1].split(separator: ".")
#else
let process = Process()
process.executableURL = URL(fileURLWithPath: "/bin/bash")
process.arguments = ["-c", "gtk4-launch --version"]
let pipe = Pipe()
process.standardOutput = pipe
guard let _ = try? process.run(),
let data = try? pipe.fileHandleForReading.readToEnd(),
case _ = process.waitUntilExit(),
let version = String(data: data, encoding: .utf8)?.split(separator: ".")
else {
print("Failed to get gtk version")
return nil
}
#endif
guard version.count >= 2, let minor = Int(version[1]) else {
print("Failed to get gtk version")
return nil
}
return minor
}