Skip to content

Commit

Permalink
llgo/rust/readme: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
赵英杰 authored and 赵英杰 committed Jul 17, 2024
1 parent 58ab129 commit 0eb60ea
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions doc/Rust-to-LLGO-Migration-Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -75,26 +80,33 @@ 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
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
Expand Down

0 comments on commit 0eb60ea

Please sign in to comment.