https://github.com/elcritch/cheerp
Nim wrapper for Cheerp (experimental)
https://github.com/elcritch/cheerp
Last synced: about 2 months ago
JSON representation
Nim wrapper for Cheerp (experimental)
- Host: GitHub
- URL: https://github.com/elcritch/cheerp
- Owner: elcritch
- Created: 2023-03-15T05:30:29.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-16T03:48:00.000Z (over 2 years ago)
- Last Synced: 2025-08-01T03:03:43.237Z (2 months ago)
- Language: Nim
- Homepage:
- Size: 327 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cheerp
Quick experimental wrapper for Cheerp. Unfortunately, `[[cheerp::genericjs]]` functions don't work with Nim's C++ output. However, Cheerp's clang++ output works well with compiling Nim to WASM.
Here's an example `config.nims` setup:
```nim
switch("path", "$projectDir/../src")
# --compileOnly
--noMain
--cpu:arm
--os:standalone
--d:useMalloc
--mm:arc
--nimcache:nimcache
--cc:clangswitch("clang.exe", "/Applications/cheerp/bin/clang")
switch("clang.cpp.exe", "/Applications/cheerp/bin/clang++")
switch("clang.linkerexe", "/Applications/cheerp/bin/clang")
switch("clang.cpp.linkerexe", "/Applications/cheerp/bin/clang++")switch("clang.options.linker", " ")
switch("clang.cpp.options.linker", " ")switch("clang.options.always", "--target=cheerp-wasm -fexceptions -cheerp-linear-heap-size=128")
switch("clang.cpp.options.always", "--target=cheerp-wasm -fexceptions -cheerp-linear-heap-size=128")# switch("define", "StandaloneHeapSize:1_048_576")
```
Here's an example Nim code for calling `console.log` from a Nim WASM program:
```nim
{.emit: """
[[cheerp::genericjs]] void domOutput(const char* str)
{
client::console.log(str);
}
""".}proc domOutput(msg: cstring) {.importc, header: "cheerp/clientlib.h".}
# proc printf(frmt: cstring) {.varargs, importc, header: "", cdecl.}# webMain is the entry point for web applications written in Cheerp
proc webMain() {.exportc.} =
# printf "hello world\n"
domOutput("hello world!")```