plugins {
  id 'net.consensys.zkevm.kotlin-common-minimal-conventions'
  id 'net.consensys.zkevm.linea-native-libs-helper'
  id 'java-test-fixtures'
}

description = 'Java JNA wrapper for Linea Blob Decompressor Library implemented in GO Lang'

dependencies {
  compileOnly "net.java.dev.jna:jna:${libs.versions.jna.get()}"
  compileOnly project(":jvm-libs:generic:extensions:kotlin")

  testImplementation "net.java.dev.jna:jna:${libs.versions.jna.get()}"
  testImplementation project(":jvm-libs:linea:blob-compressor")
  testImplementation(testFixtures(project(":jvm-libs:linea:blob-compressor")))
  testImplementation(testFixtures(project(":jvm-libs:linea:core:domain-models")))
  testImplementation(project(":jvm-libs:linea:besu-rlp-and-mappers"))
  testImplementation(project(":jvm-libs:linea:testing:file-system"))
  testImplementation("io.consensys.tuweni:tuweni-bytes:${libs.versions.tuweni.get()}")
  testImplementation(project(":jvm-libs:linea:besu-libs"))
}

jar {
  dependsOn configurations.runtimeClasspath
}

def libsZipDownloadOutputDir = project.parent.layout.buildDirectory.asFile.get().absolutePath

task downloadNativeLibs {
  doLast {
    fetchLibFromZip("https://github.com/Consensys/linea-monorepo/releases/download/blob-libs-v1.2.0/linea-blob-libs-v1.2.0.zip", "blob_decompressor", libsZipDownloadOutputDir)
    fetchLibFromZip("https://github.com/Consensys/linea-monorepo/releases/download/blob-libs-v2.1.0-rc1/linea-blob-libs-v2.1.0-rc1.zip", "blob_decompressor", libsZipDownloadOutputDir)
  }
}

compileKotlin {
  dependsOn tasks.downloadNativeLibs
}

task cleanResources(type: Delete) {
  fileTree(project.layout.projectDirectory.dir('src/main/resources'))
      .filter {
        it.name.endsWith(".so") || it.name.endsWith(".dll") || it.name.endsWith(".dylib")
      }.each {
        delete it
      }
}

clean.dependsOn cleanResources
