refactor: merge 2 rust crate in one
This commit is contained in:
@@ -3,17 +3,12 @@
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "bmap"
|
||||
name = "bmap-rs"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"bmap-sys",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bmap-sys"
|
||||
version = "0.4.0"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
@@ -34,9 +29,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.114"
|
||||
version = "2.0.115"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
|
||||
checksum = "6e614ed320ac28113fa64972c4262d5dbc89deacdfd00c34a3e4cea073243c12"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -65,6 +60,6 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.22"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e"
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "bmap-sys"
|
||||
name = "bmap-rs"
|
||||
version = "0.4.0"
|
||||
authors = ["yyc12345"]
|
||||
edition = "2024"
|
||||
@@ -7,3 +7,5 @@ description = "The Rust binding to BMap."
|
||||
license = "SPDX:MIT"
|
||||
|
||||
[dependencies]
|
||||
thiserror = "2.0.12"
|
||||
|
||||
36
Assets/BMapBindings/bmap-rs/README.md
Normal file
36
Assets/BMapBindings/bmap-rs/README.md
Normal 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.
|
||||
@@ -1,3 +1,8 @@
|
||||
//! 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;
|
||||
3
Assets/BMapBindings/bmap-rs/src/bmap_wrapper.rs
Normal file
3
Assets/BMapBindings/bmap-rs/src/bmap_wrapper.rs
Normal 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.
|
||||
3
Assets/BMapBindings/bmap-rs/src/lib.rs
Normal file
3
Assets/BMapBindings/bmap-rs/src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod virtools_types;
|
||||
pub mod bmap;
|
||||
pub mod bmap_wrapper;
|
||||
1
Assets/BMapBindings/bmap-rs/src/virtools_types.rs
Normal file
1
Assets/BMapBindings/bmap-rs/src/virtools_types.rs
Normal file
@@ -0,0 +1 @@
|
||||
//! The module conatins all basic Virtools types used by BMap native FFI calling.
|
||||
7
Assets/BMapBindings/bmap-rs/tests/basic.rs
Normal file
7
Assets/BMapBindings/bmap-rs/tests/basic.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use bmap_rs::bmap;
|
||||
|
||||
#[test]
|
||||
fn test_init_and_dispose() {
|
||||
assert!(unsafe { bmap::BMInit() });
|
||||
assert!(unsafe { bmap::BMDispose() });
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## Layout
|
||||
|
||||
This project follow `src` and `test` layout and is managed by Astral UV.
|
||||
This project follows `src` and `test` layout and is managed by Astral UV.
|
||||
The source code of pybmap is located inside `src`.
|
||||
And the files located in `test` is used for testing.
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
members = ["bmap","bmap-sys"]
|
||||
|
||||
[workspace.dependencies]
|
||||
thiserror = "2.0.12"
|
||||
@@ -1,7 +0,0 @@
|
||||
use bmap_sys;
|
||||
|
||||
#[test]
|
||||
fn test_init_and_dispose() {
|
||||
assert!(unsafe { bmap_sys::BMInit() });
|
||||
assert!(unsafe { bmap_sys::BMDispose() });
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
[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" }
|
||||
@@ -1 +0,0 @@
|
||||
use bmap_sys;
|
||||
@@ -31,6 +31,8 @@ target_compile_definitions(BMap
|
||||
PRIVATE
|
||||
BMAP_EXPORTING
|
||||
)
|
||||
# Remove any possible prefix (such as `lib` on Linux)
|
||||
set_target_properties(BMap PROPERTIES PREFIX "")
|
||||
|
||||
# Install binary and headers
|
||||
install(TARGETS BMap
|
||||
|
||||
@@ -9,7 +9,7 @@ When bumping a new version, you should update the version number in following fi
|
||||
* `CMakeLists.txt`: It control the version of `LibCmo`, `Unvirt`, `BMap` and `BMapInspector`. All of these projects share the same version.
|
||||
* `Assets/BMapBindings/pybmap/pyproject.toml`: The version of `BMap` Python binding. It should have the same version with `BMap` but not compelled.
|
||||
* `Assets/BMapBindings/BMapSharp/BMapSharp/BMapSharp.csproj`: The version of `BMap` C# binding. Same as above.
|
||||
* TODO
|
||||
* `Assets/BMapBindings/bmap-rs/Cargo.toml`: The version of `BMap` Rust binding. Same as above.
|
||||
|
||||
## Java
|
||||
|
||||
|
||||
@@ -118,6 +118,8 @@ PUBLIC
|
||||
"$<$<CONFIG:Debug>:LIBCMO_BUILD_DEBUG>"
|
||||
"$<$<CONFIG:Release,RelWithDebInfo,MinSize>:LIBCMO_BUILD_RELEASE>"
|
||||
)
|
||||
# Remove any possible prefix (such as `lib` on Linux)
|
||||
set_target_properties(LibCmo PROPERTIES PREFIX "")
|
||||
|
||||
# Install binary and headers
|
||||
install(TARGETS LibCmo
|
||||
|
||||
Reference in New Issue
Block a user