Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.
/ ffiapi-rust Public archive

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

License

Notifications You must be signed in to change notification settings

brenomfviana/ffiapi-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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#.

Topics

Resources

License

Stars

Watchers

Forks