iffy / wiish

Why Is It So Hard (to make a cross-platform app)?
MIT License
116 stars 7 forks source link

statically compiling sqlite3 on android required these changes #66

Open hagna opened 5 years ago

hagna commented 5 years ago
diff --git a/wiishpkg/building/build_android.nim b/wiishpkg/building/build_android.nim
index 54c21d4..9cb4118 100644
--- a/wiishpkg/building/build_android.nim
+++ b/wiishpkg/building/build_android.nim
@@ -97,6 +97,9 @@ proc doAndroidBuild*(directory:string, config:Config): string =
       &"--cpu:{cpu}",
       &"-d:appJavaPackageName={config.java_package_name}",
       "--noMain",
+      "--dynlibOverride:sqlite3",
+      "--dynlibOverride:sqlite3_32",
+      "--dynlibOverride:sqlite3_64",
       "--gc:regions",
       "--header",
       "--threads:on",
@@ -200,7 +203,8 @@ LOCAL_PATH := $(call my-dir)

 include $(CLEAR_VARS)
 LOCAL_MODULE := main
-LOCAL_SRC_FILES := {cfiles.join(" ")}
+LOCAL_SRC_FILES := {cfiles.join(" ")} /home/demo/sqlitesrc/sqlite3.c
+LOCAL_CFLAGS := -DSQLITE_ENABLE_FTS5
 LOCAL_LDLIBS := -llog

 include $(BUILD_SHARED_LIBRARY)

Where /home/demo/sqlitesrc is the sqlite3 amalgamation.

cfiles also includes another sqlite.nim.c file:

 [armeabi-v7a] Compile thumb  : main <= @m..@s.nimble@spkgs@sndb-0.19.7@sndb@ssqlite.nim.c

Here is the main_mobile.nim that I compiled:

## Hello, World Wiish App
import wiishpkg/webview_mobile
import wiishpkg/mobileutil
import os
import strformat
import strutils
import logging
import times
import ndb/sqlite

let index_html = app.resourcePath("index.html").replace(" ", "%20")

app.launched.handle:
  debug "app: App launched"
  app.window.onReady.handle:
    info "app: onReady"
    app.window.sendMessage("Looks like you're ready, JS!")
  app.window.onMessage.handle(message):
    info "app: onMessage: " & message
    let db1 = open("", "", "", "")
    db1.exec(sql"""create table bar (a);""")
    db1.exec(sql"""create virtual table t using fts5(a, b);""")
    info "create fts5 table"
    app.window.sendMessage("Celebrate in memory db over and over" & message)

app.willExit.handle:
  debug "app: App is exiting"

app.start(url = "file://" & index_html)

It would be nice if wiish had a way to add these build flags and the changes to Android.mk.