Code Monkey home page Code Monkey logo

Comments (9)

humblehacker avatar humblehacker commented on July 29, 2024 8

So I went spelunking around in the SQLDelight gradle plugin source to see if I could find how adding the plugin to my shared project solved the linking problem. Then I thought I could just pull that out and use it, avoiding the other problems the plugin was causing. Well, I found it and it worked!

If I add this to my shared build.gradle.kts file right below the android block, all methods of building work, and the above workarounds are no longer necessary:

fun Project.linkSqlite() {
    val extension = project.extensions.findByType(org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension::class.java) ?: return
    extension.targets
        .filterIsInstance<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>()
        .flatMap { it.binaries }
        .forEach { compilationUnit ->
            compilationUnit.linkerOpts("-lsqlite3")
        }
}

linkSqlite()

This is a literal cut-and-paste. I'm not a gradle expert and I haven't done anything to clean it up yet. But this is my fourth attempt over many months of trying to get this to work, so I'm happy to finally have a solution.


After some minor clean-up:

project.extensions.findByType(KotlinMultiplatformExtension::class.java)?.apply {
    targets
        .filterIsInstance<KotlinNativeTarget>()
        .flatMap { it.binaries }
        .forEach { compilationUnit -> compilationUnit.linkerOpts("-lsqlite3") }
}

from sqliter.

kpgalligan avatar kpgalligan commented on July 29, 2024

Need to add the sqlite linker arg -lsqlite3. See long thread discussing: cashapp/sqldelight#1442 (comment)

from sqliter.

vanniktech avatar vanniktech commented on July 29, 2024

I've tried:

kotlin {
  [
    iosX64(),
    iosArm64(),
    iosSimulatorArm64(),
  ].forEach {
    it.binaries.all {
      freeCompilerArgs += "-Xg0" // Required for CrashKiOS.
      if (it instanceof org.jetbrains.kotlin.gradle.plugin.mpp.Framework) {
        it.isStatic = true // Required for CrashKiOS.
        it.linkerOpts.add("-lsqlite3")
        it.embedBitcode("YES".equals(System.getenv("ENABLE_BITCODE")) ? "bitcode" : "marker")
        it.setFreeCompilerArgs(it.getFreeCompilerArgs() + "-Xobjc-generics")
      }
    }
  }
}

Does not seem to do the trick though.

from sqliter.

kpgalligan avatar kpgalligan commented on July 29, 2024

Sorry for delay here. Was this resolved? Will take a look on newer sqldelight releases if not. At the end of the day, it's always some form of -lsqlite3 is missing somewhere, but occasionally it's in an unexpected place.

from sqliter.

vanniktech avatar vanniktech commented on July 29, 2024

Nope. Still getting that failure.

from sqliter.

lcszc avatar lcszc commented on July 29, 2024

@vanniktech did you find a fix? I'm facing a similar issue and I've tried all possible linking solutions and am still unable to run ./gradlew iosSimulatorArm64Test

I have a shared module that contains database stuff and shared-ui for presentation logic that exports shared. I can run ./gradlew :shared:iosSimulatorArm64Test and it works, however when trying to run shared-ui tests it fails.

from sqliter.

vanniktech avatar vanniktech commented on July 29, 2024

Nope. I have the exact same issue as you do.

from sqliter.

humblehacker avatar humblehacker commented on July 29, 2024

I have the same problem. I also have a separate module for database stuff. I've found that if I add the sqldelight plugin to both modules while keeping the sqldelight configuration block only in the database module, everything compiles and links properly, but I lose the on-the-fly code generation and other niceties sqldelight provides.

from sqliter.

samhill303 avatar samhill303 commented on July 29, 2024

Closing this. Please re-open and let us know if you're still having issues

from sqliter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.