1
0

refactor: merge 2 rust crate in one

This commit is contained in:
2026-02-15 11:41:23 +08:00
parent ade1eadd50
commit 763255d2a7
18 changed files with 69 additions and 38 deletions

View File

@@ -0,0 +1 @@
/target

65
Assets/BMapBindings/bmap-rs/Cargo.lock generated Normal file
View File

@@ -0,0 +1,65 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "bmap-rs"
version = "0.4.0"
dependencies = [
"thiserror",
]
[[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.115"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e614ed320ac28113fa64972c4262d5dbc89deacdfd00c34a3e4cea073243c12"
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.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e"

View File

@@ -0,0 +1,11 @@
[package]
name = "bmap-rs"
version = "0.4.0"
authors = ["yyc12345"]
edition = "2024"
description = "The Rust binding to BMap."
license = "SPDX:MIT"
[dependencies]
thiserror = "2.0.12"

View File

@@ -0,0 +1,36 @@
# bmap-rs
## Layout
This project follows standard Rust project layout.
Source code are located in `src` directory and test code are in `tests` directory.
Please note that the raw FFI functions and the wrapper of it are placed in the single project,
not like other Rust project that raw bindings and wrapper are put into 2 different project,
one of them is ended with `-sys` and another one is not.
This is a considerable decision due to the following reasons:
- I want this project has same pattern with other bindings. In other bindings, FFI binding code and wrapper are put together.
- They (FFI binding and wrapper) can not be easily splitted due to logic reasons. Putting them together can avoid some extra work.
## Native BMap Library Location
This project uses native way (native compiler and linker) to link the BMap library.
This is different with other bindings.
> [!IMPORTANT]
> We highly suggest that you make sure that the toolchain building your BMap is same as your configured Rust toolchain.
> Although BMap is a dynamic library and its function is exposed as C function, the link issue may still occurs due to the different toolchain.
According to this, you should set `LibCmo_ROOT` environment variable pointing to the CMake install directory of LibCmo with built BMap before configuring this Rust project.
This project will find it in `build.rs` script and tell Rust compiler how to link it.
> [!IMPORTANT]
> For Linux and macOS user, you may need manually to rename the final built BMap artifact.
> Because in these platforms, CMake produced BMap dynamic library may have `lib` prefix in its name.
> This can not be recognized by our build script.
>
> You should rename it to `BMap.so` or `BMap.dylib` depending on your platform.
> You also may need rename some contents of other files involving this rename change.
Also due to this, when distributing your Rust project, please do not forget copy the built BMap library with your Rust artifacts.

View File

@@ -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");
}

View File

@@ -0,0 +1,15 @@
//! The module contains raw FFI bindings to native BMap library.
//!
//! For the user of this library, use `bmap_wrapper` instead of this module,
//! except you really need these raw calling and know what you are doing.
use std::ffi::{CStr, CString};
use std::os::raw::{c_float, c_void};
//use std::ptr;
#[rustfmt::skip]
#[link(name = "BMap", kind = "dylib")]
unsafe extern "C" {
pub unsafe fn BMInit() -> bool;
pub unsafe fn BMDispose() -> bool;
}

View File

@@ -0,0 +1,3 @@
//! The module includes all senior wrappers for BMap FFI calling in Rust style.
//!
//! This module is what user of this library should use.

View File

@@ -0,0 +1,3 @@
pub mod virtools_types;
pub mod bmap;
pub mod bmap_wrapper;

View File

@@ -0,0 +1 @@
//! The module conatins all basic Virtools types used by BMap native FFI calling.

View File

@@ -0,0 +1,7 @@
use bmap_rs::bmap;
#[test]
fn test_init_and_dispose() {
assert!(unsafe { bmap::BMInit() });
assert!(unsafe { bmap::BMDispose() });
}