Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build JSI, React-Debug and React-logger with SPM #50075

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions packages/react-native/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// swift-tools-version: 6.0
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import PackageDescription

let react = "React"

let cxxRNDepHeaderSearchPath: (Int) -> CXXSetting = {
let prefix = (0..<$0).map { _ in "../" } .joined(separator: "")
return .headerSearchPath("\(prefix)third-party/ReactNativeDependencies.xcframework/Headers")
}
let cRNDepHeaderSearchPath: (Int) -> CSetting = {
let prefix = (0..<$0).map { _ in "../" } .joined(separator: "")
return .headerSearchPath("\(prefix)third-party/ReactNativeDependencies.xcframework/Headers")
}

let package = Package(
name: react,
products: [
.library(
name: react,
type: .dynamic,
targets: [.reactDebug, .jsi, .logger, .mapbuffer]
),
],
targets: [
.reactNativeTarget(
name: .reactDebug,
dependencies: [.reactNativeDependencies],
path: "ReactCommon/react/debug",
publicHeadersPath: "."
),
.reactNativeTarget(
name: .jsi,
dependencies: [.reactNativeDependencies],
path: "ReactCommon/jsi",
extraExcludes: ["jsi/CMakeLists.txt", "jsi/test/testlib.h", "jsi/test/testlib.cpp"],
sources: ["jsi"],
publicHeadersPath: "jsi/",
extraCSettings: [.headerSearchPath(".")],
extraCxxSettings: [.headerSearchPath(".")]
),
.reactNativeTarget(
name: .logger,
dependencies: [.reactNativeDependencies, .jsi],
path: "ReactCommon/logger",
publicHeadersPath: "."
),
.reactNativeTarget(
name: .mapbuffer,
dependencies: [.reactNativeDependencies, .reactDebug],
path: "ReactCommon/react/renderer/mapbuffer",
extraExcludes: ["tests/MapBufferTest.cpp"],
publicHeadersPath: ".",
extraCSettings: [.headerSearchPath("../../..")],
extraCxxSettings: [.headerSearchPath("../../..")]
),
.binaryTarget(
name: .reactNativeDependencies,
path: "third-party/ReactNativeDependencies.xcframework"
),
]
)

extension String {
static let reactDebug = "React-debug"
static let jsi = "React-jsi"
static let logger = "React-logger"
static let mapbuffer = "React-Mapbuffer"

static let reactNativeDependencies = "ReactNativeDependencies"
}

func defaultExcludeFor(module: String) -> [String] {
return ["BUCK", "CMakeLists.txt", "\(module).podspec"]
}

extension Target {
static func reactNativeTarget(
name: String,
dependencies: [String],
path: String,
extraExcludes: [String] = [],
sources: [String]? = nil,
publicHeadersPath: String? = nil,
extraCSettings: [CSetting] = [],
extraCxxSettings: [CXXSetting] = []
) -> Target {
let dependencies = dependencies.map { Dependency.byNameItem(name: $0, condition: nil) }
let excludes = defaultExcludeFor(module: .logger) + extraExcludes
let numOfSlash = path.count { $0 == "/" }
let cSettings = [cRNDepHeaderSearchPath(numOfSlash + 1)] + extraCSettings
let cxxSettings = [cxxRNDepHeaderSearchPath(numOfSlash + 1), .unsafeFlags(["-std=c++20"])] + extraCxxSettings

return .target(
name: name,
dependencies: dependencies,
path: path,
exclude: excludes,
sources: sources,
publicHeadersPath: publicHeadersPath,
cSettings: cSettings,
cxxSettings: cxxSettings
)
}
}
Loading