bleam 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/cli.cjs +23 -4
  2. package/dist/cli.d.cts +2 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +23 -4
  5. package/dist/{ui-234Plg7Z.d.cts → ui-Bg11tvlc.d.ts} +7 -7
  6. package/dist/ui.d.ts +1 -1
  7. package/dist/window.d.ts +1 -1
  8. package/package.json +4 -1
  9. package/templates/image-generation/app/index.tsx +1 -1
  10. package/templates/native/.gitattributes +1 -0
  11. package/templates/native/App.tsx +26 -0
  12. package/templates/native/app.json +12 -0
  13. package/templates/native/index.ts +8 -0
  14. package/templates/native/ios/.xcode.env +11 -0
  15. package/templates/native/ios/Bleam/AI/Flux2/Configuration/Flux2Config.swift +288 -0
  16. package/templates/native/ios/Bleam/AI/Flux2/Configuration/MemoryConfig.swift +233 -0
  17. package/templates/native/ios/Bleam/AI/Flux2/Configuration/MemoryOptimizationConfig.swift +157 -0
  18. package/templates/native/ios/Bleam/AI/Flux2/Configuration/ModelRegistry.swift +425 -0
  19. package/templates/native/ios/Bleam/AI/Flux2/Configuration/QuantizationConfig.swift +138 -0
  20. package/templates/native/ios/Bleam/AI/Flux2/Configuration/TransformerRepoProfile.swift +59 -0
  21. package/templates/native/ios/Bleam/AI/Flux2/Configuration/VAEConfig.swift +134 -0
  22. package/templates/native/ios/Bleam/AI/Flux2/Flux2Core.swift +55 -0
  23. package/templates/native/ios/Bleam/AI/Flux2/Loading/WeightLoader.swift +1192 -0
  24. package/templates/native/ios/Bleam/AI/Flux2/Pipeline/FluxImageRunner.swift +1282 -0
  25. package/templates/native/ios/Bleam/AI/Flux2/Pipeline/LatentUtils.swift +191 -0
  26. package/templates/native/ios/Bleam/AI/Flux2/Scheduler/FlowMatchEulerScheduler.swift +279 -0
  27. package/templates/native/ios/Bleam/AI/Flux2/Text/KleinTextEncoder.swift +380 -0
  28. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Attention.swift +379 -0
  29. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Embeddings.swift +159 -0
  30. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2FeedForward.swift +154 -0
  31. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2FusedKernels.swift +198 -0
  32. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2KVCache.swift +36 -0
  33. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Modulation.swift +193 -0
  34. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2ParallelAttention.swift +389 -0
  35. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2RoPE.swift +304 -0
  36. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2SingleBlock.swift +290 -0
  37. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Transformer.swift +530 -0
  38. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2TransformerBlock.swift +362 -0
  39. package/templates/native/ios/Bleam/AI/Flux2/Utils/Flux2Debug.swift +101 -0
  40. package/templates/native/ios/Bleam/AI/Flux2/Utils/MLXCheckpoint.swift +118 -0
  41. package/templates/native/ios/Bleam/AI/Flux2/Utils/MemoryManager.swift +201 -0
  42. package/templates/native/ios/Bleam/AI/Flux2/VAE/AutoencoderKL.swift +476 -0
  43. package/templates/native/ios/Bleam/AI/Flux2/VAE/ResnetBlock.swift +316 -0
  44. package/templates/native/ios/Bleam/AI/Flux2/VAE/VAEDecoder.swift +120 -0
  45. package/templates/native/ios/Bleam/AI/Flux2/VAE/VAEEncoder.swift +136 -0
  46. package/templates/native/ios/Bleam/AppDelegate.swift +373 -0
  47. package/templates/native/ios/Bleam/Appearance.swift +62 -0
  48. package/templates/native/ios/Bleam/Bridging-Header.h +3 -0
  49. package/templates/native/ios/Bleam/Images.xcassets/AppIcon.appiconset/Contents.json +13 -0
  50. package/templates/native/ios/Bleam/Images.xcassets/Contents.json +6 -0
  51. package/templates/native/ios/Bleam/Info.plist +76 -0
  52. package/templates/native/ios/Bleam/PrivacyInfo.xcprivacy +48 -0
  53. package/templates/native/ios/Bleam/SceneDelegate.swift +58 -0
  54. package/templates/native/ios/Bleam/SplashScreen.storyboard +47 -0
  55. package/templates/native/ios/Bleam/Supporting/Expo.plist +6 -0
  56. package/templates/native/ios/Bleam/bleam.entitlements +10 -0
  57. package/templates/native/ios/Bleam.xcodeproj/project.pbxproj +1146 -0
  58. package/templates/native/ios/Bleam.xcodeproj/xcshareddata/xcschemes/Bleam.xcscheme +88 -0
  59. package/templates/native/ios/GenerationService/GenerationService.entitlements +10 -0
  60. package/templates/native/ios/GenerationService/ImageGenerationRunner.swift +591 -0
  61. package/templates/native/ios/GenerationService/Info.plist +31 -0
  62. package/templates/native/ios/GenerationService/main.swift +165 -0
  63. package/templates/native/ios/PlatformHelper/Info.plist +29 -0
  64. package/templates/native/ios/PlatformHelper/main.swift +335 -0
  65. package/templates/native/ios/Podfile +198 -0
  66. package/templates/native/ios/Podfile.lock +2284 -0
  67. package/templates/native/ios/Podfile.properties.json +5 -0
  68. package/templates/native/ios/Shared/Generation/GenerationServiceProtocol.swift +12 -0
  69. package/templates/native/ios/Shared/Generation/GenerationWorkerProtocol.swift +124 -0
  70. package/templates/native/metro.config.js +6 -0
  71. package/templates/native/modules/bleam-runtime/BleamRuntime.podspec +14 -0
  72. package/templates/native/modules/bleam-runtime/expo-module.config.json +8 -0
  73. package/templates/native/modules/bleam-runtime/ios/AIModule.swift +1258 -0
  74. package/templates/native/modules/bleam-runtime/ios/GenerationContracts.swift +135 -0
  75. package/templates/native/modules/bleam-runtime/ios/PlatformModule.swift +313 -0
  76. package/templates/native/modules/bleam-runtime/package.json +5 -0
  77. package/templates/native/package.json +39 -0
  78. package/templates/native/scripts/build/mlx-frameworks.ts +421 -0
  79. package/templates/native/scripts/start/index.ts +474 -0
  80. package/templates/native/scripts/start/known-failures.ts +20 -0
  81. package/templates/native/scripts/start/loader.ts +76 -0
  82. package/templates/native/scripts/start/native-state.ts +242 -0
  83. package/templates/native/scripts/start/package.json +4 -0
  84. package/templates/native/scripts/start/swift-packages.ts +414 -0
  85. package/templates/native/scripts/start/xcode-formatter.ts +106 -0
  86. package/templates/native/tsconfig.json +14 -0
  87. package/templates/native/yarn.lock +3749 -0
  88. package/dist/ui-BJmXhz9Q.d.ts +0 -92
  89. package/dist/ui-Dd7SXdbg.d.cts +0 -92
  90. package/dist/ui-Ds88eETu.d.ts +0 -92
  91. package/dist/ui-TaqnB5SP.d.ts +0 -92
  92. package/dist/ui-WQvnXL0W.d.ts +0 -92
