brenomfviana / ffiapi-rust

This repository contains codes for learning to build FFI APIs in Rust for C++ and C#.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rust ffiapis for C++ and C#

This repository contains codes for learning to build FFI APIs in Rust for C++ and C#. There is only one memory leak in this library. The cause of this leak is the println macro, which is called in the function print_rust. More details in the following link: rust-lang/rust#19776.

How to compile the library

cargo build

C++

Generating C++ header

cbindgen --config cbindgen.toml --crate ffiapi --output include/ffiapi.h

Compiling C++ code

Add the library in the LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/home/breno/Documents/Workspace/Projects/rust_for_cpp/target/debug:$LD_LIBRARY_PATH

Using the library in C++ code

g++ --std=c++11 -o target/test examples/test.cpp -Ltarget/debug/ -lffiapi

or

g++ --std=c++11 -o target/test examples/test.cpp target/debug/libffiapi.so

Compile and test

reset && cargo build && cbindgen --config cbindgen.toml --crate ffiapi --output include/ffiapi.h && g++ --std=c++11 -o target/test examples/test.cpp -Ltarget/debug/ -lffiapi && valgrind ./target/test

C#

Compile and test

reset && cargo build && dotnet run

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

This repository contains codes for learning to build FFI APIs in Rust for C++ and C#.

License:MIT License


Languages

Language:Rust 85.0%Language:C++ 15.0%