PaGr0m / kotlin-spm-plugin

Gradle plugin for integration Kotlin with Swift package dependencies
MIT License
48 stars 5 forks source link

Properties are missing input or output annotations #3

Open luca992 opened 2 years ago

luca992 commented 2 years ago

I can't get gradle to build after adding a spm dependency:

    spm {
        macos("11") {
            dependencies {
                `package`(
                    url = "https://github.com/AFNetworking/AFNetworking.git",
                    version = "4.0.0",
                    name = "AFNetworking"
                )
            }
        }
    }

I'm using kotlin 1.6.21

> Task :shared:initializeSwiftPackageProjectOSX FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings
1 actionable task: 1 executed

FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':shared:initializeSwiftPackageProjectOSX' (type 'InitializeSwiftPackageProjectTask').
  - In plugin 'com.github.pagr0m.kotlin.native.spm.plugin.KotlinSpmPlugin$Inject' type 'com.github.pagr0m.kotlin.native.spm.tasks.InitializeSwiftPackageProjectTask' property 'platformFamily.appleFamily' is missing an input or output annotation.

    Reason: A property without annotation isn't considered during up-to-date checking.

    Possible solutions:
      1. Add an input or output annotation.
      2. Mark it as @Internal.

    Please refer to https://docs.gradle.org/7.4.2/userguide/validation_problems.html#missing_annotation for more details about this problem.
  - In plugin 'com.github.pagr0m.kotlin.native.spm.plugin.KotlinSpmPlugin$Inject' type 'com.github.pagr0m.kotlin.native.spm.tasks.InitializeSwiftPackageProjectTask' property 'platformFamily.dynamicPrefix' is missing an input or output annotation.

    Reason: A property without annotation isn't considered during up-to-date checking.

    Possible solutions:
      1. Add an input or output annotation.
      2. Mark it as @Internal.

    Please refer to https://docs.gradle.org/7.4.2/userguide/validation_problems.html#missing_annotation for more details about this problem.
  - In plugin 'com.github.pagr0m.kotlin.native.spm.plugin.KotlinSpmPlugin$Inject' type 'com.github.pagr0m.kotlin.native.spm.tasks.InitializeSwiftPackageProjectTask' property 'platformFamily.dynamicSuffix' is missing an input or output annotation.

    Reason: A property without annotation isn't considered during up-to-date checking.

    Possible solutions:
      1. Add an input or output annotation.
      2. Mark it as @Internal.

    Please refer to https://docs.gradle.org/7.4.2/userguide/validation_problems.html#missing_annotation for more details about this problem.
  - In plugin 'com.github.pagr0m.kotlin.native.spm.plugin.KotlinSpmPlugin$Inject' type 'com.github.pagr0m.kotlin.native.spm.tasks.InitializeSwiftPackageProjectTask' property 'platformFamily.exeSuffix' is missing an input or output annotation.

    Reason: A property without annotation isn't considered during up-to-date checking.

    Possible solutions:
      1. Add an input or output annotation.
      2. Mark it as @Internal.

    Please refer to https://docs.gradle.org/7.4.2/userguide/validation_problems.html#missing_annotation for more details about this problem.
  - In plugin 'com.github.pagr0m.kotlin.native.spm.plugin.KotlinSpmPlugin$Inject' type 'com.github.pagr0m.kotlin.native.spm.tasks.InitializeSwiftPackageProjectTask' property 'platformFamily.staticPrefix' is missing an input or output annotation.

    Reason: A property without annotation isn't considered during up-to-date checking.

    Possible solutions:
      1. Add an input or output annotation.
      2. Mark it as @Internal.

    Please refer to https://docs.gradle.org/7.4.2/userguide/validation_problems.html#missing_annotation for more details about this problem.
twyatt commented 1 year ago

Unfortunately it doesn't appear that this project is maintained anymore.

I tried the https://github.com/doublesymmetry/kotlin-spm-plugin fork, which fixes the annotation issues, but then fails during temporary Xcode project creation:

https://github.com/doublesymmetry/kotlin-spm-plugin/blob/b0fe2867568d182daff17a72cec757c236ffacf0/plugin-build/plugin/src/main/java/com/doublesymmetry/kotlin/native/spm/tasks/GenerateXcodeTask.kt#L37-L38

The generate-xcodeproj option for the swift tool has long been deprecated and removed.

I attempted to switch to using xcodegen to produce a temporary project (for building a temporary framework for the cinterop) but could not get headers from the output framework.

I imagine it would take quite a bit of work to get this project in working order again. 😢

markst commented 2 months ago

@twyatt I'd be interested to try and take this on. I think it may be achievable using swift build.

However may be blocked when building libraries which depend on Obj-C. For instance if I try to import AVFoundation:

swift build -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator"

#import <AVFoundation/AVDisplayCriteria.h>
        ^
<unknown>:0: error: could not build Objective-C module 'AVFoundation'
error: fatalError

https://forums.swift.org/t/swiftpm-swift-build-for-ios/42517/4

Building without import works fine:

swift build -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator"

Building for debugging...
<unknown>:0: warning: using sysroot for 'MacOSX' but targeting 'iPhone'
<unknown>:0: warning: using sysroot for 'MacOSX' but targeting 'iPhone'
[6/6] Archiving libRadioPlayerLocal.a
Build complete! (0.43s)
markst commented 2 months ago

https://youtrack.jetbrains.com/issue/KT-53877/Support-Swift-Package-Manager-in-Kotlin-Multiplatform

Comment on the Jetbrains issue could be relevant.

I need to investigate using Gradle plugin to build swift Package.swft.

https://docs.gradle.org/current/userguide/building_swift_projects.html https://docs.gradle.org/current/userguide/swift_library_plugin.html#swift_library_plugin

markst commented 2 months ago

mmm perhaps not possible with Gradle plugin, seems iOS not available:

image
markst commented 2 months ago

Using the following command I can build my Package.swift directly which produces output binary.

xcodebuild build -scheme RadioPlayerLocal -sdk "`xcrun --sdk iphonesimulator --show-sdk-path`" -destination "OS=17.1,name=iPhone 13 Pro"  

https://github.com/openbakery/gradle-xcodePlugin

https://stackoverflow.com/questions/60245159/how-can-i-build-a-swift-package-for-ios-over-command-line

markst commented 2 months ago

xcodebuild build produces a Mach-O object .o file rather than a framework/static library.

possibly need to take steps like this in order to produce a packaged XCFramework: https://mustafa-ysf.medium.com/creating-xcframework-from-swift-package-e8af6f44501f

Also a helper here I've yet to try: https://github.com/mstfy/spm-to-xcframework