Add back-end server to template

This commit is contained in:
NGnius 2022-07-30 14:50:42 -04:00
parent 2b192a59b1
commit ac03348e96
5 changed files with 53 additions and 1 deletions

View file

@ -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

View 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

View file

@ -0,0 +1,2 @@
[build]
default-target = "x86_64-unknown-linux-gnu"

View file

@ -0,0 +1,6 @@
#!/bin/bash
cargo build --release
mkdir ../bin
# TODO replace "backend" \/ with binary name
cp ./target/release/backend ../bin/backend

View 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()
}