19
19
20
20
import PackageDescription
21
21
22
- let debug = " _debug "
23
- let deliverables = [
22
+ let debug_suffix = " _debug "
23
+ let dependencies_suffix = " _with_dependencies "
24
+
25
+ let products = [
24
26
" backend_coreml " : [
25
27
" frameworks " : [
26
28
" Accelerate " ,
@@ -37,49 +39,64 @@ let deliverables = [
37
39
" MetalPerformanceShadersGraph " ,
38
40
] ,
39
41
] ,
40
- " backend_xnnpack " : [ : ] ,
41
- " executorch " : [ : ] ,
42
+ " backend_xnnpack " : [
43
+ " targets " : [
44
+ " threadpool " ,
45
+ ] ,
46
+ ] ,
47
+ " executorch " : [
48
+ " libraries " : [
49
+ " c++ " ,
50
+ ] ,
51
+ ] ,
42
52
" kernels_custom " : [ : ] ,
43
- " kernels_optimized " : [ : ] ,
53
+ " kernels_optimized " : [
54
+ " frameworks " : [
55
+ " Accelerate " ,
56
+ ] ,
57
+ " targets " : [
58
+ " threadpool " ,
59
+ ] ,
60
+ ] ,
44
61
" kernels_portable " : [ : ] ,
45
62
" kernels_quantized " : [ : ] ,
46
63
] . reduce ( into: [ String: [ String: Any] ] ( ) ) {
47
64
$0 [ $1. key] = $1. value
48
- $0 [ $1. key + debug] = $1. value
49
- } . reduce ( into: [ String: [ String: Any] ] ( ) ) {
50
- var newValue = $1. value
51
- if $1. key. hasSuffix ( debug) {
52
- $1. value. forEach { key, value in
53
- if key. hasSuffix ( debug) {
54
- newValue [ String ( key. dropLast ( debug. count) ) ] = value
55
- }
56
- }
57
- }
58
- $0 [ $1. key] = newValue. filter { key, _ in !key. hasSuffix ( debug) }
65
+ $0 [ $1. key + debug_suffix] = $1. value
59
66
}
60
67
68
+ let targets = [
69
+ " threadpool " ,
70
+ ] . flatMap { [ $0, $0 + debug_suffix] }
71
+
61
72
let package = Package (
62
73
name: " executorch " ,
63
74
platforms: [
64
75
. iOS( . v17) ,
65
76
. macOS( . v10_15) ,
66
77
] ,
67
- products: deliverables . keys. map { key in
68
- . library( name: key, targets: [ " \( key) _dependencies " ] )
78
+ products: products . keys. map { key in
79
+ . library( name: key, targets: [ " \( key) \( dependencies_suffix ) " ] )
69
80
} . sorted { $0. name < $1. name } ,
70
- targets: deliverables. flatMap { key, value -> [ Target ] in
81
+ targets: targets. map { key in
82
+ . binaryTarget(
83
+ name: key,
84
+ path: " cmake-out/ \( key) .xcframework "
85
+ )
86
+ } + products. flatMap { key, value -> [ Target ] in
71
87
[
72
88
. binaryTarget(
73
89
name: key,
74
90
path: " cmake-out/ \( key) .xcframework "
75
91
) ,
76
92
. target(
77
- name: " \( key) _dependencies " ,
78
- dependencies: [ . target( name: key) ] ,
93
+ name: " \( key) \( dependencies_suffix) " ,
94
+ dependencies: ( [ key] +
95
+ ( value [ " targets " ] as? [ String ] ?? [ ] ) . map {
96
+ target in key. hasSuffix ( debug_suffix) ? target + debug_suffix : target
97
+ } ) . map { . target( name: $0) } ,
79
98
path: " .Package.swift/ \( key) " ,
80
- linkerSettings: [
81
- . linkedLibrary( " c++ " )
82
- ] +
99
+ linkerSettings:
83
100
( value [ " frameworks " ] as? [ String ] ?? [ ] ) . map { . linkedFramework( $0) } +
84
101
( value [ " libraries " ] as? [ String ] ?? [ ] ) . map { . linkedLibrary( $0) }
85
102
) ,
@@ -88,18 +105,17 @@ let package = Package(
88
105
. testTarget(
89
106
name: " tests " ,
90
107
dependencies: [
91
- . target( name: " executorch_debug " ) ,
92
- . target( name: " kernels_portable " ) ,
108
+ . target( name: " executorch \( debug_suffix ) " ) ,
109
+ . target( name: " kernels_optimized \( dependencies_suffix ) " ) ,
93
110
] ,
94
111
path: " extension/apple/ExecuTorch/__tests__ " ,
95
112
resources: [
96
- . copy( " resources/add.pte " )
113
+ . copy( " resources/add.pte " ) ,
97
114
] ,
98
115
linkerSettings: [
99
- . linkedLibrary( " c++ " ) ,
100
116
. unsafeFlags( [
101
117
" -Xlinker " , " -force_load " ,
102
- " -Xlinker " , " cmake-out/kernels_portable .xcframework/macos-arm64/libkernels_portable_macos .a " ,
118
+ " -Xlinker " , " cmake-out/kernels_optimized .xcframework/macos-arm64/libkernels_optimized_macos .a " ,
103
119
] )
104
120
]
105
121
)
0 commit comments