@@ -0,0 +1,421 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { execFileSync } from 'node:child_process'
3
+ import {
4
+ cpSync,
5
+ existsSync,
6
+ mkdirSync,
7
+ readdirSync,
8
+ readFileSync,
9
+ rmSync,
10
+ writeFileSync,
11
+ } from 'node:fs'
12
+ import path from 'node:path'
13
+ import { pathToFileURL } from 'node:url'
14
+
15
+ type MLXFrameworkAsset = {
16
+ name: string
17
+ url: string
18
+ sha256: string
19
+ }
20
+
21
+ export const MLX_SWIFT_VERSION = '0.31.6'
22
+ export const MLX_CATALYST_LIBRARY_IDENTIFIER = 'ios-arm64_x86_64-maccatalyst'
23
+ export const MLX_MACOS_LIBRARY_IDENTIFIER = 'macos-arm64_x86_64'
24
+ export const SWIFT_NUMERICS_VERSION = '1.1.1'
25
+
26
+ const SWIFT_NUMERICS_ASSET: MLXFrameworkAsset = {
27
+ name: `swift-numerics-${SWIFT_NUMERICS_VERSION}.zip`,
28
+ url: `https://github.com/apple/swift-numerics/archive/refs/tags/${SWIFT_NUMERICS_VERSION}.zip`,
29
+ sha256: 'f37ab2a80b6507ad2af7f564d7481ab72eb1f7a70692238de12ba442443462e0',
30
+ }
31
+
32
+ const SWIFT_NUMERICS_SWIFT_MODULES = ['RealModule', 'ComplexModule', 'Numerics']
33
+ const SWIFT_NUMERICS_ARCHES = [
34
+ { arch: 'arm64', triple: 'arm64-apple-ios-macabi' },
35
+ { arch: 'x86_64', triple: 'x86_64-apple-ios-macabi' },
36
+ ]
37
+ const SWIFT_NUMERICS_MACOS_ARCHES = [
38
+ { arch: 'arm64', triple: 'arm64-apple-macos' },
39
+ { arch: 'x86_64', triple: 'x86_64-apple-macos' },
40
+ ]
41
+
42
+ export const MLX_SWIFT_ASSETS: MLXFrameworkAsset[] = [
43
+ {
44
+ name: 'Cmlx.xcframework.zip',
45
+ url: 'https://github.com/ml-explore/mlx-swift/releases/download/0.31.6/Cmlx.xcframework.zip',
46
+ sha256: 'a202bf1dcfe1e64404adabfeb5eb363332e3a6221d18e4289ca0663fa3ab86c9',
47
+ },
48
+ {
49
+ name: 'MLX.xcframework.zip',
50
+ url: 'https://github.com/ml-explore/mlx-swift/releases/download/0.31.6/MLX.xcframework.zip',
51
+ sha256: '697f45a2ec2c0c312d9aa041a2b21f9c3706f18276823854dd96396118004c25',
52
+ },
53
+ {
54
+ name: 'MLXNN.xcframework.zip',
55
+ url: 'https://github.com/ml-explore/mlx-swift/releases/download/0.31.6/MLXNN.xcframework.zip',
56
+ sha256: 'afe3c8fa7c95e343266897b42bc7b312c3b7f4baac50ead955161e288eb51d79',
57
+ },
58
+ {
59
+ name: 'MLXOptimizers.xcframework.zip',
60
+ url: 'https://github.com/ml-explore/mlx-swift/releases/download/0.31.6/MLXOptimizers.xcframework.zip',
61
+ sha256: '6273556851fdd0c869b1b245917062acbec73f50a08944b77c4f6206400df5c1',
62
+ },
63
+ ]
64
+
65
+ export function mlxFrameworkCacheRoot(rootDir: string) {
66
+ return path.join(rootDir, 'build', 'Vendor', 'MLXSwift', MLX_SWIFT_VERSION)
67
+ }
68
+
69
+ export function mlxCatalystFrameworksRoot(rootDir: string) {
70
+ return path.join(
71
+ rootDir,
72
+ 'ios',
73
+ 'Vendor',
74
+ 'MLXSwift',
75
+ MLX_SWIFT_VERSION,
76
+ )
77
+ }
78
+
79
+ export function mlxMacOSFrameworksRoot(rootDir: string) {
80
+ return path.join(
81
+ rootDir,
82
+ 'ios',
83
+ 'Vendor',
84
+ 'MLXSwift',
85
+ `${MLX_SWIFT_VERSION}-macos`,
86
+ )
87
+ }
88
+
89
+ function assetFrameworkName(asset: MLXFrameworkAsset) {
90
+ return asset.name.replace(/\.xcframework\.zip$/, '')
91
+ }
92
+
93
+ function sha256File(filePath: string) {
94
+ return createHash('sha256').update(readFileSync(filePath)).digest('hex')
95
+ }
96
+
97
+ function downloadAsset(asset: MLXFrameworkAsset, destination: string) {
98
+ if (existsSync(destination) && sha256File(destination) === asset.sha256) {
99
+ return
100
+ }
101
+
102
+ rmSync(destination, { force: true })
103
+ execFileSync('curl', ['--fail', '--location', '--output', destination, asset.url], {
104
+ stdio: 'inherit',
105
+ })
106
+
107
+ const actual = sha256File(destination)
108
+ if (actual !== asset.sha256) {
109
+ rmSync(destination, { force: true })
110
+ throw new Error(
111
+ `Checksum mismatch for ${asset.name}: expected ${asset.sha256}, got ${actual}`,
112
+ )
113
+ }
114
+ }
115
+
116
+ function findExtractedXCFramework(extractRoot: string, frameworkName: string) {
117
+ const direct = path.join(extractRoot, `${frameworkName}.xcframework`)
118
+ if (existsSync(direct)) {
119
+ return direct
120
+ }
121
+
122
+ for (const entry of readdirSync(extractRoot)) {
123
+ const candidate = path.join(extractRoot, entry, `${frameworkName}.xcframework`)
124
+ if (existsSync(candidate)) {
125
+ return candidate
126
+ }
127
+ }
128
+
129
+ throw new Error(`Could not find ${frameworkName}.xcframework in ${extractRoot}`)
130
+ }
131
+
132
+ function extractCatalystFramework(asset: MLXFrameworkAsset, zipPath: string, rootDir: string) {
133
+ extractFramework(asset, zipPath, rootDir, MLX_CATALYST_LIBRARY_IDENTIFIER, mlxCatalystFrameworksRoot(rootDir))
134
+ }
135
+
136
+ function extractMacOSFramework(asset: MLXFrameworkAsset, zipPath: string, rootDir: string) {
137
+ extractFramework(asset, zipPath, rootDir, MLX_MACOS_LIBRARY_IDENTIFIER, mlxMacOSFrameworksRoot(rootDir))
138
+ }
139
+
140
+ function extractFramework(
141
+ asset: MLXFrameworkAsset,
142
+ zipPath: string,
143
+ rootDir: string,
144
+ libraryIdentifier: string,
145
+ destinationRoot: string,
146
+ ) {
147
+ const frameworkName = assetFrameworkName(asset)
148
+ const cacheRoot = mlxFrameworkCacheRoot(rootDir)
149
+ const extractRoot = path.join(cacheRoot, 'Extracted', frameworkName)
150
+ const destination = path.join(destinationRoot, `${frameworkName}.framework`)
151
+
152
+ rmSync(extractRoot, { recursive: true, force: true })
153
+ mkdirSync(extractRoot, { recursive: true })
154
+ execFileSync('ditto', ['-x', '-k', zipPath, extractRoot])
155
+
156
+ const xcframework = findExtractedXCFramework(extractRoot, frameworkName)
157
+ const framework = path.join(
158
+ xcframework,
159
+ libraryIdentifier,
160
+ `${frameworkName}.framework`,
161
+ )
162
+ if (!existsSync(framework)) {
163
+ throw new Error(
164
+ `${asset.name} does not contain ${libraryIdentifier}/${frameworkName}.framework`,
165
+ )
166
+ }
167
+
168
+ mkdirSync(destinationRoot, { recursive: true })
169
+ rmSync(destination, { recursive: true, force: true })
170
+ cpSync(framework, destination, { recursive: true })
171
+ normalizeVersionedFrameworkSymlinks(destination, frameworkName)
172
+ }
173
+
174
+ function findSwiftNumericsSourceRoot(extractRoot: string) {
175
+ const direct = path.join(extractRoot, `swift-numerics-${SWIFT_NUMERICS_VERSION}`)
176
+ if (existsSync(path.join(direct, 'Package.swift'))) {
177
+ return direct
178
+ }
179
+
180
+ for (const entry of readdirSync(extractRoot)) {
181
+ const candidate = path.join(extractRoot, entry)
182
+ if (existsSync(path.join(candidate, 'Package.swift'))) {
183
+ return candidate
184
+ }
185
+ }
186
+
187
+ throw new Error(`Could not find swift-numerics Package.swift in ${extractRoot}`)
188
+ }
189
+
190
+ function copySwiftNumericsModuleFramework(
191
+ moduleName: string,
192
+ moduleBuildRoot: string,
193
+ destinationRoot: string,
194
+ arches = SWIFT_NUMERICS_ARCHES,
195
+ ) {
196
+ const frameworkRoot = path.join(destinationRoot, `${moduleName}.framework`)
197
+ const moduleRoot = path.join(frameworkRoot, 'Modules', `${moduleName}.swiftmodule`)
198
+ rmSync(frameworkRoot, { recursive: true, force: true })
199
+ mkdirSync(moduleRoot, { recursive: true })
200
+
201
+ for (const { arch, triple } of arches) {
202
+ const sourceBase = path.join(
203
+ moduleBuildRoot,
204
+ `${moduleName}.build`,
205
+ 'Objects-normal',
206
+ arch,
207
+ moduleName,
208
+ )
209
+
210
+ for (const extension of [
211
+ 'swiftmodule',
212
+ 'swiftinterface',
213
+ 'private.swiftinterface',
214
+ 'swiftdoc',
215
+ 'abi.json',
216
+ ]) {
217
+ const source = `${sourceBase}.${extension}`
218
+ if (existsSync(source)) {
219
+ cpSync(source, path.join(moduleRoot, `${triple}.${extension}`))
220
+ }
221
+ }
222
+ }
223
+ }
224
+
225
+ function copySwiftNumericsShimsFramework(sourceRoot: string, destinationRoot: string) {
226
+ const frameworkRoot = path.join(destinationRoot, '_NumericsShims.framework')
227
+ const headersRoot = path.join(frameworkRoot, 'Headers')
228
+ const modulesRoot = path.join(frameworkRoot, 'Modules')
229
+ rmSync(frameworkRoot, { recursive: true, force: true })
230
+ mkdirSync(headersRoot, { recursive: true })
231
+ mkdirSync(modulesRoot, { recursive: true })
232
+ cpSync(
233
+ path.join(sourceRoot, 'Sources', '_NumericsShims', 'include', '_NumericsShims.h'),
234
+ path.join(headersRoot, '_NumericsShims.h'),
235
+ )
236
+ writeFileSync(
237
+ path.join(modulesRoot, 'module.modulemap'),
238
+ [
239
+ 'framework module _NumericsShims {',
240
+ ' umbrella header "_NumericsShims.h"',
241
+ ' export *',
242
+ '}',
243
+ '',
244
+ ].join('\n'),
245
+ )
246
+ }
247
+
248
+ function ensureSwiftNumericsMacOSModules(rootDir: string) {
249
+ const macOSRoot = mlxMacOSFrameworksRoot(rootDir)
250
+ const numericsModule = path.join(
251
+ macOSRoot,
252
+ 'Numerics.framework',
253
+ 'Modules',
254
+ 'Numerics.swiftmodule',
255
+ 'arm64-apple-macos.swiftmodule',
256
+ )
257
+ if (existsSync(numericsModule)) {
258
+ return
259
+ }
260
+
261
+ const cacheRoot = mlxFrameworkCacheRoot(rootDir)
262
+ const downloadRoot = path.join(cacheRoot, 'Downloads')
263
+ const zipPath = path.join(downloadRoot, SWIFT_NUMERICS_ASSET.name)
264
+ downloadAsset(SWIFT_NUMERICS_ASSET, zipPath)
265
+
266
+ const extractRoot = path.join(cacheRoot, 'Extracted', `swift-numerics-${SWIFT_NUMERICS_VERSION}`)
267
+ rmSync(extractRoot, { recursive: true, force: true })
268
+ mkdirSync(extractRoot, { recursive: true })
269
+ execFileSync('ditto', ['-x', '-k', zipPath, extractRoot])
270
+
271
+ const sourceRoot = findSwiftNumericsSourceRoot(extractRoot)
272
+ const buildRoot = path.join(cacheRoot, 'Build', `swift-numerics-${SWIFT_NUMERICS_VERSION}-macos`)
273
+ const archivePath = path.join(buildRoot, 'Numerics-macos.xcarchive')
274
+ const derivedDataPath = path.join(buildRoot, 'DerivedData')
275
+ rmSync(buildRoot, { recursive: true, force: true })
276
+ mkdirSync(buildRoot, { recursive: true })
277
+
278
+ execFileSync(
279
+ 'xcodebuild',
280
+ [
281
+ 'archive',
282
+ '-scheme',
283
+ 'Numerics',
284
+ '-destination',
285
+ 'generic/platform=macOS',
286
+ '-archivePath',
287
+ archivePath,
288
+ '-derivedDataPath',
289
+ derivedDataPath,
290
+ 'SKIP_INSTALL=NO',
291
+ 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES',
292
+ ],
293
+ { cwd: sourceRoot, stdio: 'inherit' },
294
+ )
295
+
296
+ const moduleBuildRoot = path.join(
297
+ derivedDataPath,
298
+ 'Build',
299
+ 'Intermediates.noindex',
300
+ 'ArchiveIntermediates',
301
+ 'Numerics',
302
+ 'IntermediateBuildFilesPath',
303
+ 'swift-numerics.build',
304
+ 'Release',
305
+ )
306
+
307
+ mkdirSync(macOSRoot, { recursive: true })
308
+ copySwiftNumericsShimsFramework(sourceRoot, macOSRoot)
309
+ for (const moduleName of SWIFT_NUMERICS_SWIFT_MODULES) {
310
+ copySwiftNumericsModuleFramework(moduleName, moduleBuildRoot, macOSRoot, SWIFT_NUMERICS_MACOS_ARCHES)
311
+ }
312
+ }
313
+
314
+ function ensureSwiftNumericsCatalystModules(rootDir: string) {
315
+ const catalystRoot = mlxCatalystFrameworksRoot(rootDir)
316
+ const numericsModule = path.join(
317
+ catalystRoot,
318
+ 'Numerics.framework',
319
+ 'Modules',
320
+ 'Numerics.swiftmodule',
321
+ 'arm64-apple-ios-macabi.swiftmodule',
322
+ )
323
+ if (existsSync(numericsModule)) {
324
+ return
325
+ }
326
+
327
+ const cacheRoot = mlxFrameworkCacheRoot(rootDir)
328
+ const downloadRoot = path.join(cacheRoot, 'Downloads')
329
+ const zipPath = path.join(downloadRoot, SWIFT_NUMERICS_ASSET.name)
330
+ downloadAsset(SWIFT_NUMERICS_ASSET, zipPath)
331
+
332
+ const extractRoot = path.join(cacheRoot, 'Extracted', `swift-numerics-${SWIFT_NUMERICS_VERSION}`)
333
+ rmSync(extractRoot, { recursive: true, force: true })
334
+ mkdirSync(extractRoot, { recursive: true })
335
+ execFileSync('ditto', ['-x', '-k', zipPath, extractRoot])
336
+
337
+ const sourceRoot = findSwiftNumericsSourceRoot(extractRoot)
338
+ const buildRoot = path.join(cacheRoot, 'Build', `swift-numerics-${SWIFT_NUMERICS_VERSION}`)
339
+ const archivePath = path.join(buildRoot, 'Numerics-maccatalyst.xcarchive')
340
+ const derivedDataPath = path.join(buildRoot, 'DerivedData')
341
+ rmSync(buildRoot, { recursive: true, force: true })
342
+ mkdirSync(buildRoot, { recursive: true })
343
+
344
+ execFileSync(
345
+ 'xcodebuild',
346
+ [
347
+ 'archive',
348
+ '-scheme',
349
+ 'Numerics',
350
+ '-destination',
351
+ 'generic/platform=macOS,variant=Mac Catalyst',
352
+ '-archivePath',
353
+ archivePath,
354
+ '-derivedDataPath',
355
+ derivedDataPath,
356
+ 'SKIP_INSTALL=NO',
357
+ 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES',
358
+ ],
359
+ { cwd: sourceRoot, stdio: 'inherit' },
360
+ )
361
+
362
+ const moduleBuildRoot = path.join(
363
+ derivedDataPath,
364
+ 'Build',
365
+ 'Intermediates.noindex',
366
+ 'ArchiveIntermediates',
367
+ 'Numerics',
368
+ 'IntermediateBuildFilesPath',
369
+ 'swift-numerics.build',
370
+ 'Release-maccatalyst',
371
+ )
372
+
373
+ mkdirSync(catalystRoot, { recursive: true })
374
+ copySwiftNumericsShimsFramework(sourceRoot, catalystRoot)
375
+ for (const moduleName of SWIFT_NUMERICS_SWIFT_MODULES) {
376
+ copySwiftNumericsModuleFramework(moduleName, moduleBuildRoot, catalystRoot)
377
+ }
378
+ }
379
+
380
+ function replaceSymlink(linkPath: string, target: string) {
381
+ rmSync(linkPath, { recursive: true, force: true })
382
+ execFileSync('ln', ['-sfn', target, linkPath])
383
+ }
384
+
385
+ function normalizeVersionedFrameworkSymlinks(frameworkPath: string, frameworkName: string) {
386
+ const versionA = path.join(frameworkPath, 'Versions', 'A')
387
+ if (!existsSync(versionA)) {
388
+ return
389
+ }
390
+
391
+ replaceSymlink(path.join(frameworkPath, 'Versions', 'Current'), 'A')
392
+
393
+ for (const entry of [frameworkName, 'Modules', 'Resources', 'Headers', 'PrivateHeaders']) {
394
+ if (existsSync(path.join(versionA, entry))) {
395
+ replaceSymlink(path.join(frameworkPath, entry), path.join('Versions', 'Current', entry))
396
+ }
397
+ }
398
+ }
399
+
400
+ export function ensureMLXSwiftCatalystFrameworks(rootDir: string = process.cwd()) {
401
+ const cacheRoot = mlxFrameworkCacheRoot(rootDir)
402
+ const downloadRoot = path.join(cacheRoot, 'Downloads')
403
+ mkdirSync(downloadRoot, { recursive: true })
404
+
405
+ for (const asset of MLX_SWIFT_ASSETS) {
406
+ const zipPath = path.join(downloadRoot, asset.name)
407
+ downloadAsset(asset, zipPath)
408
+ extractCatalystFramework(asset, zipPath, rootDir)
409
+ extractMacOSFramework(asset, zipPath, rootDir)
410
+ }
411
+
412
+ ensureSwiftNumericsCatalystModules(rootDir)
413
+ ensureSwiftNumericsMacOSModules(rootDir)
414
+ }
415
+
416
+ if (
417
+ process.argv[1] &&
418
+ import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
419
+ ) {
420
+ ensureMLXSwiftCatalystFrameworks(process.cwd())
421
+ }