Skip to content

Latest commit

 

History

History
136 lines (95 loc) · 2.91 KB

README.md

File metadata and controls

136 lines (95 loc) · 2.91 KB

Emscripten

Install

Install CMake, LLVM, Clang, Node, Python

  • rurumimic/supply/tools
  • rurumimic/supply/node: v16
  • rurumimic/supply/python: v3.11

Install emsdk

cd ~/.local/share

git clone https://github.com/emscripten-core/emsdk.git

# delete:
# rm -rf ~/.local/share/emsdk
# ~/.zshrc
export PATH="$PATH:$HOME/.local/share/emsdk"
export EMSDK_QUIET=1
source $HOME/.local/share/emsdk/emsdk_env.sh

Install Tools

emsdk list
emsdk install emscripten-main-64bit binaryen-main-64bit
emsdk activate emscripten-main-64bit binaryen-main-64bit

Check Installation

emsdk list

The following tools can be compiled from source:
    (*)    emscripten-main-64bit     INSTALLED
    (*)    binaryen-main-64bit       INSTALLED

Items marked with * are activated for the current user.
Items marked with (*) are selected for use, but your current shell environment is not configured to use them. Type "source ./emsdk_env.sh" to set up your current shell to use them.
emsdk help
emsdk help
emcc version
emcc -v

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.35-git (de7cbc56c3ac38b83cc3e8bbc17ac5fbb6b3bbd7)
Ubuntu clang version 17.0.0 (++20230326042432+943df86c82b1-1~exp1~20230326042544.827)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/bin

Hello World

src/helloworld/main.c:

#include <stdio.h>

int main() {
  printf("Hello, World!\n");
  return 0;
}

Compile C

emcc main.c
helloworld/
├── a.out.js
├── a.out.wasm
└── main.c

0 directories, 3 files

Run Javascript:

node a.out.js

Hello, World!

Compile HTML

emcc main.c -o index.html

Run a Local Server: localhost:8000

python -m http.server

Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
127.0.0.1 - - [24/Feb/2023 20:53:00] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Feb/2023 20:53:00] "GET /index.js HTTP/1.1" 200 -
127.0.0.1 - - [24/Feb/2023 20:53:00] "GET /index.wasm HTTP/1.1" 200 -

helloworld