-
Notifications
You must be signed in to change notification settings - Fork 198
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
Web Assembly builds? #28
Comments
No, there is no such plan but I would accept a PR ;-) |
I think there was discussion to create a build target for it. Basically, you use emscripten instead of the built in C++ compiler to generate the web assembly files. Here is an example repo: https://github.com/urish/pdfium-wasm However, it seems a bit outdate in its build process. |
@bblanchon we're looking into using the WASM build for go-pdfium, see: klippa-app/go-pdfium#60 Would it be possible to also compile WASM in standalone mode so that we can use it for that purspose? |
@jerbob92, I'm not so familiar with WASM... |
I found the answer to my own question:
Source: https://v8.dev/blog/emscripten-standalone-wasm#do-we-need-non-standalone-wasm%3F |
Hi @bblanchon, I wasn't completely clear in my question, my intention was indeed to have a web build and a standalone build. |
I wonder if it's useful to provide both: it seems that the standalone build could work for everyone. |
Looking at this article: https://github.com/emscripten-core/emscripten/wiki/WebAssembly-Standalone |
Here is a build that ran with |
Thanks a lot! Will do soon when I have some time, hopefully tonight! I do see that this has been added to the JS file:
Might become an issue |
@bblanchon I'm making some progress in getting it to work, but I'm getting some odd internal issues. Would it be possible to create a debug build so I can see the stacktrace? I can only see things like this now:
I believe the flag is called |
@bblanchon nvm about that, the flag is called |
Awesome! Let me know if I can help you with anything else. |
@bblanchon Thanks! Nothing for now, just some FYI's:
Also:
|
I don't know if PDFium works without threads. |
Yeah, I know we don't need a full filesystem, but it does at least need a working |
@bblanchon I'm making some progress, I have gotten
Do you have any idea what could cause that? Looking at the code doesn't really give me a clue. Will do more research tomorrow what that actually means. |
The PDFium team updated the "partition_allocator" last week. |
Great catch, I had no idea! I just compiled with 5254 and disabling the |
@bblanchon even with 5254, it looks like it works more, but that might just be the difference between the two allocators. When looking at the code, this has not been implemented: https://github.com/emscripten-core/emscripten/blob/1bbb5f8dea4422768bdc9a9a44ce8a9eb6dd39c9/system/lib/libc/emscripten_mmap.c#L119 This was changed a few months ago: emscripten-core/emscripten@d81e048 Any idea if we can remove the address space randomization, it seems to be causing all of the issues right now (needing /dev/urandom, not being able to call mmap) |
@bblanchon I'm fairly certain that all the memory issues are caused by the same thing, and there is already a long thread about it at Emscripten: emscripten-core/emscripten#14459 So I think the current WASM version is not really usable in any form (Web or Standalone), |
@bblanchon I have been testing some more, and pdfium recently added the build option |
That's excellent news, @jerbob92! pdfium-binaries/steps/05-configure.sh Lines 33 to 36 in 6120c98
|
@bblanchon I'm doing some more tests now to see what needs to be changed to make this work completely for both serverside and in the browser support, but the most important change is adding the line in there indeed. |
@bblanchon Might be good to give you some sort of update: I have been working together with the Wazero team to get a working runtime for the compiled pdfium (we needed to implement some WASI calls to get font/file reading to work). I have also been patching Emscripten to proxy syscalls to WASI to make that actually end up at the application. However, once these syscalls are implemented in Emscripten, they do not show up anymore in the generated JS, meaning that these features then suddenly break in the JS build. What I also experienced is that there are a lot of different WASM features that are not finalized yet so they are not implemented in every engine. Emscripten allows you to turn them on/off with a flag. My conclusion is that we can't really get away with 1 WASM build for all environments. I think we need at least 2 builds:
Then there's a load of flags that you can pass into Emscripten to change it's behaviour, like WASMFS and enabling WASM Exception support, which also change what is being required of the runtime. I would not use them right until there's support for those in more engines. Then there's also the thing that Emscripten emits a lot of methods that the runtime should implement before it works:
My suggestion for now would be to create two builds:
I will let you know once I have my Emscripten patches completed enough to implement all the required syscalls/WASI calls. Once we're able to compile pdfium with wasi-sdk, we should probably switch the standalone build to that, seems like a way better choice for server-side runtimes. |
Thanks for the update. |
I think for now add |
I was wondering if there are any plans to have wasm builds as well?
The text was updated successfully, but these errors were encountered: