-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathPackage.swift
More file actions
308 lines (293 loc) · 10.8 KB
/
Copy pathPackage.swift
File metadata and controls
308 lines (293 loc) · 10.8 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
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
// swift-tools-version: 6.1
let lumaFridaDevkitLinkerSettings: [LinkerSetting] = {
guard let devkit = ProcessInfo.processInfo.environment["LUMA_FRIDA_DEVKIT"], !devkit.isEmpty else { return [] }
var flags = ["-L\(devkit)/lib", "-lfrida-core", "-lc++", "-lresolv", "-liconv", "-lbsm", "-lm"]
for framework in ["Foundation", "CoreFoundation", "AppKit", "CoreServices", "IOKit", "Security", "Network", "SystemConfiguration"] {
flags += ["-framework", framework]
}
return [.unsafeFlags(flags)]
}()
import Foundation
import PackageDescription
#if canImport(Darwin)
let manifestArgs = CommandLine.arguments
let manifestFileno = manifestArgs.firstIndex(of: "-fileno").flatMap { index -> String? in
let valueIndex = manifestArgs.index(after: index)
guard valueIndex < manifestArgs.endIndex else { return nil }
return manifestArgs[valueIndex]
}
let usesXcodePackageResolution = manifestFileno != nil && manifestFileno != "4"
#else
let usesXcodePackageResolution = false
#endif
let lumaCoreExcludes = ["VirtualMachines/AndroidEmulator/EmulatorControl/proto"] + (usesXcodePackageResolution ? [] : ["Generated"])
let lumaCorePlugins: [Target.PluginUsage] = usesXcodePackageResolution ? [] : [
.plugin(name: "LumaBundlePlugin"),
.plugin(name: "LumaShaderPlugin"),
]
let lumaBundlePluginTargets: [Target] = usesXcodePackageResolution ? [] : [
.plugin(
name: "LumaBundlePlugin",
capability: .buildTool(),
dependencies: [
.target(name: "LumaBundleCompiler"),
],
path: "Plugins/LumaBundlePlugin"
),
.plugin(
name: "LumaShaderPlugin",
capability: .buildTool(),
dependencies: [
.target(name: "LumaShaderCompiler"),
],
path: "Plugins/LumaShaderPlugin"
),
]
#if canImport(Darwin)
// Apple's mobile SDKs reach the audio session through AVFoundation, so the
// device unit has to be Objective-C there. Desktop follows suit rather than
// carry two behaviours.
let cLumaAudioSources = ["luma_audio_device.m"]
let cLumaAudioLinkerSettings: [LinkerSetting] = [
.linkedFramework("CoreAudio"),
.linkedFramework("AudioToolbox"),
.linkedFramework("CoreFoundation"),
]
#elseif os(Windows)
let cLumaAudioSources = ["luma_audio_device.c"]
let cLumaAudioLinkerSettings: [LinkerSetting] = []
#else
let cLumaAudioSources = ["luma_audio_device.c"]
// miniaudio dlopens ALSA and PulseAudio, so neither is a link-time dependency.
let cLumaAudioLinkerSettings: [LinkerSetting] = [
.linkedLibrary("pthread"),
.linkedLibrary("m"),
.linkedLibrary("dl"),
]
#endif
#if !canImport(Darwin)
let cSoupTargets: [Target] = [
.systemLibrary(
name: "CSoup",
path: "Sources/CSoup",
pkgConfig: "libsoup-3.0",
providers: [
.apt(["libsoup-3.0-dev"]),
.yum(["libsoup3-devel"]),
]
)
]
let lumaCoreSoupDeps: [Target.Dependency] = ["CSoup"]
let cCompressionTargets: [Target] = [
.systemLibrary(
name: "CLzma",
path: "Sources/CLzma",
pkgConfig: "liblzma",
providers: [
.apt(["liblzma-dev"]),
.yum(["xz-devel"]),
]
),
.systemLibrary(
name: "CZlib",
path: "Sources/CZlib",
pkgConfig: "zlib",
providers: [
.apt(["zlib1g-dev"]),
.yum(["zlib-devel"]),
]
),
]
let lumaCoreCompressionDeps: [Target.Dependency] = ["CLzma", "CZlib"]
#else
let cSoupTargets: [Target] = []
let lumaCoreSoupDeps: [Target.Dependency] = []
let cCompressionTargets: [Target] = []
let lumaCoreCompressionDeps: [Target.Dependency] = []
#endif
// Runtime GLSL->MSL translation, so a shader written in a snippet reaches a
// Metal host with no build step, and the same libraries do it at build time.
// Only Apple platforms have one to reach: elsewhere OpenGL takes the GLSL as
// it stands, and neither the target nor the toolchain it needs is built.
//
// Neither project builds under SwiftPM, so CI makes them into an xcframework
// (see scripts/make-shader-toolchain-xcframework.sh) and this names it.
//
// A locally made one short-circuits the published artifact, the way
// SwiftyPharo honours PHARO_VM_ROOT: run that script and set
// SHADER_TOOLCHAIN_ROOT=artifacts/ShaderToolchain.xcframework, which SwiftPM
// wants relative to the package. Asking the filesystem rather than being told
// would not do -- a manifest is cached, so whichever answer it gave first
// would stick.
let shaderToolchainVersion = "2"
let shaderToolchainRoot = ProcessInfo.processInfo.environment["SHADER_TOOLCHAIN_ROOT"]
#if canImport(Darwin)
let shaderToolchainTarget: Target = shaderToolchainRoot.map {
.binaryTarget(name: "ShaderToolchain", path: $0)
} ?? .binaryTarget(
name: "ShaderToolchain",
url: "https://github.com/frida/luma/releases/download/"
+ "shader-toolchain-\(shaderToolchainVersion)/ShaderToolchain.xcframework.zip",
checksum: "721feadac2243501ac04141ee6bd579955fce573f78c78d220c970eac0b97211"
)
let shaderTranslateTargets: [Target] = [
shaderToolchainTarget,
.target(
name: "CShaderTranslate",
dependencies: ["ShaderToolchain"],
path: "Sources/CShaderTranslate",
publicHeadersPath: "include",
linkerSettings: [.unsafeFlags(["-lc++"])]
),
]
let shaderTranslateDeps: [Target.Dependency] = ["CShaderTranslate"]
#else
let shaderTranslateTargets: [Target] = []
let shaderTranslateDeps: [Target.Dependency] = []
#endif
// Typed up front: left inline, the whole array and its four concatenations
// are one expression, and the type-checker gives up on it.
let lumaTargets: [Target] = [
.target(
name: "LumaCore",
dependencies: [
.product(name: "Frida", package: "frida-swift"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "GRDB", package: "GRDB.swift"),
.product(name: "SwiftyR2", package: "SwiftyR2"),
.product(name: "SwiftyPharo", package: "SwiftyPharo"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "NIOHTTP2", package: "swift-nio-http2"),
.product(name: "NIOHPACK", package: "swift-nio-http2"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
"CLumaAudio",
"CZstd",
] + lumaCoreSoupDeps + lumaCoreCompressionDeps + shaderTranslateDeps,
path: "Sources/LumaCore",
exclude: lumaCoreExcludes,
resources: [
.process("Resources/LumaPortal.pem"),
.copy("Resources/MachineIcons"),
// Staged by the build, and copied rather than processed so it
// keeps the directory the runtime looks in.
.copy("Resources/pharo-image"),
],
swiftSettings: [
.swiftLanguageMode(.v6),
],
plugins: lumaCorePlugins
),
.executableTarget(
name: "LumaBundleCompiler",
dependencies: [
.product(name: "Frida", package: "frida-swift"),
],
path: "Sources/LumaBundleCompiler",
swiftSettings: [
.swiftLanguageMode(.v5),
]
),
.target(
name: "CZstd",
path: "Sources/CZstd",
publicHeadersPath: "include"
),
.target(
name: "CLumaAudio",
path: "Sources/CLumaAudio",
sources: cLumaAudioSources,
publicHeadersPath: "include",
linkerSettings: cLumaAudioLinkerSettings
),
.executableTarget(
name: "LumaSynthCheck",
dependencies: ["LumaCore"],
path: "Sources/LumaSynthCheck",
swiftSettings: [.swiftLanguageMode(.v6)]
),
.executableTarget(
name: "LumaExampleCheck",
dependencies: ["LumaCore"],
path: "Sources/LumaExampleCheck",
swiftSettings: [
.swiftLanguageMode(.v6),
]
),
.executableTarget(
name: "LumaEditorCheck",
dependencies: ["LumaCore"],
path: "Sources/LumaEditorCheck",
swiftSettings: [
.swiftLanguageMode(.v6),
]
),
.executableTarget(
name: "LumaEmulatorCheck",
dependencies: [
"LumaCore",
.product(name: "Frida", package: "frida-swift"),
],
path: "Sources/LumaEmulatorCheck",
swiftSettings: [
.swiftLanguageMode(.v5),
],
linkerSettings: lumaFridaDevkitLinkerSettings
),
.executableTarget(
name: "LumaShaderCompiler",
dependencies: shaderTranslateDeps,
path: "Sources/LumaShaderCompiler",
swiftSettings: [
.swiftLanguageMode(.v5),
]
),
.executableTarget(
name: "LumaVMCheck",
dependencies: [
"LumaCore",
.product(name: "Frida", package: "frida-swift"),
],
path: "Sources/LumaVMCheck",
swiftSettings: [
.swiftLanguageMode(.v5),
]
),
]
// Frida comes from the published bindings and the artifact they name. Work on
// frida-core itself is picked up by pointing FRIDA_SWIFT_ROOT at a checkout of
// the bindings beside it, with USE_SYSTEM_FRIDA set so they link what
// pkg-config finds. Being told rather than asking the filesystem is what the
// toolchain artifact does above, and for the same reason.
let fridaSwift: Package.Dependency = ProcessInfo.processInfo.environment["FRIDA_SWIFT_ROOT"]
.map { Package.Dependency.package(path: $0) } ?? .package(
url: "https://github.com/frida/frida-swift",
branch: "main"
)
let package = Package(
name: "luma",
platforms: [
.macOS(.v15),
.iOS("26.0"),
.visionOS(.v2),
],
products: [
.library(name: "LumaCore", targets: ["LumaCore"]),
.executable(name: "LumaBundleCompiler", targets: ["LumaBundleCompiler"]),
.executable(name: "LumaShaderCompiler", targets: ["LumaShaderCompiler"]),
.executable(name: "LumaExampleCheck", targets: ["LumaExampleCheck"]),
.executable(name: "LumaEditorCheck", targets: ["LumaEditorCheck"]),
.executable(name: "LumaSynthCheck", targets: ["LumaSynthCheck"]),
],
dependencies: [
fridaSwift,
.package(url: "https://github.com/apple/swift-crypto", .upToNextMajor(from: "3.0.0")),
.package(url: "https://github.com/groue/GRDB.swift", .upToNextMajor(from: "7.0.0")),
.package(url: "https://github.com/radareorg/SwiftyR2", branch: "main"),
.package(url: "https://github.com/frida/SwiftyPharo", branch: "main"),
.package(url: "https://github.com/apple/swift-nio", .upToNextMajor(from: "2.76.0")),
.package(url: "https://github.com/apple/swift-nio-http2", .upToNextMajor(from: "1.35.0")),
.package(url: "https://github.com/apple/swift-protobuf", .upToNextMajor(from: "1.28.0")),
],
targets: cSoupTargets + cCompressionTargets + shaderTranslateTargets + lumaTargets + lumaBundlePluginTargets
)