-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deserialize extension_api.json and generate code
- Loading branch information
Showing
6 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 1,8 @@ | ||
.vscode | ||
.idea | ||
target/ | ||
Cargo.lock | ||
Cargo.lock | ||
|
||
# Input JSONs and code generation | ||
/gdext-codegen/input/ | ||
/gdext-sys/src/gen/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,55 @@ | ||
use miniserde::{json, Deserialize}; | ||
use quote::quote; | ||
use std::path::Path; | ||
|
||
// ---------------------------------------------------------------------------------------------------------------------------------------------- | ||
// JSON models | ||
|
||
#[derive(Deserialize)] | ||
struct ExtensionApi { | ||
builtin_class_sizes: Vec<ClassSizes>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct ClassSizes { | ||
build_configuration: String, | ||
sizes: Vec<ClassSize>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct ClassSize { | ||
name: String, | ||
size: usize, | ||
} | ||
|
||
// ---------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Implementation | ||
|
||
pub struct ApiParser {} | ||
|
||
impl ApiParser { | ||
pub fn generate_file() { | ||
let tokens = quote! { | ||
struct Constants { | ||
|
||
} | ||
}; | ||
|
||
Self::load_extension_api(); | ||
|
||
let string = tokens.to_string(); | ||
|
||
let _ = std::fs::create_dir("src/gen"); | ||
std::fs::write("src/gen/extensions.rs", string).expect("failed to write extension file"); | ||
} | ||
|
||
fn load_extension_api() { | ||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/input/extension_api.json"); | ||
|
||
let build_config = "float_32"; // TODO infer this | ||
|
||
let json = std::fs::read_to_string(path).expect(&format!("failed to open file {:?}", path)); | ||
println!("JSON: {}", &json[0..30]); | ||
let model: ExtensionApi = json::from_str(&json).expect("failed to deserialize JSON"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 1,7 @@ | ||
mod api_parser; | ||
|
||
pub use api_parser::ApiParser; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters