-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update bindgen for dojo.js sdk #2501
Changes from 5 commits
3471ead
00e942e
6369165
20713d4
4af6821
cf57537
d906cbb
9654818
e2a7957
688bc7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ use std::fmt; | |
use std::path::PathBuf; | ||
|
||
use async_trait::async_trait; | ||
use cainome::parser::tokens::{Composite, Function}; | ||
|
||
use crate::error::BindgenResult; | ||
use crate::DojoData; | ||
use crate::{DojoContract, DojoData}; | ||
|
||
pub mod recs; | ||
pub mod typescript; | ||
pub mod typescript_v2; | ||
pub mod unity; | ||
|
@@ -16,6 +18,7 @@ pub enum BuiltinPlugins { | |
Typescript, | ||
Unity, | ||
TypeScriptV2, | ||
Recs, | ||
} | ||
|
||
impl fmt::Display for BuiltinPlugins { | ||
|
@@ -24,16 +27,49 @@ impl fmt::Display for BuiltinPlugins { | |
BuiltinPlugins::Typescript => write!(f, "typescript"), | ||
BuiltinPlugins::Unity => write!(f, "unity"), | ||
BuiltinPlugins::TypeScriptV2 => write!(f, "typescript_v2"), | ||
BuiltinPlugins::Recs => write!(f, "recs"), | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
pub trait BuiltinPlugin { | ||
pub trait BuiltinPlugin: Sync { | ||
/// Generates code by executing the plugin. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `data` - Dojo data gathered from the compiled project. | ||
async fn generate_code(&self, data: &DojoData) -> BindgenResult<HashMap<PathBuf, Vec<u8>>>; | ||
} | ||
|
||
pub trait BindgenWriter: Sync { | ||
/// Writes the generated code to the specified path. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `code` - The generated code. | ||
fn write(&self, path: &str, data: &DojoData) -> BindgenResult<(PathBuf, Vec<u8>)>; | ||
fn get_path(&self) -> &str; | ||
} | ||
|
||
pub trait BindgenModelGenerator: Sync { | ||
/// Generates code by executing the plugin. | ||
/// The generated code is written to the specified path. | ||
/// This will write file sequentially (for now) so we need one generator per part of the file. | ||
/// (header, type definitions, interfaces, functions and so on) | ||
/// TODO: add &mut ref to what's currently generated to place specific code at specific places. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// | ||
fn generate(&self, token: &Composite, buffer: &mut Vec<String>) -> BindgenResult<String>; | ||
} | ||
|
||
pub trait BindgenContractGenerator: Sync { | ||
fn generate( | ||
&self, | ||
contract: &DojoContract, | ||
token: &Function, | ||
buffer: &mut Vec<String>, | ||
) -> BindgenResult<String>; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document the new code generation traits thoroughly The introduction of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
BuiltinPlugins
documentation to includeRecs
With the addition of the
Recs
variant to theBuiltinPlugins
enum, please ensure that any associated documentation or comments are updated accordingly.