-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Is there a GLIB emscripten port available ? #11066
Comments
I'm not aware of any glib port I'm afraid. I imagine porting libffi might be tricky as IIRC it involves assembly code. Perhaps there is way to remove that dependency. Feel free to add a port to https://github.com/emscripten-ports if you manage to get it working. |
I had a similar problem while porting libvips to Emscripten (see libvips/libvips#192 for details). GLib and libffi currently require patches to successfully build them with Emscripten. Could you try these?: These patches were copied from my local Git repository and tested with libffi 3.3 and GLib 2.64.2. Most of the libffi work has already been done by @Brion (thanks!), see: https://github.com/brion/libffi/commits/emscripten-work I just made it compatible with the latest Emscripten (by swapping Anyways, I'll eventually try to incorporate these patches upstream. |
That sounds great @kleisauke ! If there are issues getting them upstream, adding a port in emscripten-ports is also an option. |
thanks @kleisauke for your patches I tried them on
Things look a bit better but I keep getting the error I have applied your emscripten cross file wasm32 is the right cpu family and not x86 of course ... but wasm32 seems unsupported I am exploring multiple issues at the same time I guess 😊 |
@o-micron I've updated the gist with an example build script. Let me know if that works for you. |
thanks @kleisauke that definitely works ! 💯 Also for anyone coming from the future for the same issue, here are some packages needed as well
|
Great! If someone is interested to add this to |
@kripken I would definitely help adding that to emscripten-ports but I would rather let @kleisauke do it and take the credit for his work I have added above the simple steps I took to successfully build it on ubuntu |
@kripken Here is a script which does everything really ... could replace the whole port repository Tested on
|
Nice @o-micron, yeah, if we don't need a separate repo then this is quite easy. That script could be converted into a python script and put under |
For a long time we (I) have been trying to come up with a place to put "contrib" ports like this. Simply adding everything and the kitchen sink to "tools/ports" doesn't scale very well. I don't have an answer right now.. only the question. |
The meson build system solves this problem with the Wrap dependency system. Perhaps we could do something similar with Emscripten ports? For example, port files could look like this: Details[port-file]
directory = glib-2.64.2
source_url = https://download.gnome.org/sources/glib/2.64/glib-2.64.2.tar.xz
source_filename = glib-2.64.2.tar.xz
source_hash = 9a2f21ed8f13b9303399de13a0252b7cbcede593d26971378ec6cb90e87f2277
patch_url = https://gist.github.com/kleisauke/acfa1c09522705efa5eb0541d2d00887/raw/37e3787a16cef2b8a1b577d469406ebbb80147d7/glib-emscripten.patch
patch_filename = glib-emscripten.patch
patch_hash = bb46e867ce457d4c34551968303ffde520b5f17a54df69653e11677b7df9cfc5 [port-git]
url = https://github.com/brion/libffi.git
revision = emscripten-work (This is heavily inspired from Meson Wrap files) The advantage of this is that updating ports can then be done without much effort, since you don't have to embed an entire project into the source tree (i.e. This is only for the source part, I'm not sure how the actual build of these ports might look like (because it can be very specific to users' needs). |
The immediate problem I'd like to solve is how to add ports without adding:
There are lots good ports systems out there. Its not clear if we want to block this work on choosing one and switching to it, or sticking with our existing one. Part of me would like to do all of this out-of-tree using something like pacman (from arch) the freebsd ports system: https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/ports-using.html. But as an incremental step I think we could just use |
At least one related bug: #10048 |
I think we can get rid of that boilerplate by automatically adding a setting for each port. So adding a port would mean just adding a single file under
I think we don't need to test every thing in |
Yes I pretty much agree with that. I do think that using a subdirectory would useful to indicate to two distinct and separate types of ports. I like |
Also the current ports system isn't quite plug and play enough, you currently also need to add to the list in |
For now, adding to |
For the record, I would like to check in glib and libffi as port, but my main concern with https://github.com/emscripten-ports is that it's difficult to maintain when a new upstream version is available, especially if the Emscripten parts are also integrated upstream. Downloading tarballs and applying custom patches (if necessary) seems more common and a lot easier.
Looks like you're describing #9353. |
We can argue the benefits of using tarball + patche file vs using a git repo, but changing the way we do things would be much bigger change and if you just want to get glib working in emscripten than using If we do want to get into the weeds of git vs patch patch files, I think I would argue that maintaining a series of patches on top of an upstream set of code is pretty much exactly what git is designed to do. A system you like describe, such as quilt (https://linux.die.net/man/1/quilt) where the user must manually the parch series as a set of individual files, just seems like doing everything git does but with a lot more work and lot more error prone. I imagine there are some advantages to keeping the patches outside of git, but storing them as gists seems pretty odd, when you have git, which has things like history. I guess each gist has its own history? But then are you are basically maintaining each patch its own git repo? Anyways, as you can see, I don't think its clear cut argument. |
Is there a reason why some of the
Indeed, storing them in gists is odd. It was just to resolve this issue as the libvips WASM port (which contains the same patches) is not released yet. |
If there is a historical reason I don't know it. I would have thought the point of creation of repository there is the point at which we need a patch. If no patch is needed no repository should be needed. |
I agree, I think it should be as simple as a single or couple of patching files. I like how cmake works, whenever I open a new project I search for This type of consistency solves a lot of problems, it's like you can almost guess how to build the project and with 90% chance you will build it with no issues unless the author adds more complicated options and that's what makes Emscripten could have same model but without the options and complexity, just a single command to build and everyone is happy .. that's not easy to do, but I think that's how it should be done |
@o-micron I did according to above steps, but below error pop up Error: bad memory |
@wurc Could you try this?: # The struct_info file must be built without modifications to EMMAKEN_CFLAGS
EMMAKEN_CFLAGS= embuilder.py build struct_info (I just added this to the gist) |
@kleisauke, it works :-) |
@kleisauke one more question, |
I think there's no reason to create a forked directory unnecessarily. Perhaps we created some historically when we thought we would need patches, but ended up not needing them? PRs to simplify that would be welcome, and we can delete those repos. |
@kripken when I use the generated glib, below error comes, do you know why this issue happened? |
Those functions are not being linked in, it seems? To investigate it, find where they are defined, and then you can use |
res_query is used to looking up hostnames in DNS. You should probably find a what to remove that call from
|
Sorry .. see the above discussion about libffi and had forgotten we had already discussed it and it looks like the a solution already. |
Yes I just use gsocket related apis. It is impossible to use those apis? |
@wurc You could try to adapt this patch: I created that patch because
Perhaps it's only needed to just disable @kripken That's great, thanks for clarifying! I'll take a look to prefer the upstream repositories if no patches are needed. This may also facilitate port maintenance and speed up delivering improvements from new versions to end users. |
@kleisauke it means currently it is impossible to use gsocket apis which depends on network libs, right? Actually we use the glib socket apis to implement muti-cast function, and we want to transfer it to wasm module |
The socket I/O APIs in emscripten are based on websockets, which means you need to proxy all your socket data back through a websocket to your server and then out from there. I doubt very much that things like mutli-cast will work, but perhaps its possible. Sadly, sockets and web are not currently a good match and you will have to go through these extra hoops. I would advise looking onto how the websocket bridge works and running some experiments to see if you use case can be made to work on the web. |
Hi I use below method to use muti-cast, but when calling start_muticast_client in C++, it can't works |
A first release for the above mentioned WebAssembly bindings for libvips has now been published. I'll try to integrate the necessary patches of this project upstream (annotated with |
I'm currently working to port some code from https://gitlab.com/inkscape/lib2geom to wasm and glib is the last dependency I need to tackle. Thanks a lot for working to sort this out folks. I tried carefully and repeatedly to get a glib build using the instructions on Ubuntu 20.04 but failed. Here's the most relevant part of the log from the build log:
My meson version was ahead of a tested version mentioned so I also tried downgrading from 0.56.0 to 0.54.1 and got the same results. full console log Note: I renamed the hash folder to EDIT: I found this issue which seems related to this one I'm having. |
@kleisauke do you think the glib and ffi patches are the only ones we need to fix the glib build as instructed above? |
@justin-hackin I've just updated the gist with a tested Dockerfile and necessary patches for glib and libffi. Let me know if that works for you. |
@kleisauke that's kind of you to share, thanks a lot, it works! You made my day :) |
I did some work on libffi because it is a blocker for ctypes support in Pyodide. I added support for long double, structs, and closures. It now passes 56/56 libffi.call tests and 84/94 libffi.closures tests. I have my changes here: Hopefully I can figure out how to set up a CI test runner for this. |
@hoodmane Great, thanks for doing this! I made some changes to my fork: Let me know if you want a PR for that. With those changes, the libffi test suite almost passes with 20 failures (and 26 failures when building without DetailsBuild with
Build without
|
Please! Thanks for working with me on this.
Yeah it's strange. The only relevant conditional seems to be: if { [libffi_feature_test "#if FFI_CLOSURES"] } { and we certainly defined |
FWIW, after commit kleisauke/wasm-vips@10dd7e0 patches are kept in forks to facilitate upstreaming, for example: Unfortunally, the GLib patches might not be appropriate to upstream, as they currently have a hard requirement regarding function pointer conversions - see: So the work on that is stalled, it needs to be discussed upstream first. I'm not sure if GLib would drop that hard requirement, from an ABI/API perspective. |
This emscripten can do though. It sounds to me like they are trying to rule out fat function pointers? If they need more flexible casts that change the number or type of arguments one can always call them with a trampoline. |
TIL, about fat function pointers. I think you're right, that seems to only relate to the I fixed most of these issues with commit kleisauke/glib@013ba3b (e.g. grep for FWIW, I'm aware that GLib currently also fails when running with |
These are the original set of changes very kindly organized and released in a patch by https://github.com/kleisauke. The details of this patch are in this thread: emscripten-core/emscripten#11066.
Thanks to @kleisauke et al for the progress in this thread. I have been trying to build using the docker gist, with modifications, on Mac M1. I had to add Still stuck linking with emcc though. Everything from the gist compiles without error, but some functions, like file system stuff (g_unix_mount_is_readonly etc) are unavailable. Is there a specific flag that might not be adding those functions to the compile list? They exist in the source, so I don't see offhand why they wouldn't be included, but others in the libraries are found just fine. Make line:
If anyone has made any further progress or has successfully linked glib let me know. |
Based on @kleisauke 's work, I built Pango and Cairo with GLib. In case anyone has interests, here is the gist: https://gist.github.com/VitoVan/92ba4f2b68fec31cda803119686295e5 |
Hi! As an alternative to emscripten-ports, we've added |
Hi, I had some code depending on glib and I went to build glib from source to find out it is a rabbit hole.
glib is using meson build system, no cmake or makefiles out there ...
6 hours later, it turns out the problem is building libffi for emscripten ...
Am I missing something ? Maybe there is a glib port available ?
The text was updated successfully, but these errors were encountered: