Skip to content

Commit

Permalink
update codebase and make deploy to shuttle manual:
Browse files Browse the repository at this point in the history
  • Loading branch information
glendc committed Oct 18, 2023
1 parent 0b2674c commit cc2717b
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 152 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/Shuttle.yml

This file was deleted.

24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"nes-studio-app",
"nes-studio",
"nes-studio-website",
]
resolver = "2"
47 changes: 36 additions & 11 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
run:
cargo shuttle run

watch:
cargo watch -x "shuttle run" -i Cargo.lock

deploy:
cargo shuttle deploy

trunk:
check:
cargo check --workspace --all-targets

check-wasm32:
cargo check --workspace --all-features --lib --target wasm32-unknown-unknown

check-fmt:
cargo fmt --all -- --check

clippy:
cargo clippy --workspace --all-targets --all-features -- -D warnings -W clippy::all

test:
cargo test --workspace --all-targets --all-features

test-docs:
cargo test --workspace --doc
cd nes-studio && trunk build

trunk-build:
cd nes-studio-app && trunk build

trunk-watch:
cd nes-studio-app && trunk watch

qa: check check-wasm32 check-fmt clippy test test-docs trunk-build

fmt:
cargo fmt --all

clippy-fix:
cargo clippy --fix --workspace --all-targets --all-features --allow-dirty

fix: fmt clippy-fix

git-push: qa
git push

shuttle-deploy: qa
cargo shuttle deploy

shuttle-watch:
cargo watch -x 'shuttle run' -i 'nes-studio-app,Cargo.lock'
46 changes: 46 additions & 0 deletions nes-studio-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
name = "nes-studio-app"
version = "0.1.0"
authors = ["Glen Henri J. De Cauwsemaecker <[email protected]>"]
edition = "2021"


[dependencies]
egui = "0.23.0"
eframe = { version = "0.23.0", default-features = false, features = [
"accesskit", # Make egui comptaible with screen readers. NOTE: adds a lot of dependencies.
"default_fonts", # Embed the default egui fonts.
"wgpu", # Use the wgpu rendering backend.
"persistence", # Enable restoring app state when restarting the app.
] }
log = "0.4"

# You only need serde if you want app persistence:
serde = { version = "1", features = ["derive"] }

# native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger = "0.10"

# web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"


[profile.release]
opt-level = 2 # fast and small wasm

# Optimize all dependencies even in debug builds:
[profile.dev.package."*"]
opt-level = 2


[patch.crates-io]

# If you want to use the bleeding edge version of egui and eframe:
# egui = { git = "https://github.com/emilk/egui", branch = "master" }
# eframe = { git = "https://github.com/emilk/egui", branch = "master" }

# If you fork https://github.com/emilk/egui you can test with:
# egui = { path = "../egui/crates/egui" }
# eframe = { path = "../egui/crates/eframe" }
File renamed without changes.
6 changes: 3 additions & 3 deletions nes-studio/dist/index.html → nes-studio-app/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<title>NES Studio</title>

<!-- config for our rust wasm binary. go to https://trunkrs.dev/assets/#rust for more customization -->
<script type="module">import init from '/nes-studio-53894f64447dc15a.js';init('/nes-studio-53894f64447dc15a_bg.wasm');</script>
<script type="module">import init from '/nes-studio-app-f98dff9e3f5d751c.js';init('/nes-studio-app-f98dff9e3f5d751c_bg.wasm');</script>
<!-- this is the base url relative to which other urls will be constructed. trunk will insert this from the public-url option -->
<base href="/">

Expand Down Expand Up @@ -106,8 +106,8 @@

</style>

<link rel="preload" href="/nes-studio-53894f64447dc15a_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
<link rel="modulepreload" href="/nes-studio-53894f64447dc15a.js"></head>
<link rel="preload" href="/nes-studio-app-f98dff9e3f5d751c_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
<link rel="modulepreload" href="/nes-studio-app-f98dff9e3f5d751c.js"></head>

<body>
<!-- The WASM code will resize the canvas dynamically -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ async function __wbg_init(input) {
if (wasm !== undefined) return wasm;

if (typeof input === 'undefined') {
input = new URL('nes-studio-53894f64447dc15a_bg.wasm', import.meta.url);
input = new URL('nes-studio-app-f98dff9e3f5d751c_bg.wasm', import.meta.url);
}
const imports = __wbg_get_imports();

Expand Down
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions nes-studio-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#![warn(clippy::all, rust_2018_idioms)]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

// When compiling natively:
#[cfg(not(target_arch = "wasm32"))]
fn main() -> eframe::Result<()> {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).

let native_options = eframe::NativeOptions {
initial_window_size: Some([400.0, 300.0].into()),
min_window_size: Some([300.0, 220.0].into()),
..Default::default()
};
eframe::run_native(
"eframe template",
native_options,
Box::new(|cc| Box::new(nes_studio_app::TemplateApp::new(cc))),
)
}

