From 1b2bab4f424812e72bff37049e90c1fb2b829550 Mon Sep 17 00:00:00 2001 From: Voreck Lukas Date: Fri, 20 Sep 2024 01:35:54 +0200 Subject: [PATCH] Read env var to compile custom service definitions (#18) * Read env var to compile custom service definitions * Document the new env var in the README --- README.md | 6 ++++++ build.rs | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fa536b8..7d42495 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,12 @@ for _ in 0..10 { } ``` +### Using Custom Service Definitions + +If you have a set of custom service definitions, for example from [KRPC.MechJeb](https://github.com/Genhis/KRPC.MechJeb) you can put them all in a directory and point the `KRPC_SERVICES` environment variable to it at build time, this crate will generate a rust client implementation for them. + +Important: If you do this you have to provide *all* service definitions, even the ones this crate usually includes + ### Features * `fmt` (default): Format generated services. Remove for a quicker build producing an unreadable file. * `tokio`: Replace all blocking functions with async functions using the tokio runtime diff --git a/build.rs b/build.rs index 4ea78b9..ce56d18 100644 --- a/build.rs +++ b/build.rs @@ -37,5 +37,13 @@ fn main() { .unwrap(); let mut f = File::create(proto_path.join("services.rs")).unwrap(); - krpc_build::build("service_definitions/", &mut f).unwrap(); + if let Some(path) = env::var("KRPC_SERVICES") + .ok() + .map(|path| Path::new(&path).to_owned()) + .filter(|path| path.exists()) + { + krpc_build::build(path.to_str().unwrap(), &mut f).unwrap(); + } else { + krpc_build::build("service_definitions/", &mut f).unwrap(); + } }