Skip to content
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

libfreetype.so when system == Emscripten #155

Open
jansindl3r opened this issue Jun 16, 2022 · 11 comments
Open

libfreetype.so when system == Emscripten #155

jansindl3r opened this issue Jun 16, 2022 · 11 comments

Comments

@jansindl3r
Copy link

in pyodide system = platform.system() is equal to Emscripten, which results to library_name = 'libfreetype.so', lib file (if I understand correctly) which can't be found. Is it something on your side or is it my incompetency?

File "/lib/python3.10/site-packages/freetype/raw.py", line 49, in <module>
     _lib = ctypes.CDLL(filename)
File "/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: Could not load dynamic lib: libfreetype.so
Error: libfreetype.so: file not found, and synchronous loading of external files is not available
@anthrotype
Copy link
Collaborator

i'm not even sure that loading dynamic libraries via cytpes is supported with emscripten python..
googling around I found this pyodide/pyodide#728

@anthrotype
Copy link
Collaborator

anthrotype commented Jun 16, 2022

since pyodide/pyodide#1656 was merged, ctypes is supposedly supported in pyodide.
Maybe you simply don't have the libfreetype.so installed, or your linker can't find it in the default library search paths (try setting LD_LIBRARY_PATH or DYLD_LIBRARY_PATH).

I also found pyodide/pyodide#2338 while searching for "synchronous loading of external files is not available" error.

I've never used emscripten python, maybe other maintainers know more.

@HinTak
Copy link
Collaborator

HinTak commented Jun 16, 2022 via email

@jansindl3r
Copy link
Author

I am on MacOs, but that shouldn't influence Pyodide, right? Thanks for pointing out the issue on Pyodide. Sorry, I am not that knowledgeable. I think my comment has nothing to do with this library, but rather with Pyodide.

This wrapper relies on the FreeType installed by the OS, like via brew, right? I guess the browser won't be able to access it anyway, even after the fix. Then I need to compile FreeType to .so and put it somewhere so freetype/raw.py can find it and then generate wheel out of this package, I believe 🙈

@anthrotype
Copy link
Collaborator

we do provide precompiled wheels for most platforms/py-versions already, they are published on the Python Packaging Index (PyPI), it's what gets normally installed when you do pip install freetype-py

@anthrotype
Copy link
Collaborator

anthrotype commented Jun 17, 2022

ok you're on mac so you should find the library under the name "libfreetype.dylib".. but instead of "Darwin" you get "Emscripten" from platform.system() so it falls back to the (implicit) "Linux" else branch of the if statement.
Not sure what's the best way to detect this situation.

@anthrotype
Copy link
Collaborator

anthrotype commented Jun 17, 2022

how did you install freetype-py in pyodide? Using micropip.install?

not sure, but maybe we need to build a custom Pyodide package where the freetype library itself is converted to webassembly?

https://pyodide.org/en/stable/development/new-packages.html#c-library-dependencies

@HinTak
Copy link
Collaborator

HinTak commented Jun 17, 2022 via email

@anthrotype
Copy link
Collaborator

pyodide is cpython compiled to webassembly, it runs in a special vm inside the browser, it doesn't have access to external libraries. We need to make a pyodide package as explained in the pyodide docs link I posted above. We're lucky in that there's already an emscripten port for the freetype library itself, so it's a matter of doing something similar to what they do for the pyodide package for "matplotlib" module (which also depends on the freetype library):
https://github.com/pyodide/pyodide/blob/38fae6e9cbcdd8e932a53bf1c763279dc55729d5/packages/matplotlib/meta.yaml#L24-L26

@HinTak
Copy link
Collaborator

HinTak commented Jun 17, 2022 via email

@anthrotype
Copy link
Collaborator

The emscripten port of freetype is really old though

yeah, 2.6 is quite old. Some user of the emscripten port reported success in building freetype with the emcmake tool

I discovered that the latest FreeType builds fine using emcmake cmake with their latest CMakeLists.txt file, so I switched to using that in my workflow.

emscripten-ports/FreeType#4 (comment)

So it's technically feasible, only need someone to take the time to understand how to build a pyodide package and make a PR upstream to include in pyodide's own built-in packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants