How to use a local .xcFramework as a Resource of a Swift Package

I asked this question here incorrectly:
https://developer.apple.com/forums/thread/651187?page=1#615966022

What I am actually trying to do is use a local .xcFramework as a Resource inside of a Swift Package without having to distribute it with the package..?

Am I supposed to create a binaryTarget as a dependency instead of it being a resource?


Im getting the error: "No such module 'SampleFramework' "

Example:

Say that my SampleFramework has a dependency on sample.xcFramework, how can I add it as a resource to use it in sample.swift

Source
Code Block language
// Sample.swift
// MARK: Import the local xcFramework inside of my package
import SampleFramework
struct Model {
var something: SampleFramework.something
}

Package file
Code Block swift
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
    name: "SamplePackage",
    platforms: [
        .iOS(.v13)
],
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "SamplePackage",
            targets: ["SamplePackage"]),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "SamplePackage",
            resources: [
                .process("SampleFramework.xcframework")
// I have also tried .copy()
            ]),
        .testTarget(
            name: "SamplePackageTests",
            dependencies: ["SamplePackage"])
    ]
)


Structure:
| SamplePackage
| - | Package.swift
| - | README.swift
| - | Sources
| - | - | SamplePackage
| - | - | - | sample.swift
| - | - | - | SampleFramework.xcframework
| - | - | Tests
| - | - | - | LinuxMain.swift
| - | - | - | SampleTexts
| - | - | - | - | sampleTests.swift


Answered by Developer Tools Engineer in 615890022
I think this could be the same issue we are seeing in https://developer.apple.com/forums/thread/651069
Yah, you need to create a binaryTarget for the XCFramework. Declaring it as a resource will essentially just copy the XCFramework as a resource since there is no processing rule for it.
Ok, so doing so, I'm able to distribute the binaryTarget, I can now find it in the source file but im not able to use anything from the framework

Its saying "Cannot find type "Something" in scope

Code Block swift
// This file is in the Sources/SamplePackage/Sample.swift
import SampleFramework
// ^^ Was giving Error Module not found: Resolved
struct Model {
var something: Something // Something is a model in the SampleFramework.xcFramework
// ERROR: Cannot find type "Something" in scope
}


Code Block swift
import PackageDescription
let package = Package(
    name: "SamplePackage",
    platforms: [
        .iOS(.v13),
        .macOS(.v10_14)
    ],
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "SamplePackage",
            targets: ["SamplePackage", "SampleXCFramework"]),
    ],
        targets: [
            // Targets are the basic building blocks of a package. A target can define a module or a test suite.
            // Targets can depend on other targets in this package, and on products in packages which this package depends on.
            .target(
                name: "SamplePackage",
                dependencies: [
                    "SampleXCFramework"
                ]),
            .testTarget(
                name: "SamplePackageTests",
                dependencies: ["SamplePackage"]),
            .binaryTarget(
                name: "SampleXCFramework",
                path: "SampleFramework.xcframework")
        ]
)




Accepted Answer
I think this could be the same issue we are seeing in https://developer.apple.com/forums/thread/651069
How to use a local .xcFramework as a Resource of a Swift Package
 
 
Q