From 8bc0792f1e6ffa1c0c6b4d47bd0da703fd55c297 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 5 Feb 2026 17:18:48 +0800 Subject: [PATCH] feat: add rust binding framework --- Assets/BMapBindings/rusty-bmap/.gitignore | 1 + Assets/BMapBindings/rusty-bmap/Cargo.lock | 70 +++++++++++++++++++ Assets/BMapBindings/rusty-bmap/Cargo.toml | 6 ++ .../rusty-bmap/bmap-sys/Cargo.toml | 9 +++ .../BMapBindings/rusty-bmap/bmap-sys/build.rs | 13 ++++ .../rusty-bmap/bmap-sys/src/lib.rs | 9 +++ .../rusty-bmap/bmap-sys/tests/basic.rs | 7 ++ .../BMapBindings/rusty-bmap/bmap/Cargo.toml | 11 +++ .../BMapBindings/rusty-bmap/bmap/src/lib.rs | 1 + 9 files changed, 127 insertions(+) create mode 100644 Assets/BMapBindings/rusty-bmap/.gitignore create mode 100644 Assets/BMapBindings/rusty-bmap/Cargo.lock create mode 100644 Assets/BMapBindings/rusty-bmap/Cargo.toml create mode 100644 Assets/BMapBindings/rusty-bmap/bmap-sys/Cargo.toml create mode 100644 Assets/BMapBindings/rusty-bmap/bmap-sys/build.rs create mode 100644 Assets/BMapBindings/rusty-bmap/bmap-sys/src/lib.rs create mode 100644 Assets/BMapBindings/rusty-bmap/bmap-sys/tests/basic.rs create mode 100644 Assets/BMapBindings/rusty-bmap/bmap/Cargo.toml create mode 100644 Assets/BMapBindings/rusty-bmap/bmap/src/lib.rs diff --git a/Assets/BMapBindings/rusty-bmap/.gitignore b/Assets/BMapBindings/rusty-bmap/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/Assets/BMapBindings/rusty-bmap/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Assets/BMapBindings/rusty-bmap/Cargo.lock b/Assets/BMapBindings/rusty-bmap/Cargo.lock new file mode 100644 index 0000000..ce7dbc0 --- /dev/null +++ b/Assets/BMapBindings/rusty-bmap/Cargo.lock @@ -0,0 +1,70 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "bmap" +version = "0.4.0" +dependencies = [ + "bmap-sys", + "thiserror", +] + +[[package]] +name = "bmap-sys" +version = "0.4.0" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" diff --git a/Assets/BMapBindings/rusty-bmap/Cargo.toml b/Assets/BMapBindings/rusty-bmap/Cargo.toml new file mode 100644 index 0000000..bf94eed --- /dev/null +++ b/Assets/BMapBindings/rusty-bmap/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] +resolver = "3" +members = ["bmap","bmap-sys"] + +[workspace.dependencies] +thiserror = "2.0.12" diff --git a/Assets/BMapBindings/rusty-bmap/bmap-sys/Cargo.toml b/Assets/BMapBindings/rusty-bmap/bmap-sys/Cargo.toml new file mode 100644 index 0000000..5c3f33a --- /dev/null +++ b/Assets/BMapBindings/rusty-bmap/bmap-sys/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "bmap-sys" +version = "0.4.0" +authors = ["yyc12345"] +edition = "2024" +description = "The Rust binding to BMap." +license = "SPDX:MIT" + +[dependencies] diff --git a/Assets/BMapBindings/rusty-bmap/bmap-sys/build.rs b/Assets/BMapBindings/rusty-bmap/bmap-sys/build.rs new file mode 100644 index 0000000..b0b8a8b --- /dev/null +++ b/Assets/BMapBindings/rusty-bmap/bmap-sys/build.rs @@ -0,0 +1,13 @@ +use std::env; +use std::path::PathBuf; + +fn main() { + // Fetch user specified install directory of built BMap. + let install_dir = env::var("LibCmo_ROOT").expect("You must set LibCmo_ROOT to the install directory of LibCmo built by CMake before building this Rust crate."); + let install_path = PathBuf::from(install_dir); + + // Tell Rust compiler where to find linkd dynamic library. + println!("cargo:rustc-link-search=native={}", install_path.join("lib").display()); + // Tell Rust compiler the name of linked dynamic library. + println!("cargo:rustc-link-lib=dylib=BMap"); +} diff --git a/Assets/BMapBindings/rusty-bmap/bmap-sys/src/lib.rs b/Assets/BMapBindings/rusty-bmap/bmap-sys/src/lib.rs new file mode 100644 index 0000000..f5a3971 --- /dev/null +++ b/Assets/BMapBindings/rusty-bmap/bmap-sys/src/lib.rs @@ -0,0 +1,9 @@ +use std::ffi::{CStr, CString}; +use std::os::raw::{c_float, c_void}; +//use std::ptr; + +#[link(name = "BMap", kind = "dylib")] +unsafe extern "C" { + pub unsafe fn BMInit() -> bool; + pub unsafe fn BMDispose() -> bool; +} diff --git a/Assets/BMapBindings/rusty-bmap/bmap-sys/tests/basic.rs b/Assets/BMapBindings/rusty-bmap/bmap-sys/tests/basic.rs new file mode 100644 index 0000000..328f3cf --- /dev/null +++ b/Assets/BMapBindings/rusty-bmap/bmap-sys/tests/basic.rs @@ -0,0 +1,7 @@ +use bmap_sys; + +#[test] +fn test_init_and_dispose() { + assert!(unsafe { bmap_sys::BMInit() }); + assert!(unsafe { bmap_sys::BMDispose() }); +} diff --git a/Assets/BMapBindings/rusty-bmap/bmap/Cargo.toml b/Assets/BMapBindings/rusty-bmap/bmap/Cargo.toml new file mode 100644 index 0000000..9b41393 --- /dev/null +++ b/Assets/BMapBindings/rusty-bmap/bmap/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "bmap" +version = "0.4.0" +authors = ["yyc12345"] +edition = "2024" +description = "The wrapper for Rust binding to BMap." +license = "SPDX:MIT" + +[dependencies] +thiserror = { workspace = true } +bmap-sys = { path="../bmap-sys" } diff --git a/Assets/BMapBindings/rusty-bmap/bmap/src/lib.rs b/Assets/BMapBindings/rusty-bmap/bmap/src/lib.rs new file mode 100644 index 0000000..c453c6e --- /dev/null +++ b/Assets/BMapBindings/rusty-bmap/bmap/src/lib.rs @@ -0,0 +1 @@ +use bmap_sys;