// 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.
 */

// AUTO-GENERATED by scripts/setup-apple-spm.js – do not edit manually.
// This SPM-specific template replaces the CocoaPods codegen template
// with xcframework configuration built in.

import PackageDescription

// React headers need NO search paths: the React module comes from the
// invariant ReactHeaders Clang target,
// every other RN namespace from the ReactNativeHeaders binaryTarget
// (pure-RN), the third-party deps namespaces (folly/glog/boost/...) from the
// ReactNativeDependenciesHeaders sidecar, and the per-app generated headers
// from the ReactAppHeaders target below — all auto-served by SPM through
// product/target dependencies.
let headersDep: [Target.Dependency] = [
    .product(name: "ReactHeaders", package: "ReactNative"),
    .product(name: "ReactNativeHeaders", package: "ReactNative"),
    .product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"),
    "ReactAppHeaders",
]

let package = Package(
    name: "React-GeneratedCode",
    platforms: [.iOS(.v15), .macCatalyst(SupportedPlatform.MacCatalystVersion.v13)],
    products: [
        .library(
            name: "ReactCodegen",
            targets: ["ReactCodegen"]),
        .library(
            name: "ReactAppDependencyProvider",
            targets: ["ReactAppDependencyProvider"]),
        .library(
            name: "ReactAppHeaders",
            targets: ["ReactAppHeaders"]),
    ],
    dependencies: [
        .package(name: "ReactNative", path: "../../xcframeworks"),
    ],
    targets: [
        .target(
            name: "ReactCodegen",
            dependencies: headersDep,
            path: "ReactCodegen",
            exclude: ["ReactCodegen.podspec"],
            publicHeadersPath: ".",
            cSettings: [.headerSearchPath("headers")],
            // DEBUG/NDEBUG match the prebuilt React.framework's config-gated C++
            // ABI: NDEBUG (Release) strips DebugStringConvertible's vtable and
            // shifts the ShadowNode layout that codegen'd Props inherit, so this
            // target must compile with the same NDEBUG state or the Release link
            // fails (undefined "vtable for DebugStringConvertible"). Mirrors
            // packages/react-native/Package.swift.
            cxxSettings: [
                .headerSearchPath("headers"),
                .define("DEBUG", .when(configuration: .debug)),
                .define("NDEBUG", .when(configuration: .release)),
            ],
            linkerSettings: [
                .linkedFramework("Foundation")
            ]
        ),
        .target(
            name: "ReactAppDependencyProvider",
            dependencies: ["ReactCodegen"] + headersDep,
            path: "ReactAppDependencyProvider",
            exclude: ["ReactAppDependencyProvider.podspec"],
            publicHeadersPath: ".",
            cSettings: [.headerSearchPath(".."), .headerSearchPath("headers")],
            cxxSettings: [
                .headerSearchPath(".."),
                .headerSearchPath("headers"),
                // Match the prebuilt React.framework NDEBUG-gated C++ ABI (see above).
                .define("DEBUG", .when(configuration: .debug)),
                .define("NDEBUG", .when(configuration: .release)),
            ],
            linkerSettings: [
                .linkedFramework("Foundation")
            ]
        ),
        // The per-app generated-headers farm (built by spm sync), vended as a
        // normal SPM headers target.
        .target(
            name: "ReactAppHeaders",
            path: "ReactAppHeaders",
            publicHeadersPath: "."
        ),
    ],
    // React Native headers require C++20 (concepts, std::optional, etc.)
    cxxLanguageStandard: .cxx20
)
