forked from PADL/FlutterSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.swift
399 lines (369 loc) · 12.2 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
// swift-tools-version:5.10
import Foundation
import PackageDescription
func tryGuessSwiftLibRoot() -> String {
let task = Process()
task.executableURL = URL(fileURLWithPath: "/bin/sh")
task.arguments = ["-c", "which swift"]
task.standardOutput = Pipe()
do {
try task.run()
let outputData = (task.standardOutput as! Pipe).fileHandleForReading.readDataToEndOfFile()
let path = URL(fileURLWithPath: String(decoding: outputData, as: UTF8.self))
return path.deletingLastPathComponent().path + "/../lib/swift"
} catch {
return "/usr/lib/swift"
}
}
let SwiftLibRoot = tryGuessSwiftLibRoot()
#if os(macOS) // Note: This is the _build_ platform
let FlutterRoot = "/opt/flutter"
let _FlutterLibPath = "\(FlutterRoot)/bin/cache/artifacts/engine"
let FlutterPlatform = "darwin-x64"
let FlutterFramework = "FlutterMacOS"
let FlutterLibPath = "\(_FlutterLibPath)/\(FlutterPlatform)"
let FlutterUnsafeLinkerFlags = [
"-Xlinker", "-F", "-Xlinker", FlutterLibPath,
"-Xlinker", "-rpath", "-Xlinker", FlutterLibPath,
"-Xlinker", "-framework", "-Xlinker", FlutterFramework,
]
#elseif os(Linux)
// FIXME: this is clearly not right
let FlutterRoot = ".build/artifacts/flutterswift/CFlutterEngine/flutter-engine.artifactbundle"
#if arch(arm64)
let FlutterArch = "arm64"
#elseif arch(x86_64)
let FlutterArch = "x64"
#else
#error("Unknown architecture")
#endif
// FIXME: for release target
let FlutterLibPath = "\(FlutterRoot)/elinux-\(FlutterArch)-debug"
let FlutterAltLibPath = "/opt/flutter-elinux/lib"
let FlutterUnsafeLinkerFlags: [String] = [
"-Xlinker", "-L", "-Xlinker", FlutterLibPath,
"-Xlinker", "-rpath", "-Xlinker", FlutterLibPath,
"-Xlinker", "-L", "-Xlinker", FlutterAltLibPath,
"-Xlinker", "-rpath", "-Xlinker", FlutterAltLibPath,
"-Xlinker", "-l", "-Xlinker", "flutter_engine",
]
#endif
var targets: [Target] = []
var products: [Product] = []
var platformCxxSettings: [CXXSetting] = []
var platformSwiftSettings: [SwiftSetting] = []
#if os(Linux)
enum FlutterELinuxBackendType {
static var defaultBackend: FlutterELinuxBackendType {
if let backend = ProcessInfo.processInfo.environment["FLUTTER_SWIFT_BACKEND"] {
switch backend {
case "gbm": return .drmGbm
case "eglstream": return .drmEglStream
case "wayland": return .wayland
default: break
}
}
return .drmGbm
}
case drmGbm
case drmEglStream
case wayland
var displayBackendType: String {
switch self {
case .drmGbm: return "DRM_GBM"
case .drmEglStream: return "DRM_EGLSTREAM"
case .wayland: return "WAYLAND"
}
}
var flutterTargetBackend: String {
switch self {
case .drmGbm: return "GBM"
case .drmEglStream: return "EGLSTREAM"
case .wayland: return "WAYLAND"
}
}
var targetSpecificDefine: String {
switch self {
case .drmGbm: return "__GBM__"
case .drmEglStream: return "EGL_NO_X11"
case .wayland: return "WL_EGL_PLATFORM"
}
}
}
let FlutterELinuxBackend = FlutterELinuxBackendType.defaultBackend
targets = [
.binaryTarget(
name: "CFlutterEngine",
path: "flutter-engine.artifactbundle.zip"
),
.systemLibrary(
name: "CEGL",
pkgConfig: "egl",
providers: [.apt(["libegl1-mesa-dev", "libgles2-mesa-dev"])]
),
.systemLibrary(
name: "CXKBCommon",
pkgConfig: "xkbcommon",
providers: [.apt(["libxkbcommon-dev"])]
),
]
switch FlutterELinuxBackend {
case .drmGbm:
targets += [
.systemLibrary(
name: "CLibUV",
pkgConfig: "libuv",
providers: [.apt(["libuv1-dev"])]
),
.systemLibrary(
name: "CLibInput",
pkgConfig: "libinput",
providers: [.apt(["libinput-dev"])]
),
.systemLibrary(
name: "CLibDRM",
pkgConfig: "libdrm",
providers: [.apt(["libdrm-dev"])]
),
.systemLibrary(
name: "CLibUDev",
pkgConfig: "libudev",
providers: [.apt(["libudev-dev"])]
),
.systemLibrary(
name: "CGBM",
pkgConfig: "gbm",
providers: [.apt(["libgbm-dev"])]
),
]
case .drmEglStream:
break // TODO:
case .wayland:
targets += [
.systemLibrary(
name: "CWaylandCursor",
pkgConfig: "wayland-cursor",
providers: [.apt(["libwayland-dev", "wayland-protocols"])]
),
.systemLibrary(
name: "CWaylandEGL",
pkgConfig: "wayland-egl",
providers: [.apt(["libwayland-dev", "wayland-protocols"])]
),
]
}
let WaylandSources = [
"elinux_window_wayland.cc",
"native_window_wayland.cc",
"native_window_wayland_decoration.cc",
]
let DRMCommonSources = [
"native_window_drm.cc",
]
let DRMGBMSources = [
"native_window_drm_gbm.cc",
]
let DRMEGLSources = [
"native_window_drm_eglstream.cc",
]
let X11Sources = ["elinux_window_x11.cc", "native_window_x11.cc"]
let ExcludedSources: [String]
let BackendDependencies: [Target.Dependency]
switch FlutterELinuxBackend {
case .drmGbm:
BackendDependencies = ["CLibUV", "CLibInput", "CLibDRM", "CLibUDev", "CGBM"]
ExcludedSources = WaylandSources + DRMEGLSources
case .drmEglStream:
BackendDependencies = [] // TODO:
ExcludedSources = WaylandSources + DRMGBMSources
case .wayland:
BackendDependencies = ["CWaylandCursor", "CWaylandEGL"]
ExcludedSources = DRMCommonSources + DRMGBMSources + DRMEGLSources
}
var Exclusions: [String] = [
"flutter-embedded-linux/cmake",
"flutter-embedded-linux/examples",
"flutter-embedded-linux/src/client_wrapper",
"flutter-embedded-linux/src/flutter/shell/platform/common/client_wrapper/engine_method_result.cc",
]
if FlutterELinuxBackend != .wayland {
Exclusions += ["wayland",
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc",
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.cc",
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc",
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/renderer/elinux_shader.cc",
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/renderer/elinux_shader_context.cc",
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/renderer/elinux_shader_program.cc",
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc",
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.cc",
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc"]
}
if FlutterELinuxBackend != .drmEglStream {
Exclusions +=
[
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc",
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/surface/environment_egl_stream.cc",
]
}
Exclusions += X11Sources
.map { "flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/\($0)" }
Exclusions += ExcludedSources
.map { "flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/window/\($0)" }
targets += [
.target(
name: "CxxFlutterSwift",
dependencies: ["CEGL", "CXKBCommon"] + BackendDependencies,
exclude: Exclusions,
cSettings: [],
cxxSettings: [
.define(FlutterELinuxBackend.targetSpecificDefine),
.define("DISPLAY_BACKEND_TYPE_\(FlutterELinuxBackend.displayBackendType)"),
.define("FLUTTER_TARGET_BACKEND_\(FlutterELinuxBackend.flutterTargetBackend)"),
// USE_DIRTY_REGION_MANAGEMENT OFF
// .define("USE_GLES3"),
.define("ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER"),
// ENABLE_VSYNC OFF
// .define("ENABLE_VSYNC"),
// ENABLE_ELINUX_EMBEDDER_LOG ON
.define("ENABLE_ELINUX_EMBEDDER_LOG"),
// .define("FLUTTER_RELEASE") // FIXME: for release
.define("RAPIDJSON_HAS_STDSTRING"),
.define("RAPIDJSON_HAS_CXX11_RANGE_FOR"),
.define("RAPIDJSON_HAS_CXX11_RVALUE_REFS"),
.define("RAPIDJSON_HAS_CXX11_TYPETRAITS"),
.define("RAPIDJSON_HAS_CXX11_NOEXCEPT"),
.headerSearchPath("."),
.headerSearchPath("flutter-embedded-linux/src"),
.headerSearchPath("flutter-embedded-linux/src/flutter/shell/platform/linux_embedded"),
.headerSearchPath("flutter-embedded-linux/src/flutter/shell/platform/common/public"),
.headerSearchPath(
"flutter-embedded-linux/src/flutter/shell/platform/common/client_wrapper/include"
),
.headerSearchPath(
"flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/public"
),
.headerSearchPath("flutter-embedded-linux/src/third_party/rapidjson/include"),
// FIXME: .cxxLanguageStandard breaks Foundation compile
// FIXME: include path for swift/bridging.h
.unsafeFlags(["-pthread", "-I", SwiftLibRoot, "-I", "/usr/include/drm", "-std=c++17"]),
],
linkerSettings: [
// .unsafeFlags(["-pthread"]),
]
),
.executableTarget(
name: "Counter",
dependencies: [
.target(name: "FlutterSwift"),
"CFlutterEngine",
],
path: "Examples/counter/swift",
cSettings: [
],
cxxSettings: [
],
swiftSettings: [
.interoperabilityMode(.Cxx),
// FIXME: https://github.com/apple/swift-package-manager/issues/6661
.unsafeFlags(["-cxx-interoperability-mode=default"]),
],
linkerSettings: [
// .unsafeFlags(["-pthread"]),
]
),
]
products = [
.executable(name: "Counter", targets: ["Counter"]),
]
platformCxxSettings += [
.define("DISPLAY_BACKEND_TYPE_\(FlutterELinuxBackend.displayBackendType)"),
.define("FLUTTER_TARGET_BACKEND_\(FlutterELinuxBackend.flutterTargetBackend)"),
.headerSearchPath("../CxxFlutterSwift/flutter-embedded-linux/src"),
.headerSearchPath(
"../CxxFlutterSwift/flutter-embedded-linux/src/flutter/shell/platform/linux_embedded"
),
.headerSearchPath(
"../CxxFlutterSwift/flutter-embedded-linux/src/flutter/shell/platform/linux_embedded/public"
),
.headerSearchPath(
"../CxxFlutterSwift/flutter-embedded-linux/src/flutter/shell/platform/common/public"
),
.headerSearchPath(
"../CxxFlutterSwift/flutter-embedded-linux/src/flutter/shell/platform/common/client_wrapper/include"
),
]
platformSwiftSettings += [
.define("DISPLAY_BACKEND_TYPE_\(FlutterELinuxBackend.displayBackendType)"),
.define("FLUTTER_TARGET_BACKEND_\(FlutterELinuxBackend.flutterTargetBackend)"),
]
#else
targets = [
.target(
name: "CxxFlutterSwift",
exclude: [
".",
"wayland",
]
),
]
#endif
let package = Package(
name: "FlutterSwift",
platforms: [
.macOS(.v10_15),
.iOS(.v16),
],
products: [
.library(name: "FlutterSwift", targets: ["FlutterSwift"]),
] + products,
dependencies: [
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-atomics", from: "1.0.0"),
.package(url: "https://github.com/lhoward/AsyncExtensions", branch: "linux"),
],
targets: [
.target(
name: "FlutterSwift",
dependencies: [
.target(name: "CxxFlutterSwift", condition: .when(platforms: [.linux])),
.target(name: "Flutter", condition: .when(platforms: [.iOS])),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "Atomics", package: "swift-atomics"),
"AsyncExtensions",
],
cSettings: [
],
cxxSettings: platformCxxSettings,
swiftSettings: platformSwiftSettings + [
.interoperabilityMode(.Cxx),
],
linkerSettings: [
.unsafeFlags(FlutterUnsafeLinkerFlags, .when(platforms: [.macOS, .linux])),
]
),
.testTarget(
name: "FlutterSwiftTests",
dependencies: [
.target(name: "FlutterSwift"),
],
cSettings: [
],
cxxSettings: [
],
swiftSettings: [
// FIXME: https://github.com/apple/swift-package-manager/issues/6661
.interoperabilityMode(.Cxx),
.unsafeFlags(["-cxx-interoperability-mode=default"]),
],
linkerSettings: [
.unsafeFlags(FlutterUnsafeLinkerFlags, .when(platforms: [.macOS, .linux])),
]
),
.binaryTarget(
name: "Flutter",
path: "Flutter.xcframework.zip"
),
] + targets,
cLanguageStandard: .c17,
cxxLanguageStandard: .cxx17
)