Skip to content

Commit

Permalink
feat: generate java bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Sep 15, 2024
1 parent 500fb5a commit f97117e
Show file tree
Hide file tree
Showing 6 changed files with 2,179 additions and 91 deletions.
100 changes: 14 additions & 86 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/fredszaq/cbindgen", branch = "java-jna-backend" }

[patch.crates-io]
# Remove this patch once the following PR is merged: <https://github.com/xJonathanLEI/starknet-rs/pull/615>
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
4 changes: 2 additions & 2 deletions dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,5 +712,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
4 changes: 2 additions & 2 deletions dojo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,6 @@ void carray_free(void *data, uintptr_t data_len);

void string_free(char *string);

} // extern "C"
} // extern "C"

} // namespace dojo_bindings
} // namespace dojo_bindings
Loading

0 comments on commit f97117e

Please sign in to comment.