I compiled the 1978 edition of The Oregon Trail — ~1,000 lines of fixed-form FORTRAN 77 — to WebAssembly with LFortran, and it’s playable in your browser, even on your phone. Source code is here.
Beautiful, thanks for getting it working!
You should post on X, for now I posted it here: LFortran on X: "The Oregon Trail in the browser – FORTRAN 77 to WebAssembly with LFortran, by @minhqdao ." / X
Thanks for helping to fix the conda package for LFortran and your bug reports. I see two open: Issues · lfortran/lfortran · GitHub, we’ll fix it.
How to compile it? Thx.
@Cean instructions are here: https://github.com/minhqdao/oregon-fortran-wasm#webassembly-build.
To rebuild them yourself, install LFortran and Emscripten, make sure both are on your PATH, and run:
npm run build:wasm
I have built a hello.c file into html file with Emscripten. No need of npm.
But it seems Emscripten can’t do fortran, so you need lFortran. How to build a fortran file into html file without npm under Windows 10?
You can try:
-
Compile with LFortran:
lfortran -c --fixed-form --implicit-interface --implicit-typing --target=wasm32-unknown-emscripten hello.f -o hello.o -
Link with Emscripten:
emcc hello.o $RUNTIME/lfortran_runtime_wasm_emcc.o -o hello.html
The scripts are in here: oregon-fortran-wasm/scripts/build-web.sh at main · minhqdao/oregon-fortran-wasm · GitHub
Tried on 0.63. Error like this:
D:\00Fortran\oregon-fortran-wasm-main\hello>lfortran --version
LFortran version: 0.63.0509
Status: alpha (expected to fail on third-party codes)
Platform: Windows
LLVM: 22.1.4
Default target: x86_64-pc-windows-msvc
D:\00Fortran\oregon-fortran-wasm-main\hello>c
D:\00Fortran\oregon-fortran-wasm-main\hello>lfortran -c --fixed-form --implicit-interface --implicit-typing --target=wasm32-unknown-emscripten hello.f -o hello.o
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
LCompilersException: No available targets are compatible with triple "wasm32-unknown-emscripten"
Maybe need a new version.
That sh file need to be converted to bat file for Windows.
It might also be a bug on Windows in LFortran. I recommend using an AI agent to isolate the bug and report it to us, if it is our bug.
I checked it briefly and it seems like there is a packaging issue on Windows, which is why it wouldn’t work with 0.67.0 either. Maybe you can try WSL2 Ubuntu + LFortran 0.67.0 for now.
I opened a PR in lfortran-feedstock to support the WASM target on Windows: Enable the WASM target on Windows by minhqdao · Pull Request #154 · conda-forge/lfortran-feedstock · GitHub
Thanks.
I compiled it with vs2022 some times ago. I’ll try to compile it with DWITH_TARGET_WASM.
I added -DLFORTRAN_BUILD_TO_WASM=yes
When build, got an error:
emscripten.h is at emsdk\upstream\emscripten\system\include\emscripten, so I copied this folder into lfortran-main\src, then the error gone.
now only the DIA errors.
This removes the DIA error.
C:\Program Files\Microsoft Visual Studio\2022\Community\DIA SDK\lib\amd64\diaguids.lib
Now errors are:
Good progress. Use an AI agent, it can figure all this out for you.
Tried -DWITH_LFORTRAN_ASSERT=NO with a clean build. Now it says:
Including files directly from the emscripten source tree is not supported. Please use the cache/sysroot/include directory
This cache folder is at emsdk\upstream\emscripten\cache
Need to let lfortran uses this:
emsdk\upstream\emscripten\cache\sysroot\include\emscripten\emscripten.h
In lfortran-main\src\bin\lfortran.cpp, make change like this:
#ifdef HAVE_BUILD_TO_WASM
#include <emsdk\upstream\emscripten\cache\sysroot\include\emscripten/emscripten.h>
#endif
emscripten.h is found. But still got the error from em_types.h:
'aligned': identifier not found
This seems a MSVC vs. GCC/Clang (emscripten) Syntax Mismatch.
Maybe I need to start with gcc from the beginning now?


