Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
  • lfortran lfortran
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 394
    • Issues 394
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 72
    • Merge requests 72
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • lfortran
  • lfortranlfortran
  • Merge requests
  • !1549

Draft: Compile LFortran itself to WASM

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Ondřej Čertík requested to merge certik/lfortran:wasm into master Oct 27, 2021
  • Overview 6
  • Commits 34
  • Pipelines 16
  • Changes 13

Current status: everything compiles (without LLVM) and few simple things disabled.

Steps to compile:

  1. Install emscripten using: https://emscripten.org/docs/getting_started/downloads.html, it should work on all platforms. I tested on Apple M1. No root required.

  2. ./build0.sh (as usual)

  3. Load emscripten using source ./emsdk_env.sh (per the downloads manual) and:

emcmake cmake \
    -DCMAKE_BUILD_TYPE=Debug \
    -DWITH_LLVM=no \
    -DLFORTRAN_BUILD_ALL=yes \
    -DWITH_STACKTRACE=no \
    -DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH_LFORTRAN;$CONDA_PREFIX" \
    -DCMAKE_INSTALL_PREFIX=`pwd`/inst \
    .
cmake --build . -j16 --target install

Everything will compile. It fails while compiling the Fortran part of the runtime library because the lfortran executable does not exist. It creates lfortran.js and lfortran.wasm.

To run, this currently fails:

$ node src/bin/lfortran.js -- -h                 

/Users/certik/repos/lfortran/lfortran/src/bin/lfortran.js:141
      throw ex;
      ^
5555320 - Exception catching is disabled, this exception cannot be caught. Compile with -s NO_DISABLE_EXCEPTION_CATCHING or -s EXCEPTION_CATCHING_ALLOWED=[..] to catch.
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Not sure if it is supposed to work.

The main step now is to figure out how to actually run it, first locally and then in the browser.

Given that we skipped LLVM, we might need to write our own WASM backend in LFortran.

Exceptions I think don't work, but we don't need exceptions at this point. They are only used to report compiler errors and only locally and we can rework it not to need them at all.

Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: wasm