Update running project

This commit is contained in:
Rafael Caricio 2020-09-22 10:10:10 +02:00
parent 496cad8aec
commit 62c79d87cc
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
9 changed files with 49 additions and 23 deletions

1
.gitattributes vendored
View file

@ -1 +1,2 @@
include/* linguist-vendored
docs/* linguist-vendored

11
Makefile Normal file
View file

@ -0,0 +1,11 @@
all: web native
web:
cargo +nightly build --release --target wasm32-unknown-emscripten
native:
cargo +nightly build --release
serve:
@echo "Available at http://localhost:8000/lvgl_example.html"
@python3 -m http.server 8000

View file

@ -1,6 +1,8 @@
# LVGL Rust to WASM
Example of LVLG in Rust compiling to WASM.
Example of LVGL in Rust compiling to WASM. The same project can run natively and in the browser.
Access the live version [here](https://rafaelcaricio.github.io/lvgl-rs-wasm).
## Setup
@ -28,11 +30,36 @@ https://emscripten.org/docs/getting_started/downloads.html
$ embuilder.py build sdl2
```
- Compile the example project:
## Compiling
Compile the Web version:
```
cargo +nightly build --target=wasm32-unknown-emscripten
make web
```
References:
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:
```
make serve
```
Now you can access locally the project running at http://localhost:8000/lvgl_example.html .
For running natively, you can do:
```
cargo +nightly run --release
```
# 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
- https://puddleofcode.com/story/definitive-guide-to-rust-sdl2-and-emscriptem

View file

@ -1,17 +0,0 @@
# The default value of `--target` used when building this crate
# in cases where it's not specified on the command line.
default-target = "wasm32-unknown-emscripten"
[cargo-web]
# Asserts the minimum required version of `cargo-web` necessary
# to compile this crate; supported since 0.6.0.
minimum-version = "0.6.0"
# These will only take effect on *-emscripten targets.
[target.emscripten]
# You can have a target-specific `prepend-js` key.
# `prepend-js = "src/emscripten_runtime.js"`
# This will enable Emscripten's SDL2 port. Consult Emscripten's documentation
# for more details.
link-args = ["-s", "USE_SDL=2"]

1
docs/index.html vendored Normal file

File diff suppressed because one or more lines are too long

1
docs/lvgl_example.js vendored Normal file

File diff suppressed because one or more lines are too long

BIN
docs/lvgl_example.wasm vendored Normal file

Binary file not shown.

1
docs/lvgl_example.wasm.map vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -7,8 +7,8 @@ use embedded_graphics_simulator::{
use lvgl::style::Style;
use lvgl::widgets::{Bar, Label, LabelAlign};
use lvgl::{self, Align, Animation, Color, Event, LvError, Part, State, Widget, UI};
use std::time::Instant;
use std::process;
use std::time::{Instant, Duration};
use std::{process, thread};
#[cfg(target_os = "emscripten")]
pub mod emscripten;
@ -78,6 +78,7 @@ fn main() -> Result<(), LvError> {
}
}
thread::sleep(Duration::from_millis(50));
ui.tick_inc(loop_started.elapsed());
loop_started = Instant::now();
};