Strumenta / antlr-kotlin

Support for Kotlin as a target for ANTLR 4
Apache License 2.0
229 stars 47 forks source link

antlr-kotlin-runtime broken with an iOS target container #71

Closed mruth1022 closed 10 months ago

mruth1022 commented 3 years ago

Context

I'm using antlr-kotlin on a KMM project, targeting android and ios containers.

Problem

The dependency on antlr-kotlin-runtime can no longer be resolved with an iOS target when using jitpack release version 6304d5c1c4. This was working previously (yesterday, on 11/1/21), which leads me to believe the jitpack project (https://jitpack.io/#com.strumenta/antlr-kotlin) was updated and a regression was introduced. Coinciding with this theory, a new release version has been added to the jitpack project: ad1c6fe979, which also doesn't work with an iOS target. Any other jitpack releases also fail due to this error or other errors.

Resources

Here are the 2 error messages when trying to build the gradle project:

Could not find com.strumenta.antlr-kotlin:antlr-kotlin-runtime-iosx64:6304d5c1c4.
Searched in the following locations:
  - https://dl.google.com/dl/android/maven2/com/strumenta/antlr-kotlin/antlr-kotlin-runtime-iosx64/6304d5c1c4/antlr-kotlin-runtime-iosx64-6304d5c1c4.pom
  - https://repo.maven.apache.org/maven2/com/strumenta/antlr-kotlin/antlr-kotlin-runtime-iosx64/6304d5c1c4/antlr-kotlin-runtime-iosx64-6304d5c1c4.pom
  - https://jitpack.io/com/strumenta/antlr-kotlin/antlr-kotlin-runtime-iosx64/6304d5c1c4/antlr-kotlin-runtime-iosx64-6304d5c1c4.pom
Required by:
    project : > com.strumenta.antlr-kotlin:antlr-kotlin-runtime:6304d5c1c4

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

and

Could not find com.strumenta.antlr-kotlin:antlr-kotlin-runtime-iosarm64:6304d5c1c4.
Searched in the following locations:
  - https://dl.google.com/dl/android/maven2/com/strumenta/antlr-kotlin/antlr-kotlin-runtime-iosarm64/6304d5c1c4/antlr-kotlin-runtime-iosarm64-6304d5c1c4.pom
  - https://repo.maven.apache.org/maven2/com/strumenta/antlr-kotlin/antlr-kotlin-runtime-iosarm64/6304d5c1c4/antlr-kotlin-runtime-iosarm64-6304d5c1c4.pom
  - https://jitpack.io/com/strumenta/antlr-kotlin/antlr-kotlin-runtime-iosarm64/6304d5c1c4/antlr-kotlin-runtime-iosarm64-6304d5c1c4.pom
Required by:
    project : > com.strumenta.antlr-kotlin:antlr-kotlin-runtime:6304d5c1c4

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

Here is my root build.gradle.kts:

group = "com.example.examplelib"
version = 1.0

plugins {
    kotlin("multiplatform") version "1.6.0-RC"
    id("com.android.library")
    id("kotlin-android-extensions")
}

buildscript {
    repositories {
        mavenCentral()
        maven(url="https://jitpack.io")
    }

    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.strumenta.antlr-kotlin:antlr-kotlin-gradle-plugin:6304d5c1c4")
    }
}

repositories {
    google()
    mavenCentral()
    // used to download antlr-kotlin-runtime
    maven(url = "https://jitpack.io")
}

kotlin {
    android()
    ios("ios") {
        binaries {
            framework {
                baseName = "examplelib"
            }
        }
    }
    sourceSets {
        val commonAntlr by creating {
            repositories {
                mavenCentral()
                maven(url="https://jitpack.io")
            }

            dependencies {
                api(kotlin("stdlib-common"))
                // add antlr-kotlin-runtime
                // otherwise, the generated sources will not compile
                api("com.strumenta.antlr-kotlin:antlr-kotlin-runtime:6304d5c1c4")
                // antlr-kotlin-runtime-jvm is automatically added as an jvm dependency by gradle
            }
        }
        val commonMain by getting {
            dependsOn(commonAntlr)
        }
        val commonTest by getting
        val androidMain by getting
        val androidTest by getting
        val iosMain by getting
        val iosTest by getting
    }
}

android {
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    compileSdkVersion(30)
    defaultConfig {
        minSdkVersion(24)
        targetSdkVersion(30)
    }
}

tasks.wrapper {
    gradleVersion = "6.9"
    distributionType = Wrapper.DistributionType.BIN
}

// in antlr-kotlin-plugin <0.0.5, the configuration was applied by the plugin.
// starting from verison 0.0.5, you have to apply it manually:
tasks.register<com.strumenta.antlrkotlin.gradleplugin.AntlrKotlinTask>("generateKotlinCommonGrammarSource") {
    // the classpath used to run antlr code generation
    antlrClasspath = configurations.detachedConfiguration(
        // antlr itself
        // antlr is transitive added by antlr-kotlin-target,
        // add another dependency if you want to choose another antlr4 version (not recommended)
        // project.dependencies.create("org.antlr:antlr4:$antlrVersion"),

        // antlr target, required to create kotlin code
        project.dependencies.create("com.strumenta.antlr-kotlin:antlr-kotlin-target:6304d5c1c4")
    )
    maxHeapSize = "64m"
    packageName = "com.example.examplelib.antlr.generated"
    arguments = listOf("-no-visitor") // Can use `-no-listener` if we don't want listeners generated
    source = project.objects
        .sourceDirectorySet("antlr", "antlr")
        .srcDir("src/commonAntlr/antlr/grammar").apply {
            include("*.g4")
        }
    // outputDirectory is required, put it into the build directory
    // if you do not want to add the generated sources to version control
    // outputDirectory = File("build/generated-src/commonAntlr/kotlin")
    // use this settings if you want to add the generated sources to version control
     outputDirectory = File("src/commonAntlr/kotlin")
}

Next Steps

Please advise on what changed between 11/1/21 and 11/2/21 which may have caused this regression, and/or what actions we can take to again allow support for an iOS target, as this is blocking my progress toward a KMM library providing necessary functionality to my project.

mistralaix commented 1 year ago

Hello @mruth1022, have you found a solution regarding this problem?

mistralaix commented 1 year ago

Hello @frett , after exploring the source code, I saw that most of the expect/actual implementation are not done for iosArm64Main, iosSimulatorArm64Main and iosX64Main. Maybe that could explain the problem. Do you have an implementation for these parts?

lppedd commented 11 months ago

@mistralaix the support is now complete for all Native platforms.

ftomassetti commented 10 months ago

Solved, as we now publish all Apple targets (thank you @lppedd )