Possible to distribute the same module from source & binary in the same package?


historically I provided a module from source through SPM. I was asked to provide a pre-compiled version of that module to speed up consumer's build time. I am able to build a xcframework with custom tooling. I was thinking to distribute the binary framework from the same Package with a binaryTarget.

I'd like to let app developers choose the library produce (AwesomeModuleFromSource vs AwesomeModuleFromBinary) but let them use the same module name

import AwesomeModule

I imagined creating such a package manifest.

// swift-tools-version:5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "AwesomePackage",
    defaultLocalization: "en",
    products: [
            name: "AwesomeModuleFromSource",
            targets: ["AwesomeModule"]
            name: "ModuleFromBinary",
            targets: ["AwesomeModuleBinary"]
    dependencies: [],
    targets: [
        .binaryTarget(name: "AwesomeModuleBinary",
                      url: "xxx",
                      checksum: "xxx"
            name: "AwesomeModule",
            dependencies: []

However, SPM complains that the downloaded archive of binary target does not contain expected binary artifact named because the module name is AwesomeModule. Changing the .target name would lead to a different module name when used from source :frowning:

Is it possible to provide the same module from source and through a binaryTarget from the same package? How can I do that?

No, you would need a second package to do that. The expectation is that the target name in the manifest has to align with the module name of the binary provided and that target names are unique.

Thank you, @NeoNacho, for the clarification.