|
| 1 | +// swift-tools-version: 6.0 |
| 2 | +/* |
| 3 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 4 | + * |
| 5 | + * This source code is licensed under the MIT license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +import PackageDescription |
| 10 | + |
| 11 | +let react = "React" |
| 12 | + |
| 13 | +let cxxRNDepHeaderSearchPath: (Int) -> CXXSetting = { |
| 14 | + let prefix = (0..<$0).map { _ in "../" } .joined(separator: "") |
| 15 | + return .headerSearchPath("\(prefix)third-party/ReactNativeDependencies.xcframework/Headers") |
| 16 | +} |
| 17 | +let cRNDepHeaderSearchPath: (Int) -> CSetting = { |
| 18 | + let prefix = (0..<$0).map { _ in "../" } .joined(separator: "") |
| 19 | + return .headerSearchPath("\(prefix)third-party/ReactNativeDependencies.xcframework/Headers") |
| 20 | +} |
| 21 | + |
| 22 | + |
| 23 | +let package = Package( |
| 24 | + name: react, |
| 25 | + products: [ |
| 26 | + .library( |
| 27 | + name: react, |
| 28 | + type: .dynamic, |
| 29 | + targets: [.reactDebug, .jsi, .logger, .mapbuffer] |
| 30 | + ), |
| 31 | + ], |
| 32 | + targets: [ |
| 33 | + .reactNativeTarget( |
| 34 | + name: .reactDebug, |
| 35 | + dependencies: [.reactNativeDependencies], |
| 36 | + path: "ReactCommon/react/debug", |
| 37 | + publicHeadersPath: "." |
| 38 | + ), |
| 39 | + .reactNativeTarget( |
| 40 | + name: .jsi, |
| 41 | + dependencies: [.reactNativeDependencies], |
| 42 | + path: "ReactCommon/jsi", |
| 43 | + extraExcludes: ["jsi/CMakeLists.txt", "jsi/test/testlib.h", "jsi/test/testlib.cpp"], |
| 44 | + sources: ["jsi"], |
| 45 | + publicHeadersPath: "jsi/", |
| 46 | + extraCSettings: [.headerSearchPath(".")], |
| 47 | + extraCxxSettings: [.headerSearchPath(".")] |
| 48 | + ), |
| 49 | + .reactNativeTarget( |
| 50 | + name: .logger, |
| 51 | + dependencies: [.reactNativeDependencies, .jsi], |
| 52 | + path: "ReactCommon/logger", |
| 53 | + publicHeadersPath: "." |
| 54 | + ), |
| 55 | + .reactNativeTarget( |
| 56 | + name: .mapbuffer, |
| 57 | + dependencies: [.reactNativeDependencies, .reactDebug], |
| 58 | + path: "ReactCommon/react/renderer/mapbuffer", |
| 59 | + extraExcludes: ["tests/MapBufferTest.cpp"], |
| 60 | + publicHeadersPath: ".", |
| 61 | + extraCSettings: [.headerSearchPath("../../..")], |
| 62 | + extraCxxSettings: [.headerSearchPath("../../..")] |
| 63 | + ), |
| 64 | + .binaryTarget( |
| 65 | + name: .reactNativeDependencies, |
| 66 | + path: "third-party/ReactNativeDependencies.xcframework" |
| 67 | + ), |
| 68 | + ] |
| 69 | +) |
| 70 | + |
| 71 | +extension String { |
| 72 | + static let reactDebug = "React-debug" |
| 73 | + static let jsi = "React-jsi" |
| 74 | + static let logger = "React-logger" |
| 75 | + static let mapbuffer = "React-Mapbuffer" |
| 76 | + |
| 77 | + static let reactNativeDependencies = "ReactNativeDependencies" |
| 78 | +} |
| 79 | + |
| 80 | +func defaultExcludeFor(module: String) -> [String] { |
| 81 | + return ["BUCK", "CMakeLists.txt", "\(module).podspec"] |
| 82 | +} |
| 83 | + |
| 84 | +extension Target { |
| 85 | + static func reactNativeTarget( |
| 86 | + name: String, |
| 87 | + dependencies: [String], |
| 88 | + path: String, |
| 89 | + extraExcludes: [String] = [], |
| 90 | + sources: [String]? = nil, |
| 91 | + publicHeadersPath: String? = nil, |
| 92 | + extraCSettings: [CSetting] = [], |
| 93 | + extraCxxSettings: [CXXSetting] = [] |
| 94 | + ) -> Target { |
| 95 | + let dependencies = dependencies.map { Dependency.byNameItem(name: $0, condition: nil) } |
| 96 | + let excludes = defaultExcludeFor(module: .logger) + extraExcludes |
| 97 | + let numOfSlash = path.count { $0 == "/"} |
| 98 | + let cSettings = [cRNDepHeaderSearchPath(numOfSlash + 1)] + extraCSettings |
| 99 | + let cxxSettings = [cxxRNDepHeaderSearchPath(numOfSlash + 1), .unsafeFlags(["-std=c++20"])] + extraCxxSettings |
| 100 | + |
| 101 | + return .target( |
| 102 | + name: name, |
| 103 | + dependencies: dependencies, |
| 104 | + path: path, |
| 105 | + exclude: excludes, |
| 106 | + sources: sources, |
| 107 | + publicHeadersPath: publicHeadersPath, |
| 108 | + cSettings: cSettings, |
| 109 | + cxxSettings: cxxSettings |
| 110 | + ) |
| 111 | + } |
| 112 | +} |
0 commit comments