// swift-tools-version:5.9
// Local-development manifest. swift/scripts/check.sh builds a single-slice
// MoqFFI.xcframework next to this file so the path-based binaryTarget below
// resolves locally without a network fetch.
//
// The released form (URL + checksum) is generated by swift/scripts/package.sh
// from Package.swift.template at release time. Edit the template, not this
// file, when changing the released manifest.

import PackageDescription

let package = Package(
    name: "Moq",
    platforms: [.iOS(.v15), .macOS("12.3")],
    products: [.library(name: "Moq", targets: ["Moq"])],
    targets: [
        .target(name: "Moq", dependencies: ["MoqFFI"], path: "Sources/Moq"),
        .target(
            name: "MoqFFI",
            dependencies: ["MoqFFIBinary"],
            path: "Sources/MoqFFI",
            linkerSettings: [
                // A Rust staticlib does not carry the link options its dependencies
                // declare, so an external linker has to name them. Mirrors
                // rs/libmoq/native-libs/apple.txt, which solves the same problem for
                // C consumers of libmoq. These cover moq-video / moq-audio: hardware
                // H.264/H.265 encode and decode, plus capture. All macOS-only, since
                // those backends are `cfg(target_os = "macos")`.
                .linkedFramework("AVFoundation", .when(platforms: [.macOS])),
                .linkedFramework("CoreGraphics", .when(platforms: [.macOS])),
                .linkedFramework("CoreMedia", .when(platforms: [.macOS])),
                .linkedFramework("CoreVideo", .when(platforms: [.macOS])),
                // ScreenCaptureKit is why the macOS floor is 12.3 rather than 12:
                // it does not exist before then, and a strong link makes the app
                // fail to load on 12.0-12.2 even when it never captures a screen.
                // SwiftPM can only weak-link via `unsafeFlags`, which would stop
                // this package being usable as a versioned dependency.
                .linkedFramework("ScreenCaptureKit", .when(platforms: [.macOS])),
                .linkedFramework("VideoToolbox", .when(platforms: [.macOS])),
                // openh264, the software H.264 fallback, is C++.
                .linkedLibrary("c++"),
            ]
        ),
        .binaryTarget(name: "MoqFFIBinary", path: "MoqFFI.xcframework"),
        .testTarget(name: "MoqTests", dependencies: ["Moq"], path: "Tests/MoqTests"),
    ]
)
