From ef0f8de88b248426ded703b710875c57d13dae1d Mon Sep 17 00:00:00 2001
From: Tristan F <26509014+LeoDog896@users.noreply.github.com>
Date: Sat, 1 Jun 2024 12:11:17 -0400
Subject: [PATCH] chore: set up & build web app
---
.github/workflows/deploy.yml | 11 +++++++++++
.gitignore | 2 +-
Cargo.lock | 4 ++++
crates/game-solver/Cargo.toml | 1 +
crates/games-ui/Cargo.toml | 10 +++++++++-
crates/games-ui/index.html | 15 +--------------
crates/games-ui/src/main.rs | 2 +-
7 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 8dfa0fb..dd56f00 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -52,6 +52,17 @@ jobs:
run: |
cp book/banner.webp dist/banner.webp
cp book/landing.html dist/index.html
+ - name: Download and install Trunk binary
+ run: wget -qO- https://github.com/thedodd/trunk/releases/latest/download/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf-
+ - name: Build Web App
+ run: ./trunk build --release --public-url $public_url
+ working-directory: crates/games-ui
+ env:
+ public_url: "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/app"
+ - name: Copy Web App
+ run: |
+ mkdir dist/app
+ cp -r ./crates/games-ui/dist/*
- name: Setup Pages
uses: actions/configure-pages@v2
- name: Upload artifact
diff --git a/.gitignore b/.gitignore
index fcb94ea..1a6f3e5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
/target
/book/book
-/dist
+dist
/doc
# performance
diff --git a/Cargo.lock b/Cargo.lock
index d9bbe3e..84a97b3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1562,6 +1562,7 @@ dependencies = [
"egui",
"env_logger",
"game-solver",
+ "log",
"serde",
"wasm-bindgen-futures",
]
@@ -1710,8 +1711,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
+ "js-sys",
"libc",
"wasi",
+ "wasm-bindgen",
]
[[package]]
@@ -3347,6 +3350,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d"
dependencies = [
"getrandom",
+ "wasm-bindgen",
]
[[package]]
diff --git a/crates/game-solver/Cargo.toml b/crates/game-solver/Cargo.toml
index c760a0d..b6eeb09 100644
--- a/crates/game-solver/Cargo.toml
+++ b/crates/game-solver/Cargo.toml
@@ -12,6 +12,7 @@ edition = "2021"
"xxhash" = ["dep:twox-hash"]
"rayon" = ["dep:rayon", "xxhash", "dep:sysinfo", "dep:moka"]
"reinforcement" = ["dep:rand", "dep:dfdx", "dep:itertools"]
+"js" = ["moka/js"]
[dependencies]
dfdx = { git = "https://github.com/coreylowman/dfdx.git", rev = "4722a99", optional = true }
diff --git a/crates/games-ui/Cargo.toml b/crates/games-ui/Cargo.toml
index 16d881b..ae396e3 100644
--- a/crates/games-ui/Cargo.toml
+++ b/crates/games-ui/Cargo.toml
@@ -12,11 +12,19 @@ eframe = { version = "0.27.2", default-features = false, features = [
"persistence"
]}
egui = "0.27"
-game-solver = { path = "../game-solver", features = ["rayon", "reinforcement"] }
serde = { version = "1", features = ["derive"] }
+log = "0.4"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger = "0.11"
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
+
+[target.'cfg(not(target_arch = "wasm32"))'.dependencies.game-solver]
+path = "../game-solver"
+features = ["rayon", "reinforcement"]
+
+[target.'cfg(target_arch = "wasm32")'.dependencies.game-solver]
+path = "../game-solver"
+features = ["rayon", "reinforcement", "js"]
diff --git a/crates/games-ui/index.html b/crates/games-ui/index.html
index 872b4f4..9b3b8c8 100644
--- a/crates/games-ui/index.html
+++ b/crates/games-ui/index.html
@@ -13,20 +13,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/crates/games-ui/src/main.rs b/crates/games-ui/src/main.rs
index 44401b7..6a339fe 100644
--- a/crates/games-ui/src/main.rs
+++ b/crates/games-ui/src/main.rs
@@ -32,7 +32,7 @@ fn main() {
.start(
"the_canvas_id", // hardcode it
web_options,
- Box::new(|cc| Box::new(eframe_template::TemplateApp::new(cc))),
+ Box::new(|cc| Box::new(games_ui::TemplateApp::new(cc))),
)
.await
.expect("failed to start eframe");