Skip to content

Commit

Permalink
Read env var to compile custom service definitions (#18)
Browse files Browse the repository at this point in the history
* Read env var to compile custom service definitions

* Document the new env var in the README
  • Loading branch information
VoreckLukas authored Sep 19, 2024
1 parent f3d64e0 commit 1b2bab4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 1b2bab4

Please sign in to comment.