Binary Frameworks with SwiftPM

@paulb777 Here's the best I could come up with so far:

// swift-tools-version:5.3

import PackageDescription
import Foundation

let simDir = "${PROJECT_DIR}/lib/SwiftProtobuf.xcframework/ios-arm64_i386_x86_64-simulator/"
let realDir = "${PROJECT_DIR}/lib/SwiftProtobuf.xcframework/ios-arm64_armv7/"
let dir: String
  
#if targetEnvironment(simulator)

dir = simDir // problem is, this never runs

#elseif !targetEnvironment(simulator)

dir = realDir // ... & this always runs, 
              // even when compiling for simulator
#endif

let package = Package(
    name: "REDACTED",
    platforms: [
        .iOS(.v13),
    ],
    products: [
        .library(
            name: "REDACTED",
            type: .dynamic,
            targets: ["REDACTED"]
        ),
    ],
    dependencies: [],
    targets: [
        .target(
            name: "REDACTED"
            ,swiftSettings: [
                .unsafeFlags([
                    "-Fsystem", dir,
                ]),
            ]
            ,linkerSettings: [
                .linkedFramework("SwiftProtobuf"),
                .unsafeFlags([
                    "-Xlinker", "-rpath", "-Xlinker", dir,
                    "-Xlinker", "-F", "-Xlinker", dir,
                ])
            ]
        ),
    ]
)

(credit for the above settings pattern goes to Apple, see this git repo for reference)

Problem is, #if targetEnvironment(simulator) simply doesn't work in Package.swift.

Can anyone think of a way to get this to work? Since I've already tried everything else, it would really be nice if someone can think of a way. Or better yet, a way to supply the .xcframework itself to the unsafe flags?

(I would just supply the .xcframework itself to the linkedFrameworks(..) function, but ironically, that function only seems to work with regular .frameworks. So we have to link the simulator or device framework from inside the xcframework, but I'm not sure how to get this working without targetEnvironment(simulator) working.

Is there really no way to do the equivalent of .when with simulator platform vs. real?