xerial / sqlite-jdbc

SQLite JDBC Driver
Apache License 2.0
2.86k stars 619 forks source link

Native libs for iOS aarch64/x86_64 #745

Open philip-han opened 2 years ago

philip-han commented 2 years ago

I've tried latest release on iOS using GraalVM but it crashes because iOS native libs are not included.

A simple insert worked with the last pure Java version but I doubt that it will work much beyond that.

Is it possible to to build native iOS native libs using Intel Mac? I could give it a try if someone could give me some pointers.

gotson commented 2 years ago

to make the builds reproducible and updatable to future versions, this project tries to always build the native libs using Docker containers with cross-compilation (https://github.com/dockcross/dockcross).

The exception is M1 macs, which are compiled by Xerial directly (since there is no cross-compilation containers for that yet).

gotson commented 2 years ago

@philip-han I'm not familiar with ios, what does it run exactly in terms of cpu architecture and OS?

Do you have logs from the graalvm execution?

philip-han commented 2 years ago

@gotson I get this error message from xerial when running on iOS simulator on Intel Mac

"No native library found for os.name=iOS, os.arch=x86_64"

I believe this error is coming from OSInfo.java.

On real iPhone, os.arch would be aarch64. My code works when I'm targeting Mac desktop since Mac native libs are included.

Also, xerial 3.7.2 pure java mode works too on iOS but I don't want to use such outdated version.

gotson commented 2 years ago

OSInfo maps the OS and architecture to a native library on disk.

iOS is not a known OS so it returns iOS but can't find a library for that value.

If iOS can run macOS binaries, you could try to add a check for iOS here, it would then load the macOS native library.

philip-han commented 2 years ago

iOS cannot run mac binaries, hence my request for iOS/x86_64 and iOS/aarch64 native libs.

I'm going to research if I can cross compile iOS libs on my Mac at some time.

iOS sdk does provide sqlite libs in it's own format which contains both aarch64 and x86_64, going to see if that could be used here.

gotson commented 2 years ago

iOS sdk does provide sqlite libs in it's own format

what format is that ?

philip-han commented 2 years ago

iOS sdk distributes .tdb files which turns out to be just a stub file in yaml format. Ultimately, it resolves to .dylib file which is standard.

It loaded but results in unsatisfied link error in NativeDB.java

java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open_utf8([BI)V [symbol: Java_org_sqlite_core_NativeDB__1open_1utf8 or Java_org_sqlite_core_NativeDB__1open_1utf8___3BI] at com.oracle.svm.jni.access.JNINativeLinkage.getOrFindEntryPoint(JNINativeLinkage.java:153) at com.oracle.svm.jni.JNIGeneratedMethodSupport.nativeCallAddress(JNIGeneratedMethodSupport.java:52) at org.sqlite.core.NativeDB._open_utf8(NativeDB.java:-1) at org.sqlite.core.NativeDB._open(NativeDB.java:72) at org.sqlite.core.DB.open(DB.java:211)