// When compiling to web using trunk:
#[cfg(target_arch = "wasm32")]
fn main() {
// Redirect `log` message to `console.log` and friends:
eframe::WebLogger::init(log::LevelFilter::Debug).ok();

let web_options = eframe::WebOptions::default();

wasm_bindgen_futures::spawn_local(async {
eframe::WebRunner::new()
.start(
"the_canvas_id", // hardcode it
web_options,
Box::new(|cc| Box::new(nes_studio_app::TemplateApp::new(cc))),
)
.await
.expect("failed to start eframe");
});
}
12 changes: 0 additions & 12 deletions nes-studio-website/Cargo.toml

This file was deleted.

22 changes: 0 additions & 22 deletions nes-studio-website/src/main.rs

This file was deleted.

46 changes: 6 additions & 40 deletions nes-studio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,46 +1,12 @@
[package]
name = "nes-studio"
version = "0.1.0"
authors = ["Glen Henri J. De Cauwsemaecker <[email protected]>"]
edition = "2021"


[dependencies]
egui = "0.23.0"
eframe = { version = "0.23.0", default-features = false, features = [
"accesskit", # Make egui comptaible with screen readers. NOTE: adds a lot of dependencies.
"default_fonts", # Embed the default egui fonts.
"wgpu", # Use the wgpu rendering backend.
"persistence", # Enable restoring app state when restarting the app.
] }
log = "0.4"

# You only need serde if you want app persistence:
serde = { version = "1", features = ["derive"] }

# native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger = "0.10"

# web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"


[profile.release]
opt-level = 2 # fast and small wasm

# Optimize all dependencies even in debug builds:
[profile.dev.package."*"]
opt-level = 2


[patch.crates-io]

# If you want to use the bleeding edge version of egui and eframe:
# egui = { git = "https://github.com/emilk/egui", branch = "master" }
# eframe = { git = "https://github.com/emilk/egui", branch = "master" }

# If you fork https://github.com/emilk/egui you can test with:
# egui = { path = "../egui/crates/egui" }
# eframe = { path = "../egui/crates/eframe" }
axum = "0.6"
shuttle-axum = "0.29"
shuttle-runtime = "0.29"
tokio = "1.28"
tower = { version = "0.4", features = ["tracing"] }
tower-http = { version = "0.4", features = ["fs", "trace", "compression-full", "normalize-path"] }
53 changes: 18 additions & 35 deletions nes-studio/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
#![warn(clippy::all, rust_2018_idioms)]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use std::path::PathBuf;

// When compiling natively:
#[cfg(not(target_arch = "wasm32"))]
fn main() -> eframe::Result<()> {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
use axum::Router;
use tower::ServiceBuilder;
use tower_http::{
compression::CompressionLayer, normalize_path::NormalizePathLayer, services::ServeDir,
trace::TraceLayer,
};

let native_options = eframe::NativeOptions {
initial_window_size: Some([400.0, 300.0].into()),
min_window_size: Some([300.0, 220.0].into()),
..Default::default()
};
eframe::run_native(
"eframe template",
native_options,
Box::new(|cc| Box::new(nes_studio::TemplateApp::new(cc))),
)
}

// When compiling to web using trunk:
#[cfg(target_arch = "wasm32")]
fn main() {
// Redirect `log` message to `console.log` and friends:
eframe::WebLogger::init(log::LevelFilter::Debug).ok();

let web_options = eframe::WebOptions::default();
#[shuttle_runtime::main]
async fn main() -> shuttle_axum::ShuttleAxum {
let router = Router::new()
.nest_service("/", ServeDir::new(PathBuf::from("nes-studio-app/dist")))
.layer(
ServiceBuilder::new()
.layer(TraceLayer::new_for_http())
.layer(CompressionLayer::new())
.layer(NormalizePathLayer::trim_trailing_slash()),
);

wasm_bindgen_futures::spawn_local(async {
eframe::WebRunner::new()
.start(
"the_canvas_id", // hardcode it
web_options,
Box::new(|cc| Box::new(nes_studio::TemplateApp::new(cc))),
)
.await
.expect("failed to start eframe");
});
Ok(router.into())
}

0 comments on commit cc2717b

Please sign in to comment.