Skip to content
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: bindgen crate #1425

Merged
merged 30 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a48a21c
feat: add first version of plugin-like integration for bindgen
glihm Jan 5, 2024
bd18a66
feat: add unity backend template
glihm Jan 5, 2024
9ea370e
refacto: move the BackendBuilder trait into backends module
glihm Jan 5, 2024
e7f4642
docs: adjust function docs
glihm Jan 5, 2024
cb9f4cf
fix: rename all to plugin for clarity
glihm Jan 6, 2024
fc90287
docs: update README
glihm Jan 6, 2024
8d556dc
docs: fix typos
glihm Jan 6, 2024
feaa9c8
fix: ensure only dojo contracts are excluded from bindgen
glihm Jan 8, 2024
879c5e6
feat: add DojoMetadata with info about models
glihm Jan 8, 2024
e8c2b31
fix: use hashmap instead of vec for models in metadata
glihm Jan 8, 2024
a19c95d
Merge branch 'main' into feat/bindgen
glihm Jan 12, 2024
766b98b
fix: run cairo test fix
glihm Jan 12, 2024
f63b367
fix: remove unused model
glihm Jan 12, 2024
8145d8f
docs: fix docs
glihm Jan 12, 2024
99d6f94
tests: add tests
glihm Jan 12, 2024
d05e74a
fix: bump cainome and work on tests
glihm Jan 12, 2024
ef54527
tests: fix tests
glihm Jan 12, 2024
e9331f5
tests: ensure correct path for test file
glihm Jan 12, 2024
e674fe5
feat: add ensure_abi method into model generated contract
glihm Jan 12, 2024
3678f73
Merge branch 'feat/model-abi' into feat/bindgen
glihm Jan 13, 2024
77e0a45
feat: add generate_models_bindings setup for builtin plugins
glihm Jan 13, 2024
2d17191
Merge remote-tracking branch 'dojo/main' into feat/bindgen
glihm Jan 13, 2024
78a2593
fix: improve code parsing and plugin API
glihm Jan 13, 2024
a342bfc
Merge branch 'main' into feat/bindgen
glihm Jan 16, 2024
a0b5251
feat: identify systems and use new cainome tokenized abi
glihm Jan 16, 2024
f66a75a
tests: fix building with dojo-test-utils + fix tests
glihm Jan 16, 2024
842de67
fix: clean example to have correct class hash
glihm Jan 16, 2024
2c4e4ba
fix: fix tests
glihm Jan 17, 2024
e82b958
chore: bump cainome to 0.2.2 to fix composite details in functions
glihm Jan 17, 2024
c3ab37c
fix: comment out testing until stack error on windows is investigated
glihm Jan 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 82 additions & 6 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"

members = [
"crates/benches",
"crates/dojo-bindgen",
"crates/dojo-core",
"crates/dojo-lang",
"crates/dojo-language-server",
Expand Down
18 changes: 18 additions & 0 deletions crates/dojo-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
description = "Dojo specific bindings generator based on Cainome."
edition.workspace = true
license-file.workspace = true
name = "dojo-bindgen"
repository.workspace = true
version.workspace = true

[dependencies]
async-trait.workspace = true
camino.workspace = true
convert_case.workspace = true
starknet.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true

cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.2.1" }
19 changes: 19 additions & 0 deletions crates/dojo-bindgen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Dojo bindings generator

This crate contains the Dojo bindings generator modules which leverage [cainome](https://github.com/cartridge-gg/cainome) to parse Cairo ABI.

## Architecture

`dojo-bindgen` aims at decoupling at most the knowledge required by `sozo` to output bindings along the contract artifacts. Cainome exposes the `parser` crate, which contains common functions to work with Cairo ABI and generate a list of tokens to have a intermediate representation of the ABI usable at runtime and build logic on top of it to generate the bindings.

[PluginManager](./src/lib.rs): The `PluginManager` is the top level interface that `sozo` uses to request code generation. By providing the artifacts path and the list of plugins (more params in the future), `sozo` indicates which plugin must be invoke to generate the bindings.

[BuiltinPlugin](./src/plugins/mod.rs): The `BuiltinPlugin` are a first lightweight and integrated plugins that are written in rust directly inside this crate. This also comes packaged into the dojo toolchain, ready to be used by developers.

In the future, `dojo-bindgen` will expose a `Plugin` interface similar to protobuf to communicate with a user defined plugin using `stdin` for greater flexibility.

## Builtin Plugins

[Typescript](./src/plugins/typescript/mod.rs)

[Unity](./src/plugins/unity/mod.rs)
16 changes: 16 additions & 0 deletions crates/dojo-bindgen/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use cainome::parser::Error as CainomeError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
IO(#[from] std::io::Error),
#[error(transparent)]
SerdeJson(#[from] serde_json::Error),
#[error(transparent)]
Cainome(#[from] CainomeError),
#[error("Format error: {0}")]
Format(String),
}

pub type BindgenResult<T, E = Error> = Result<T, E>;
Loading
Loading