Skip to content

Commit

Permalink
Proper way to generate code from build.rs (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo authored Mar 21, 2024
1 parent 26088bf commit 123f15b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion golem-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ tracing = "^0.1"
uuid = { version = "^1.6", features = ["serde"] }

[build-dependencies]
golem-openapi-client-generator = "0.0.3"
golem-openapi-client-generator = "0.0.4"
14 changes: 12 additions & 2 deletions golem-client/build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
use std::env::var_os;
use std::path::Path;

use golem_openapi_client_generator::parse_openapi_specs;

fn main() {
println!("Starting code generation for Golem OpenAPI client.");
let out_dir = var_os("OUT_DIR").unwrap();

println!("Output directory: {:?}", out_dir);

golem_openapi_client_generator::gen(
parse_openapi_specs(&[Path::new("../openapi/golem-service.yaml").to_path_buf()])
.expect("Failed to parse OpenAPI spec."),
Path::new("."),
Path::new(&out_dir),
"golem-client",
"0.0.0",
false,
true,
)
.expect("Failed to generate client code from OpenAPI spec.")
.expect("Failed to generate client code from OpenAPI spec.");

println!("cargo::rerun-if-changed=build.rs");
println!("cargo::rerun-if-changed=../openapi/golem-service.yaml");
}
2 changes: 1 addition & 1 deletion golem-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@

include!(concat!(env!("OUT_DIR"), "/src/lib.rs"));

0 comments on commit 123f15b

Please sign in to comment.