@@ -31,9 +31,11 @@ import {
3131 ANDROID_TARGETS ,
3232 AndroidTargetName ,
3333 APPLE_TARGETS ,
34+ AppleOperatingSystem ,
3435 AppleTargetName ,
3536 ensureAvailableTargets ,
3637 filterTargetsByPlatform ,
38+ parseAppleTargetName ,
3739} from "./targets.js" ;
3840import { generateTypeScriptDeclarations } from "./napi-rs.js" ;
3941import { getBlockComment } from "./banner.js" ;
@@ -299,16 +301,16 @@ export const buildCommand = new Command("build")
299301 }
300302
301303 if ( appleLibraries . length > 0 ) {
302- const libraryPaths = await combineLibraries ( appleLibraries ) ;
304+ const libraries = await combineAppleLibraries ( appleLibraries ) ;
303305
304306 const frameworkPaths = await oraPromise (
305307 Promise . all (
306- libraryPaths . map ( ( libraryPath ) =>
308+ libraries . map ( ( library ) =>
307309 limit ( ( ) =>
308- // TODO: Pass true as `versioned` argument for -darwin targets
309310 createAppleFramework ( {
310- libraryPath,
311+ libraryPath : library . path ,
311312 bundleIdentifier : appleBundleIdentifier ,
313+ versioned : library . os === "darwin" ,
312314 } ) ,
313315 ) ,
314316 ) ,
@@ -389,16 +391,23 @@ export const buildCommand = new Command("build")
389391 ) ,
390392 ) ;
391393
392- async function createUniversalAppleLibraries ( libraryPathGroups : string [ ] [ ] ) {
394+ async function createUniversalAppleLibraries (
395+ groups : { os : AppleOperatingSystem ; paths : string [ ] } [ ] ,
396+ ) : Promise < { os : AppleOperatingSystem ; path : string } [ ] > {
393397 const result = await oraPromise (
394398 Promise . all (
395- libraryPathGroups . map ( async ( libraryPaths ) => {
396- if ( libraryPaths . length === 0 ) {
399+ groups . map ( async ( { os , paths } ) => {
400+ if ( paths . length === 0 ) {
397401 return [ ] ;
398- } else if ( libraryPaths . length = == 1 ) {
399- return libraryPaths ;
402+ } else if ( paths . length == 1 ) {
403+ return [ { os , path : paths [ 0 ] } ] ;
400404 } else {
401- return [ await createUniversalAppleLibrary ( libraryPaths ) ] ;
405+ return [
406+ {
407+ os,
408+ path : await createUniversalAppleLibrary ( paths ) ,
409+ } ,
410+ ] ;
402411 }
403412 } ) ,
404413 ) ,
@@ -412,15 +421,21 @@ async function createUniversalAppleLibraries(libraryPathGroups: string[][]) {
412421 return result . flat ( ) ;
413422}
414423
415- async function combineLibraries (
424+ type CombinedAppleLibrary = {
425+ path : string ;
426+ os : AppleOperatingSystem ;
427+ } ;
428+
429+ async function combineAppleLibraries (
416430 libraries : Readonly < [ AppleTargetName , string ] > [ ] ,
417- ) : Promise < string [ ] > {
431+ ) : Promise < CombinedAppleLibrary [ ] > {
418432 const result = [ ] ;
419433 const darwinLibraries = [ ] ;
420434 const iosSimulatorLibraries = [ ] ;
421435 const tvosSimulatorLibraries = [ ] ;
422436 for ( const [ target , libraryPath ] of libraries ) {
423- if ( target . endsWith ( "-darwin" ) ) {
437+ const { os } = parseAppleTargetName ( target ) ;
438+ if ( os === "darwin" ) {
424439 darwinLibraries . push ( libraryPath ) ;
425440 } else if (
426441 target === "aarch64-apple-ios-sim" ||
@@ -433,14 +448,14 @@ async function combineLibraries(
433448 ) {
434449 tvosSimulatorLibraries . push ( libraryPath ) ;
435450 } else {
436- result . push ( libraryPath ) ;
451+ result . push ( { os , path : libraryPath } ) ;
437452 }
438453 }
439454
440455 const combinedLibraryPaths = await createUniversalAppleLibraries ( [
441- darwinLibraries ,
442- iosSimulatorLibraries ,
443- tvosSimulatorLibraries ,
456+ { os : "darwin" , paths : darwinLibraries } ,
457+ { os : "ios" , paths : iosSimulatorLibraries } ,
458+ { os : "tvos" , paths : tvosSimulatorLibraries } ,
444459 ] ) ;
445460
446461 return [ ...result , ...combinedLibraryPaths ] ;
0 commit comments