[sword-devel] Sword as a WASM library

Kovács Zoltán kovzol at gmail.com
Sat Jan 15 04:05:36 EST 2022


Dear Troy, thanks for the kind words!

Troy A. Griffitts <scribe at crosswire.org> ezt írta (időpont: 2022. jan. 14.,
P, 18:43):

> Welcome Zoltán!
>
> I am curious how local storage is used and how much is available. We jump
> through all kinds of hoops to get libsword compiled and accessible on both
> iOS and Android for Bishop. It would be nice if maybe we could simply ship
> a WASM lib with Bishop for both platforms.
>

I uploaded a WASM build to
https://github.com/kovzol/crosswire-sword-mirror/releases/tag/2022Jan03.
This should be ready to use for inclusion in other WASM based projects. I
will send you a detailed description on how one could easily build it from
scratch (in a different email).

The local storage is surprisingly easy to set. Emscripten wants to know
which native folder is to be used in the browser and it can be set by using
the --preload-file option on linking. The documentation at
https://emscripten.org/docs/porting/files/packaging_files.html#packaging-using-emcc
explains this very well. I simply packaged the ~/.sword folder to get
access to the same Bible texts I installed for the native version by using
installmgr. In my case the texts KJV, LXX and SBLGNT took about 10 MB of
disk space, and Emscripten created a .data file that had to be uploaded on
the web server too. Loading this amount of data is very fast, less than 1
second. I guess, storing a couple of other texts is still manageable. Maybe
some compression could also be done, but I haven't investigated this
question yet. When a .data file exists, it seems a web server is required
-- maybe the .data file can also be bundled in the .js, so no web server
must be used. I will check this later. (The .js file can contain the .wasm
code if you want, that's the simplest way to avoid using a web server for
WASM based web applications.)

In fact, everything is compiled transparently, no action is to be done in
Sword to access the local storage, nothing. Emscripten takes care of every
step: this works incredibly smoothly.


> I noticed your patch is to our cmake build. Greg Hellings holds the
> pumpkin there, so I defer to his wisdom on inclusion. Greg, if you're busy,
> I am happy to commit if you have a brief look and "OK" the change.
>
>
> https://github.com/kovzol/crosswire-sword-mirror/commit/2ed499fe72141345a9d90053b0c96be5549df6ca
>

Yes, this change should be harmless for the other parts of Sword. :-)

Best regards, Zoltán
--------- k�vetkez� r�sz ---------
Egy csatolt HTML �llom�ny �t lett konvert�lva...
URL: <http://crosswire.org/pipermail/sword-devel/attachments/20220115/af1d477e/attachment.html>


More information about the sword-devel mailing list