1919
2020import PackageDescription
2121
22- let debug = " _debug "
23- let deliverables = [
22+ let debug_suffix = " _debug "
23+ let dependencies_suffix = " _with_dependencies "
24+
25+ let products = [
2426 " backend_coreml " : [
2527 " frameworks " : [
2628 " Accelerate " ,
@@ -37,49 +39,64 @@ let deliverables = [
3739 " MetalPerformanceShadersGraph " ,
3840 ] ,
3941 ] ,
40- " backend_xnnpack " : [ : ] ,
41- " executorch " : [ : ] ,
42+ " backend_xnnpack " : [
43+ " targets " : [
44+ " threadpool " ,
45+ ] ,
46+ ] ,
47+ " executorch " : [
48+ " libraries " : [
49+ " c++ " ,
50+ ] ,
51+ ] ,
4252 " kernels_custom " : [ : ] ,
43- " kernels_optimized " : [ : ] ,
53+ " kernels_optimized " : [
54+ " frameworks " : [
55+ " Accelerate " ,
56+ ] ,
57+ " targets " : [
58+ " threadpool " ,
59+ ] ,
60+ ] ,
4461 " kernels_portable " : [ : ] ,
4562 " kernels_quantized " : [ : ] ,
4663] . reduce ( into: [ String: [ String: Any] ] ( ) ) {
4764 $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
5966}
6067
68+ let targets = [
69+ " threadpool " ,
70+ ] . flatMap { [ $0, $0 + debug_suffix] }
71+
6172let package = Package (
6273 name: " executorch " ,
6374 platforms: [
6475 . iOS( . v17) ,
6576 . macOS( . v10_15) ,
6677 ] ,
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 ) " ] )
6980 } . 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
7187 [
7288 . binaryTarget(
7389 name: key,
7490 path: " cmake-out/ \( key) .xcframework "
7591 ) ,
7692 . 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) } ,
7998 path: " .Package.swift/ \( key) " ,
80- linkerSettings: [
81- . linkedLibrary( " c++ " )
82- ] +
99+ linkerSettings:
83100 ( value [ " frameworks " ] as? [ String ] ?? [ ] ) . map { . linkedFramework( $0) } +
84101 ( value [ " libraries " ] as? [ String ] ?? [ ] ) . map { . linkedLibrary( $0) }
85102 ) ,
@@ -88,18 +105,17 @@ let package = Package(
88105 . testTarget(
89106 name: " tests " ,
90107 dependencies: [
91- . target( name: " executorch_debug " ) ,
92- . target( name: " kernels_portable " ) ,
108+ . target( name: " executorch \( debug_suffix ) " ) ,
109+ . target( name: " kernels_optimized \( dependencies_suffix ) " ) ,
93110 ] ,
94111 path: " extension/apple/ExecuTorch/__tests__ " ,
95112 resources: [
96- . copy( " resources/add.pte " )
113+ . copy( " resources/add.pte " ) ,
97114 ] ,
98115 linkerSettings: [
99- . linkedLibrary( " c++ " ) ,
100116 . unsafeFlags( [
101117 " -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 " ,
103119 ] )
104120 ]
105121 )
0 commit comments