diff --git a/Assets/BMapBindings/rusty-bmap/.gitignore b/Assets/BMapBindings/bmap-rs/.gitignore similarity index 100% rename from Assets/BMapBindings/rusty-bmap/.gitignore rename to Assets/BMapBindings/bmap-rs/.gitignore diff --git a/Assets/BMapBindings/rusty-bmap/Cargo.lock b/Assets/BMapBindings/bmap-rs/Cargo.lock similarity index 83% rename from Assets/BMapBindings/rusty-bmap/Cargo.lock rename to Assets/BMapBindings/bmap-rs/Cargo.lock index ce7dbc0..06a15ed 100644 --- a/Assets/BMapBindings/rusty-bmap/Cargo.lock +++ b/Assets/BMapBindings/bmap-rs/Cargo.lock @@ -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" diff --git a/Assets/BMapBindings/rusty-bmap/bmap-sys/Cargo.toml b/Assets/BMapBindings/bmap-rs/Cargo.toml similarity index 79% rename from Assets/BMapBindings/rusty-bmap/bmap-sys/Cargo.toml rename to Assets/BMapBindings/bmap-rs/Cargo.toml index 5c3f33a..22aaa6b 100644 --- a/Assets/BMapBindings/rusty-bmap/bmap-sys/Cargo.toml +++ b/Assets/BMapBindings/bmap-rs/Cargo.toml @@ -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" + diff --git a/Assets/BMapBindings/bmap-rs/README.md b/Assets/BMapBindings/bmap-rs/README.md new file mode 100644 index 0000000..537f6d9 --- /dev/null +++ b/Assets/BMapBindings/bmap-rs/README.md @@ -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. diff --git a/Assets/BMapBindings/rusty-bmap/bmap-sys/build.rs b/Assets/BMapBindings/bmap-rs/build.rs similarity index 100% rename from Assets/BMapBindings/rusty-bmap/bmap-sys/build.rs rename to Assets/BMapBindings/bmap-rs/build.rs diff --git a/Assets/BMapBindings/rusty-bmap/bmap-sys/src/lib.rs b/Assets/BMapBindings/bmap-rs/src/bmap.rs similarity index 51% rename from Assets/BMapBindings/rusty-bmap/bmap-sys/src/lib.rs rename to Assets/BMapBindings/bmap-rs/src/bmap.rs index 2ff3957..4529017 100644 --- a/Assets/BMapBindings/rusty-bmap/bmap-sys/src/lib.rs +++ b/Assets/BMapBindings/bmap-rs/src/bmap.rs @@ -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; diff --git a/Assets/BMapBindings/bmap-rs/src/bmap_wrapper.rs b/Assets/BMapBindings/bmap-rs/src/bmap_wrapper.rs new file mode 100644 index 0000000..7260d59 --- /dev/null +++ b/Assets/BMapBindings/bmap-rs/src/bmap_wrapper.rs @@ -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. diff --git a/Assets/BMapBindings/bmap-rs/src/lib.rs b/Assets/BMapBindings/bmap-rs/src/lib.rs new file mode 100644 index 0000000..01b3081 --- /dev/null +++ b/Assets/BMapBindings/bmap-rs/src/lib.rs @@ -0,0 +1,3 @@ +pub mod virtools_types; +pub mod bmap; +pub mod bmap_wrapper; diff --git a/Assets/BMapBindings/bmap-rs/src/virtools_types.rs b/Assets/BMapBindings/bmap-rs/src/virtools_types.rs new file mode 100644 index 0000000..c3517ff --- /dev/null +++ b/Assets/BMapBindings/bmap-rs/src/virtools_types.rs @@ -0,0 +1 @@ +//! The module conatins all basic Virtools types used by BMap native FFI calling. diff --git a/Assets/BMapBindings/bmap-rs/tests/basic.rs b/Assets/BMapBindings/bmap-rs/tests/basic.rs new file mode 100644 index 0000000..5ea7a1f --- /dev/null +++ b/Assets/BMapBindings/bmap-rs/tests/basic.rs @@ -0,0 +1,7 @@ +use bmap_rs::bmap; + +#[test] +fn test_init_and_dispose() { + assert!(unsafe { bmap::BMInit() }); + assert!(unsafe { bmap::BMDispose() }); +} diff --git a/Assets/BMapBindings/pybmap/README.md b/Assets/BMapBindings/pybmap/README.md index 09be203..451d779 100644 --- a/Assets/BMapBindings/pybmap/README.md +++ b/Assets/BMapBindings/pybmap/README.md @@ -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. diff --git a/Assets/BMapBindings/rusty-bmap/Cargo.toml b/Assets/BMapBindings/rusty-bmap/Cargo.toml deleted file mode 100644 index bf94eed..0000000 --- a/Assets/BMapBindings/rusty-bmap/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[workspace] -resolver = "3" -members = ["bmap","bmap-sys"] - -[workspace.dependencies] -thiserror = "2.0.12" diff --git a/Assets/BMapBindings/rusty-bmap/bmap-sys/tests/basic.rs b/Assets/BMapBindings/rusty-bmap/bmap-sys/tests/basic.rs deleted file mode 100644 index 328f3cf..0000000 --- a/Assets/BMapBindings/rusty-bmap/bmap-sys/tests/basic.rs +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 9b41393..0000000 --- a/Assets/BMapBindings/rusty-bmap/bmap/Cargo.toml +++ /dev/null @@ -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" } diff --git a/Assets/BMapBindings/rusty-bmap/bmap/src/lib.rs b/Assets/BMapBindings/rusty-bmap/bmap/src/lib.rs deleted file mode 100644 index c453c6e..0000000 --- a/Assets/BMapBindings/rusty-bmap/bmap/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -use bmap_sys; diff --git a/Ballance/BMap/CMakeLists.txt b/Ballance/BMap/CMakeLists.txt index 8842119..9be4ff4 100644 --- a/Ballance/BMap/CMakeLists.txt +++ b/Ballance/BMap/CMakeLists.txt @@ -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 diff --git a/DEVNOTE.md b/DEVNOTE.md index c12f66d..9ac03bb 100644 --- a/DEVNOTE.md +++ b/DEVNOTE.md @@ -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 diff --git a/LibCmo/CMakeLists.txt b/LibCmo/CMakeLists.txt index 83d7b3a..f73ba3c 100644 --- a/LibCmo/CMakeLists.txt +++ b/LibCmo/CMakeLists.txt @@ -118,6 +118,8 @@ PUBLIC "$<$:LIBCMO_BUILD_DEBUG>" "$<$: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