SPM to XCFrameworks and distribution by Pods Error with Swift Version

Hello, in our project we transform SPM to a XCFramework because we also distribute it in pods. We had a lot of problems with the script from SPM to Pods, but finally we got one that worked.

We used to had the problem of Swift Version compatibility problems

Failed to build module 'selphid_component'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)', while this compiler is 'Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)'). Please select a toolchain which matches the SDK.

But we added BUILD_LIBRARY_FOR_DISTRIBUTION=YES and it worked. But right now this problem is happening again. And you only find that the solution is to add that to the Xcode command.

We did a lot of research but we can't find what we are doing wrong with this. Are we missing something in the script? Or we are adding things that are wrong.

As a curiosity, in the podfile with our libraries we use:

post_install do |installer|  installer.pods_project.targets.each do |target|   target.build_configurations.each do |config|    config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'    end   end end

but it doesn't work too

Maybe the problem is SPM to pod but I saw a lot of projects that they do this but they don't have this problem. We compile with GitHub actions, macos-11, macOS-latest, and even with our Mac, but we are having that compatibility problem. This is the script we use for building from SPM to xcframework. (the part after the archive is because we added the bundle to the xcframework). Thank you for your support and your time, have a good day.


for PLATFORM in "iOS" "iOS Simulator"; do

    case $PLATFORM in
    "iOS")
    RELEASE_ARCH="Release-iphoneos"
    ARCHS=$ARCH_IPHONE
    ;;
    "iOS Simulator")
    RELEASE_ARCH="Release-iphonesimulator"
    ARCHS=$ARCH_SIMULATOR
    ;;
    esac

    ARCHIVE_PATH=$BUILD_DIR/$RELEASE_ARCH
    xcodebuild archive -workspace $PROJECT_DIR -scheme $TARGET \
            -destination "generic/platform=$PLATFORM" \
            -archivePath $ARCHIVE_PATH \
            -derivedDataPath $BUILD_DIR \
            ARCHS="$ARCHS" \
            SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES

    FRAMEWORK_PATH="$ARCHIVE_PATH.xcarchive/Products/usr/local/lib/$TARGET.framework"
    MODULES_PATH="$FRAMEWORK_PATH/Modules"
    mkdir -p $MODULES_PATH

    BUILD_PRODUCTS_PATH="$BUILD_DIR/Build/Intermediates.noindex/ArchiveIntermediates/$TARGET/BuildProductsPath"
    RELEASE_PATH="$BUILD_PRODUCTS_PATH/$RELEASE_ARCH"
    SWIFT_MODULE_PATH="$RELEASE_PATH/$TARGET.swiftmodule"
    RESOURCES_BUNDLE_PATH="$RELEASE_PATH/${TARGET}_${TARGET}.bundle"

    # Copy Swift modules
    if [ -d $SWIFT_MODULE_PATH ]
    then
        cp -r $SWIFT_MODULE_PATH $MODULES_PATH
    else
        # In case there are no modules, assume C/ObjC library and create module map
        echo "module $TARGET { export * }" > $MODULES_PATH/module.modulemap
        perl -lne 'print $1 if /\<'${TARGET}'\/(\S+.h)/' $TARGET/$TARGET    .h | \
        xargs -I {} find . -name "{}" -print | \
        xargs -I {} cp {} $HEADERS_PATH/.
        cp $TARGET/$TARGET.h $HEADERS_PATH/.
    fi
        


    # Copy resources bundle, if exists
    if [ -e $RESOURCES_BUNDLE_PATH ]
    then
        cp -r $RESOURCES_BUNDLE_PATH $FRAMEWORK_PATH
    fi

done

}

We create the archive, and finally the xcframework.

     -framework Release-iphoneos.xcarchive/Products/usr/local/lib/$TARGET.framework \
     -framework Release-iphonesimulator.xcarchive/Products/usr/local/lib/$TARGET.framework \
     -allow-internal-distribution -output $TARGET.xcframework