|
| 1 | +// swift-tools-version: 6.0 |
| 2 | +/** |
| 3 | + * Swift Package Manager support. |
| 4 | + * |
| 5 | + * This is a hand-maintained ("self-managed") manifest: React Native's SPM |
| 6 | + * autolinker sees a checked-in Package.swift and uses it as-is instead of |
| 7 | + * generating a wrapper around this package — see `findSelfManagedPackageDir` |
| 8 | + * in react-native/scripts/spm/generate-spm-autolinking.js. CocoaPods keeps |
| 9 | + * using react-native-image-editor.podspec, so apps on RN < 0.87 are unaffected. |
| 10 | + * |
| 11 | + * Two contracts the autolinker imposes, both easy to break silently: |
| 12 | + * |
| 13 | + * 1. The package, its single library product and the target must all be named |
| 14 | + * `ImageEditor`. The `swiftpmConfig.name` in package.json pins this name so |
| 15 | + * CocoaPods' dashed pod name does not become the SPM product name. The |
| 16 | + * aggregator references us as |
| 17 | + * `.product(name: "ImageEditor", package: "ImageEditor")`, so renaming any |
| 18 | + * of the three fails resolution with "no product named ... available". |
| 19 | + * |
| 20 | + * 2. The `.package(path:)` references below are constant relative strings, not |
| 21 | + * paths to discover at manifest-evaluation time. The autolinker routes this |
| 22 | + * package through a symlink at |
| 23 | + * `<appRoot>/build/generated/autolinking/libs/ImageEditor`, and SwiftPM |
| 24 | + * resolves a manifest's relative package paths against that symlink without |
| 25 | + * canonicalizing it, so both packages sit at a fixed depth in every app: |
| 26 | + * build/xcframeworks -> ../../../../xcframeworks |
| 27 | + * build/generated/ios -> ../../../ios |
| 28 | + * That is exactly what react-native/scripts/spm/scaffold-package-swift.js |
| 29 | + * emits. Do not replace them with `#filePath` walks or absolute paths. |
| 30 | + * |
| 31 | + * React headers need no search paths here — they arrive through the products |
| 32 | + * listed on the target. `RCTImage` is not a separate product: the React |
| 33 | + * xcframework vends RCTImageLoader / RCTImageUtils / RCTConvert flat under the |
| 34 | + * `React` module and umbrella, and exports RCTTransformImage et al. |
| 35 | + */ |
| 36 | + |
| 37 | +import PackageDescription |
| 38 | + |
| 39 | +let package = Package( |
| 40 | + name: "ImageEditor", |
| 41 | + platforms: [.iOS(.v15)], |
| 42 | + products: [ |
| 43 | + .library(name: "ImageEditor", targets: ["ImageEditor"]), |
| 44 | + ], |
| 45 | + dependencies: [ |
| 46 | + .package(name: "ReactNative", path: "../../../../xcframeworks"), |
| 47 | + .package(name: "React-GeneratedCode", path: "../../../ios"), |
| 48 | + ], |
| 49 | + targets: [ |
| 50 | + .target( |
| 51 | + name: "ImageEditor", |
| 52 | + dependencies: [ |
| 53 | + .product(name: "ReactHeaders", package: "ReactNative"), |
| 54 | + .product(name: "ReactNativeHeaders", package: "ReactNative"), |
| 55 | + .product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"), |
| 56 | + .product(name: "ReactAppHeaders", package: "React-GeneratedCode"), |
| 57 | + ], |
| 58 | + // Scoped to `ios` so SPM discovers sources itself — a new native |
| 59 | + // file needs no manifest edit. `publicHeadersPath: "."` keeps the |
| 60 | + // same include surface as CocoaPods (`#import "RNCFileSystem.h"`), |
| 61 | + // and keeps SPM's artifacts (.build/, .swiftpm/) out of the source |
| 62 | + // dir's way. |
| 63 | + path: "ios", |
| 64 | + publicHeadersPath: ".", |
| 65 | + cxxSettings: [ |
| 66 | + // DEBUG/NDEBUG must match the prebuilt React.framework's |
| 67 | + // config-gated C++ ABI: NDEBUG strips DebugStringConvertible's |
| 68 | + // vtable and shifts the ShadowNode layout codegen'd types |
| 69 | + // inherit, so a mismatched Release link fails on undefined |
| 70 | + // symbols. Mirrors React Native's own SPM manifests. |
| 71 | + .define("DEBUG", .when(configuration: .debug)), |
| 72 | + .define("NDEBUG", .when(configuration: .release)), |
| 73 | + ], |
| 74 | + linkerSettings: [ |
| 75 | + .linkedFramework("UIKit"), |
| 76 | + .linkedFramework("Foundation"), |
| 77 | + .linkedFramework("CoreGraphics"), |
| 78 | + ] |
| 79 | + ), |
| 80 | + ], |
| 81 | + // Required by the React headers (concepts, std::optional) and by the |
| 82 | + // codegen'd spec this module imports. |
| 83 | + cxxLanguageStandard: .cxx20 |
| 84 | +) |
0 commit comments