diff --git a/doc/Rust-to-LLGO-Migration-Guide.md b/doc/Rust-to-LLGO-Migration-Guide.md index 253aca82e..809ba9366 100644 --- a/doc/Rust-to-LLGO-Migration-Guide.md +++ b/doc/Rust-to-LLGO-Migration-Guide.md @@ -2,6 +2,8 @@ ### Add Dependencies & Build Configuration +> Take csv_wrapper library as an example + Edit `Cargo.toml` to include necessary dependencies and configuration: ```toml @@ -11,6 +13,9 @@ csv = "1.1" [lib] crate-type = ["cdylib"] # The generated dynamic library will conform to the C standard + +[build-dependencies] +cbindgen = "0.26.0" ``` ### Import C Language Types @@ -75,18 +80,16 @@ pub extern "C" fn free_string(s: *mut c_char) { } ``` -### Compilation and Installation +### Generate Header File -Build the dynamic library and use `dylib-installer` to install it to the system path: +Edit `cbindgen.toml` to configure the header file generation rules: -```sh -cargo build --release -cargo install --git https://github.com/hackerchai/dylib-installer -sudo dylib_installer ./target/release/ +```toml +# See https://github.com/mozilla/cbindgen/blob/master/docs.md#cbindgentoml for +# a list of possible configuration values. +language = "C" ``` -### Generate Header File - Use cbindgen to generate a C header file, automating this process through a `build.rs` script: ```rust @@ -94,7 +97,16 @@ fn main() { let config = cbindgen::Config::from_file("cbindgen.toml").expect("Config file not found."); cbindgen::generate_with_config(&crate_dir, config).unwrap().write_to_file("target/include/csv_wrapper.h"); } +``` + +### Compilation and Installation + +Build the dynamic library and use `dylib-installer` to install it to the system path: +```sh +cargo build --release +cargo install --git https://github.com/hackerchai/dylib-installer +sudo dylib_installer ./target/release/ ``` ### LLGO Package Mapping