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: generate java bindings #56

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
106 changes: 17 additions & 89 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ instant = { version = "0.1.13", features = ["wasm-bindgen"] }
gloo-timers = { version = "0.3.0", features = ["futures"] }

[build-dependencies]
cbindgen = "0.26.0"
cbindgen = { git = "https://github.com/Larkooo/cbindgen", branch = "java-jna-backend" }

[patch.crates-io]
# Matching the same rev that `cainome` is using. Mainly because `starknet-rs` hasn't create a new release yet.
Expand Down
35 changes: 35 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,41 @@ fn main() {
.expect("Unable to generate bindings")
.write_to_file("dojo.pyx");

cbindgen::Builder::new()
.with_config({
let mut config = cbindgen::Config::default();

config.language = cbindgen::Language::JavaJna;
config.braces = cbindgen::Braces::SameLine;
config.style = cbindgen::Style::Both;
config.layout = cbindgen::LayoutConfig { ..Default::default() };
config.enumeration = cbindgen::EnumConfig {
derive_helper_methods: true,
// prefix_with_name: true,
..Default::default()
};
config.export = cbindgen::ExportConfig {
mangle: cbindgen::MangleConfig { remove_underscores: true, ..Default::default() },
..Default::default()
};

// config.structure.derive_constructor = true;
// config.structure.derive_eq = true;
config.namespace = Some("dojo_bindings".to_string());

config.defines = HashMap::new();
config.defines.insert(
"target_pointer_width = 32".to_string(),
"TARGET_POINTER_WIDTH_32".to_string(),
);

config
})
.with_crate(crate_dir.clone())
.generate()
.expect("Unable to generate bindings")
.write_to_file("dojo.java");

// NOTE: disable for now. use c2cs to generate csharp bindings
// generics not supported
// csbindgen::Builder::default()
Expand Down
16 changes: 2 additions & 14 deletions dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ typedef enum Primitive_Tag {
U32,
U64,
U128,
#if !defined(TARGET_POINTER_WIDTH_32)
U256,
#endif
#if defined(TARGET_POINTER_WIDTH_32)
U256,
#endif
USize,
Bool,
Felt252,
Expand Down Expand Up @@ -139,16 +134,9 @@ typedef struct Primitive {
struct {
uint8_t u128[16];
};
#if !defined(TARGET_POINTER_WIDTH_32)
struct {
uint64_t u256[4];
};
#endif
#if defined(TARGET_POINTER_WIDTH_32)
struct {
uint32_t u256[8];
};
#endif
struct {
uint32_t u_size;
};
Expand Down Expand Up @@ -729,5 +717,5 @@ void carray_free(void *data, uintptr_t data_len);
void string_free(char *string);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
} // extern "C"
#endif // __cplusplus
Loading
Loading