Skip to content

LLVM_WASM: Support linking via emscripten#3877

Merged
ubaidsk merged 4 commits intolfortran:mainfrom
ubaidsk:emcc
Apr 16, 2024
Merged

LLVM_WASM: Support linking via emscripten#3877
ubaidsk merged 4 commits intolfortran:mainfrom
ubaidsk:emcc

Conversation

@ubaidsk
Copy link
Member

@ubaidsk ubaidsk commented Apr 16, 2024

No description provided.

@ubaidsk
Copy link
Member Author

ubaidsk commented Apr 16, 2024

Steps:

  1. Download and install emscripten from https://emscripten.org/docs/getting_started/downloads.html
  2. Build with the following:
diff --git a/build1.sh b/build1.sh
index 49a1cf78b..24737c919 100755
--- a/build1.sh
+++ b/build1.sh
@@ -3,6 +3,8 @@
 set -e
 set -x
 
+export EMSDK_PATH=$HOME/ext/emsdk
+
 cmake \
     -DCMAKE_BUILD_TYPE=Debug \
     -DWITH_LLVM=yes \
@@ -12,5 +14,6 @@ cmake \
     -DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH_LFORTRAN;$CONDA_PREFIX" \
     -DCMAKE_INSTALL_PREFIX=`pwd`/inst \
     -DCMAKE_INSTALL_LIBDIR=share/lfortran/lib \
+    -DWITH_TARGET_WASM=yes \
     .
 cmake --build . -j16 --target install
  1. Test using
% lfortran examples/expr2.f90 --target=wasm32-unknown-emscripten
25
% ls | grep expr2
expr2.out
expr2.out.tmp.o
expr2.wasm
% node expr2.out
25
% rm expr2*
% lfortran examples/expr2.f90 --target=wasm32-unknown-emscripten --wasm-html
25
% ls | grep expr2                                               
expr2.out.html
expr2.out.js
expr2.out.tmp.o
expr2.out.wasm
% node expr2.out.js
25
% python -m http.server
Serving HTTP on :: port 8000 (http://[::]:8000/) ...

In browser, you can open expr2.out.html to see

image

@ubaidsk
Copy link
Member Author

ubaidsk commented Apr 16, 2024

Example from #3823 (comment) in browser looks as follows:

image

@ubaidsk ubaidsk marked this pull request as ready for review April 16, 2024 14:20
Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good. Thanks!

@certik
Copy link
Contributor

certik commented Apr 16, 2024

Is non-emscripten WASM still supported?

@ubaidsk
Copy link
Member Author

ubaidsk commented Apr 16, 2024

Is non-emscripten WASM still supported?

The one from clang (for wasi)? Yes that is still supported.

@ubaidsk ubaidsk merged commit 1ce45f4 into lfortran:main Apr 16, 2024
@ubaidsk ubaidsk deleted the emcc branch April 16, 2024 15:27
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

Successfully merging this pull request may close these issues.

2 participants