lvgl-rs-wasm/README.md

68 lines
1.5 KiB
Markdown
Raw Permalink Normal View History

2020-09-21 18:08:31 +00:00
# LVGL Rust to WASM
2020-09-21 17:33:08 +00:00
2020-09-22 08:10:10 +00:00
Example of LVGL in Rust compiling to WASM. The same project can run natively and in the browser.
2020-09-22 08:17:51 +00:00
Access the web live version [here](https://rafaelcaricio.github.io/lvgl-rs-wasm).
![Project Running Natively](docs/images/native.png)
2020-09-21 17:33:08 +00:00
## Setup
2020-09-21 18:00:48 +00:00
- Install Emscripten
```
# Get the emsdk repo
git clone https://github.com/emscripten-core/emsdk.git
# Enter that directory
cd emsdk
# Download and install the latest SDK tools.
./emsdk install latest
# Make the "latest" SDK "active" for the current user. (writes .emscripten file)
./emsdk activate latest
2020-09-21 17:33:08 +00:00
2020-09-21 18:00:48 +00:00
# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh
```
https://emscripten.org/docs/getting_started/downloads.html
- Compile SDL2:
2020-09-21 17:33:08 +00:00
```
$ embuilder.py build sdl2
```
2020-09-21 18:00:48 +00:00
2020-09-22 08:10:10 +00:00
## Compiling
Compile the Web version:
```
make web
```
Compile the native version:
```
make native
```
## Running
To access the web version you need to serve the static files as web pages locally. We use `python3` for that. If you
have [Python 3](https://www.python.org/downloads/) installed, you can run:
2020-09-21 18:53:30 +00:00
```
2020-09-22 08:10:10 +00:00
make serve
2020-09-21 18:53:30 +00:00
```
2020-09-22 08:10:10 +00:00
Now you can access locally the project running at http://localhost:8000/lvgl_example.html .
For running natively, you can do:
```
2020-09-24 13:10:22 +00:00
cargo run --release
2020-09-22 08:10:10 +00:00
```
# References
- https://gregkatz.github.io/2017-05-20-rust-emscripten.html
- https://dev.to/kibebr/i-made-a-game-in-c-run-in-a-web-browser-and-so-can-you-4deb
2020-09-21 18:00:48 +00:00
- https://puddleofcode.com/story/definitive-guide-to-rust-sdl2-and-emscriptem