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

Use LFortran to compile any Fortran to WASM #684

Open
certik opened this issue Oct 27, 2023 · 7 comments
Open

Use LFortran to compile any Fortran to WASM #684

certik opened this issue Oct 27, 2023 · 7 comments

Comments

@certik
Copy link

certik commented Oct 27, 2023

LFortran (as of today) can compile 6 out of 18 Fortran packages in SciPy: lfortran/lfortran#2743, and we keep working on compiling the rest. At the same time, I think it's a good time to start using LFortran to compile SciPy to WASM, since it will take some time to iron out all issues. LFortran is available in conda-forge, works on all platforms, etc. We would like to make LFortran work seamlessly as a robust tool that you can depend on and that will eventually remove all pain issues with the tooling around Fortran.

We can start with SciPy (unless you have a better package to try). Here is my understanding so far:

@martinRenou, @DerThorsten how can we help? This will be a long term iterative process, but we want to get started. The nice thing is that once we get SciPy working, LFortran will (almost) automatically work for any other Fortran package out there, so this is a great long term investment.

@DerThorsten
Copy link
Contributor

DerThorsten commented Oct 28, 2023

Atm we take the whl build from pyodide https://github.com/pyodide/pyodide/tree/main/packages/scipy

We did that because I was too lazy to update all the above-mentioned hacks when updating to an new scipy version (these hacks are all still done by pyodide, and our initial build script was adapted from pyodide by @wolfv)

@wolfv
Copy link
Contributor

wolfv commented Oct 28, 2023

I would be super happy to test doing this with you in the emscripten-forge context, @certik. Personally I prefer building scipy from source here instead of taking it from pyodide.

@certik
Copy link
Author

certik commented Oct 28, 2023

@wolfv, @DerThorsten awesome. Let's say LFortran can generate the same wasm output as f2c+emcc. How do you then call it from Python? Do you use the f2py somehow, like scipy does? I was thinking of testing this using some small demo, to ensure everything works.

@wolfv
Copy link
Contributor

wolfv commented Oct 28, 2023

Emscripten can load the shared objects just fine iiuc

@certik
Copy link
Author

certik commented Oct 28, 2023

Ah, so we compile the Fortran code to an "object file" that emcc then loads when it is being linked to the main application? I will need to setup a working example first.

@wolfv
Copy link
Contributor

wolfv commented Oct 29, 2023

That would be an interesting start. I think one can also dlopen a SO file with emscripten. I am not sure if emscripten needs anything special.

Maybe a good start could be to take the existing scipy package, create the WASM environment with micromamba, and then exchange the .so files in there?

@DerThorsten
Copy link
Contributor

@certik I added instructions how to setup local builds with emscripten forge https://github.com/emscripten-forge/recipes#local-builds

The easiest way to build a new python package and test it is probably via a new recipe.
The build does not necessarily need happen inside the recipe.
Currently, we just take some externally built wheel in the scipy recipe and extract it.
But doing so would allow us to use all the mechanisms we have to test the packages via playwright in a headless browser

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