-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZIM backend : Try to cross-compile the libZIM library in webassembly with emscripten #116
Comments
Being able to use libZIM as is depends on the question whether we can use synchronous IO at the low-level javascript side. |
I don't think there is a way to do synchronous I/O on files in javascript. |
Dattaz, I assign you this issue, as you expressed some interest in it. |
@thiolliere if you want to have a look, too |
I met @bnjbvr yesterday (he was giving a conference about WebAssembly, at @mixitconf), and talked to him about this idea. He said he might put us in touch with the maintainer of emscripten if necessary. I found this article that tackles our issue : https://hacks.mozilla.org/2015/02/synchronous-execution-and-filesystem-access-in-emscripten/ |
I have compile libzim in webassembly ; you can check demo here : https://dattaz.github.io/libzim_wasm/ (but zimfile (meta.esperanto.stackexchange.com_eng_all_2017-05.zim 1,9M) is embedded ) ; Now we have to deal with filesystem :) Source code to build is here : https://github.com/dattaz/libzim_wasm |
Yeah! @dattaz, you rock! The virtual filesystem you used for the demo can not work with bigger ZIM files that would not fit into memory.
In both cases, we have to make it use a javascript File object that we would pass to the wasm code : I hope it's possible |
Emscripten has WORKERFS as file system which permit to load file object as file into FS. This is only allowed in web worker. According doc (https://kripken.github.io/emscripten-site/docs/api_reference/Filesystem-API.html) it's seem really close of that we want to do : "This file system provides read-only access to File and Blob objects inside a worker without copying the entire data into memory and can potentially be used for huge files." Here is a (little) demo : https://dattaz.github.io/libzim_wasm/file_api/index.html Note that for the moment there is a issue with file bigger than 2GB : emscripten-core/emscripten#5250 |
I did not know about workerfs : it looks great for our need! |
@mossroy That sounds like an important step forward, but I'm not sure to understand concretly what it means. Does it means the work to bind Kiwix JS with libzim-js could start? BTW, I use the opportunity to inform you formally that @ISNIT0 has updated |
The bindings are written in nbind, which natively supports compiling to webassembly, possible to do :) |
No, what I did yesterday is not a significant step. It just simplifies reproducing what was achieved at the last hackathon on this topic (based on the work of dattaz). There is at least one blocking issue : emscripten-core/emscripten#5250 , which prevents reading files bigger than 2GB. This has to be fixed on the emscripten side, and I'm not able to do that myself. This issue has been tagged by kripken as "help wanted" : if you know someone able to work on that, it would be cool. And there are also many things that need to be done before really using it in kiwix-js (see #116 (comment) above) :
All this is very exciting. I'm just missing some time to work on it. |
Regarding https://github.com/openzim/node-libzim, I currently don't see how it could be useful for kiwix-js. The second step is to bind the recompiled C code with javascript. |
I worked a bit on compiling kiwix-lib with emscripten (in branch https://github.com/mossroy/libzim_wasm/tree/kiwix-lib-compilation) : it's a long journey but I make progress (with many dirty hacks). |
I managed to compile the kiwix-lib with emscripten, and make a simple C call from javascript. |
When I make the second C++ call, it fails with |
Well, I have to admit I'm currently stuck. |
Would be happy to organise a call, it might be that what I've learned from |
Thanks @ISNIT0 for the pointers you gave me during this call. I'll try to sum up what we discussed :
|
I just tested to separate the code in 2 functions (initReader and getArticleCountFromReader) in https://github.com/mossroy/libzim_wasm/tree/multiple-c-calls. With the wrapper workaround, it compiles and runs, but there's the same error in the second call. |
Unfortunately I can't get the build to run on my Mac, so I can't play around with it :( |
@ISNIT0 : it's possible to build with Docker if it helps (see the README.md) |
This github issue has too much history : it's probably complicated to get into it. |
It would avoid to re-code it in javascript, and would also ease support of future evolutions of the file format.
But not sure how Emscripten would handle the file I/Os
The text was updated successfully, but these errors were encountered: