add server buildsystem base

This commit is contained in:
2025-04-30 20:08:59 +02:00
parent a9dd9bc87c
commit 1065bd1956
9 changed files with 770 additions and 3 deletions

View File

@@ -4,3 +4,9 @@ version = "0.1.0"
edition = "2024"
[dependencies]
http-body-util = "0.1.3"
hyper = { version = "1.6.0", features = ["full"] }
hyper-util = { version = "0.1.11", features = ["full"] }
serde = "1.0.219"
tokio = { version = "1.44.2", features = ["full"] }
toml = "0.8.22"

View File

@@ -0,0 +1,47 @@
macro_rules! argdef {
($(args $argdef_name: ident ($program_name: literal) { $($arg_id: ident),*$(,)? })*) => {
$(
pub struct $argdef_name {
$($arg_id: String),*
}
impl $argdef_name {
pub fn usage() -> &'static str {
concat!("usage: ", $program_name, " ", $("[", stringify!($arg_id), "] "),*)
}
$(pub fn $arg_id(&self) -> &str { &self.$arg_id })*
}
impl TryFrom<&mut std::env::Args> for $argdef_name {
type Error = String;
fn try_from(t: &mut std::env::Args) -> Result<Self, Self::Error> {
let Some(_) = t.next() else {
return Err("missing program execution path".to_string());
};
$(let Some($arg_id) = t.next() else {
let mut err = concat!(
"missing ",
stringify!($arg_id),
" argument\n"
).to_string();
err.push_str(Self::usage());
return Err(err);
};)*
Ok(Args {
$($arg_id),*
})
}
}
),*
}
}
argdef!{
args Args("theseus-server") {
config_path,
}
}

View File

@@ -1,3 +1,22 @@
fn main() {
println!("Hello, world!");
use http_body_util::{combinators::BoxBody, BodyExt, Full};
use hyper::{body::{Bytes, Incoming}, Error, Request, Response};
mod args;
async fn router(
_: Request<Incoming>,
) -> Result<Response<BoxBody<Bytes, Error>>, Error> {
Ok(Response::new(Full::new("test".into()).map_err(|n| match n {}).boxed()))
}
#[tokio::main]
async fn main() {
let args = match args::Args::try_from(&mut std::env::args()) {
Ok(v) => v,
Err(e) => {
eprintln!("{}", e);
return;
}
};
println!("{}", args.config_path());
}