How to distribute macros as a binary xcframework?

I'm trying to make an xcframework from my static library (SPM btw) with macros. My script doesn't work properly

My SPM declaration of macros:

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

import CompilerPluginSupport
import PackageDescription

let package = Package(
    name: "SomeMacr",
    platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .macCatalyst(.v13)],
    products: [
        .library(
            name: "SomeMacr",
            targets: ["SomeMacr"]
        ),
        .executable(
            name: "SomeMacrClient",
            targets: ["SomeMacrClient"]
        )
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0")
    ],
    targets: [
        .macro(
            name: "SomeMacrMacros",
            dependencies: [
                .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
                .product(name: "SwiftCompilerPlugin", package: "swift-syntax")
            ]
        ),

        .target(name: "SomeMacr", dependencies: ["SomeMacrMacros"]),

        .executableTarget(name: "SomeMacrClient", dependencies: ["SomeMacr"]),
 
        .testTarget(
            name: "SomeMacrTests",
            dependencies: [
                "SomeMacrMacros",
                .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax")
            ]
        )
    ]
)

My .sh script:

  xcodebuild archive \
    -scheme SomeMacr \
    -sdk iphoneos \
    -archivePath "Products/archives/ios_devices.xcarchive" \
    SKIP_INSTALL=NO \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES

  xcodebuild archive \
    -scheme SomeMacr \
    -sdk iphonesimulator \
    -archivePath "Products/archives/ios_simulators.xcarchive" \
    SKIP_INSTALL=NO \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES

  xcodebuild archive \
    -scheme SomeMacr \
    -sdk macosx \
    -archivePath "Products/archives/macos.xcarchive" \
    SKIP_INSTALL=NO \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES

  xcodebuild -create-xcframework \
    -library Products/archives/ios_devices.xcarchive/Products/Library/Frameworks/libSomeMacr.a \ 
    -library Products/archives/ios_simulators.xcarchive/Products/Library/Frameworks/libSomeMacr.a \
    -library Products/archives/macos.xcarchive/Products/Library/Frameworks/lib$1.a \
    -output Products/xc/SomeMacr.xcframework

It requires destination (But in other tutorials, authors clearly shows, that after this script I will get an xcframework)

xcodebuild: error: Building a Swift package requires that a destination is provided using the "-destination" option. The "-showdestinations" option can be used to list the available destinations

But when I setup the destination it was compiled to exec file, which I don't mind how to include to another SPM package / or xcframework

What am I doing wrong?

1 Like