Add back-end server to template
This commit is contained in:
parent
2b192a59b1
commit
ac03348e96
5 changed files with 53 additions and 1 deletions
2
templates/decky/.gitignore
vendored
2
templates/decky/.gitignore
vendored
|
@ -42,7 +42,7 @@ yalc.lock
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
|
|
||||||
# ignore Rust compiler files
|
# ignore Rust compiler files
|
||||||
/backend-rs/target
|
/server/target
|
||||||
backend
|
backend
|
||||||
/bin
|
/bin
|
||||||
|
|
||||||
|
|
19
templates/decky/server/Cargo.toml
Normal file
19
templates/decky/server/Cargo.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[package]
|
||||||
|
name = "backend" # TODO replace with plugin name (also in build.sh)
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
usdpl-back = { version = "0.5.3", features = ["decky"] }
|
||||||
|
|
||||||
|
# logging
|
||||||
|
log = "0.4"
|
||||||
|
simplelog = "0.12"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
debug = false
|
||||||
|
strip = true
|
||||||
|
lto = true
|
||||||
|
codegen-units = 4
|
2
templates/decky/server/Cross.toml
Normal file
2
templates/decky/server/Cross.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[build]
|
||||||
|
default-target = "x86_64-unknown-linux-gnu"
|
6
templates/decky/server/build.sh
Executable file
6
templates/decky/server/build.sh
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cargo build --release
|
||||||
|
mkdir ../bin
|
||||||
|
# TODO replace "backend" \/ with binary name
|
||||||
|
cp ./target/release/backend ../bin/backend
|
25
templates/decky/server/src/main.rs
Normal file
25
templates/decky/server/src/main.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
use simplelog::{WriteLogger, LevelFilter};
|
||||||
|
|
||||||
|
use usdpl_back::Instance;
|
||||||
|
use usdpl_back::core::serdes::Primitive;
|
||||||
|
|
||||||
|
const PORT: u16 = 54321; // TODO replace with something unique
|
||||||
|
|
||||||
|
const PACKAGE_NAME: &'static str = env!("CARGO_PKG_NAME");
|
||||||
|
const PACKAGE_VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
fn main() -> Result<(), ()> {
|
||||||
|
let log_filepath = format!("/tmp/{}.log", PACKAGE_NAME);
|
||||||
|
WriteLogger::init(
|
||||||
|
#[cfg(debug_assertions)]{LevelFilter::Debug},
|
||||||
|
#[cfg(not(debug_assertions))]{LevelFilter::Info},
|
||||||
|
Default::default(),
|
||||||
|
std::fs::File::create(&log_filepath).unwrap()
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
log::info!("Starting back-end ({} v{})", PACKAGE_NAME, PACKAGE_VERSION);
|
||||||
|
println!("Starting back-end ({} v{})", PACKAGE_NAME, PACKAGE_VERSION);
|
||||||
|
Instance::new(PORT)
|
||||||
|
.register("hello", |_: Vec<Primitive>| vec![format!("Hello {}", PACKAGE_NAME).into()])
|
||||||
|
.run_blocking()
|
||||||
|
}
|
Loading…
Reference in a new issue