Skip to content

Conversation

henwoods
Copy link

Currently non-functional and only tested on OSX. I've not much experience bundling native libs so probably there is convention errors and hackiness that needs to be cleaned up with the build/make/gradle configs and the library loader.

Notes:

  • Currently crashes on start up with [SQLITE_ERROR] SQL error or missing database (no such function: powersync_rs_version), guessing this is because we need a way to support extensions for the JVM driver. Is this handled by requery on Android?
  • Library loader is (hackily?) just pulling the shared library out to a temporary file, worth exploring other options.

TODOs:

  • Didn't implement a way to determine if debug/release build yet
  • sqlight_bindings.cpp is copy/pasta from Android, would be good to pull it up so it can be shared
  • No logic for storing the database in a shared user folder yet, when run from Android Studio the database is just dumped in the build folder

Usage:

  • Noted above, Windows/Linux will require at least implementing a library loader with the appropriate shared library extension.
  • Gradle Sync
  • Install locally:
    • Disable release signing (RELEASE_SIGNING_ENABLED=false)
    • Run publishToMavenLocal task
  • Open powersync-hello and create a Gradle run configuration
    • Select the hello-powersync:desktop module
    • Set the Run field to run -DmainClass=com.powersync.demo.MainKt
  • Run the new config

Expect the app to crash with the missing powersync_rs_version function error

outputs.files(defFile)
}

tasks.create<Exec>("buildNative") {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run build.sh to build the binary and save it to build/native/powersync-sqlite/${OS}/output

iosArm64()
iosSimulatorArm64()
jvm {
val processResources = compilations["main"].processResourcesTaskName
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundle the binary into the jar

@@ -0,0 +1,12 @@
#!/bin/bash
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whats the convention for the location of build files 🤔

@@ -0,0 +1,91 @@
#include <jni.h>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned in the PR note, this is copied from androidMain, would be good to share the file

public actual val isDebug: Boolean
// TODO: need to determine a good way to set this on JVM presuming we don't want to bundle BuildKonfig in the
// library.
get() = true
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't want to add the dependency on BuildKonfig to the library, will explore if there is an alternative.

val schema = InternalSchema.synchronous()
this.driver = PsSqlDriver(
scope = scope,
driver = JdbcSqliteDriver("jdbc:sqlite:$dbFilename", Properties(), schema)
Copy link
Author

@henwoods henwoods Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the cause of the crash, not loading sqlite driver with extension support so the powersync_rs_version isn't available

import java.io.File
import java.io.InputStream

private interface LibraryLoader {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI recommended this approach so I'm sure there is a better way 😂

@DominicGBauer
Copy link
Contributor

DominicGBauer commented Jul 25, 2024

Thanks @henwoods for getting this going, I have gone through the PR and run into the same issue as you've pointed out.

I think what might help is that we already release powersync-sqlite-core https://github.com/powersync-ja/powersync-sqlite-core/releases for different targets i.e. linux, windows etc which will be useful for here.

Here's an example of how it has been implemented in Flutter

enableExtension() seems to be the same as System.loadLibrary(...).

I will have more time to look at this again next week.

@Shabinder
Copy link

is this currently being worked on ?
would be great to have this, and sqldelight for using it with ease.

@DominicGBauer
Copy link
Contributor

@Shabinder we have noted your interest but we are not currently looking at this. We are open to anyone in the community continuing with the PR to get it complete.

@kobiebotha
Copy link
Contributor

Closing this as it has been superseded by #88

@kobiebotha kobiebotha closed this Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants