GithubHelp home page GithubHelp logo

dns2utf8 / hour_glass Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 2.0 29 KB

C++ Frontend - Rust Backend

License: MIT License

Makefile 35.32% C 21.24% C++ 23.18% Rust 20.26%
hour-glass backend rust cpp cpp11 cpp14 rust-bindings c c89

hour_glass's Introduction

hour_glass

This is a PoC (Proof of Concept) using Rust as a Backend for C++.

This is based upon the work of Alex's Rust FFI Examples.

How it works

  • The rust library is included as a static library.
  • The C++ facade lives inside the rust:: namespace.
  • A C++ std::unique_ptr manages the pointer to the Rust IntSorter ensuring it will never pass a nullpointer to the Rust functions. This prevents undefined behavior.

hg_pic.png

Contributions

If you would like to add/fix or change something, send a PR or open an issue.

Running your self

Run:

make clean all optimized

For a debug build run:

make clean all

Requirements

  • make
  • clang or clang++ or gcc or g++ with at least c89 and c++11. You may mix the compilers, please run make clean when switching.
  • cargo and rustc >= 1.11.0

Expected output:

$ make
mkdir -p target
clang -g -std=c89 -Wall -Werror -pedantic -o target/main_c.o -c src/main.c
cargo build 
   Compiling hour_glass v0.1.0 (file:///home/vp/tmp/hour_glass)
note: link against the following native artifacts when linking against this static library
note: the order and any duplication can be significant on some platforms, and so may need to be preserved
note: library: dl
note: library: pthread
note: library: gcc_s
note: library: c
note: library: m
note: library: rt
note: library: util
clang -g -std=c89 -Wall -Werror -pedantic -o target/hgc target/main_c.o target/debug/libintsorter.a -Wl,--gc-sections -lpthread
clang++ -g -std=c++11 -Wall -Werror -pedantic -o target/main_cpp.o -c src/main.cpp
clang++ -g -std=c++11 -Wall -Werror -pedantic -o target/hgcpp target/main_cpp.o target/debug/libintsorter.a -Wl,--gc-sections -lpthread
######## Testing from C
target/hgc
Hi C
0: 42
1: 23
2: 13
3: 12
4: 6
5: 0
6: 0
Destroy IntSorter Instance
Bye C
######## Testing from C++
target/hgcpp
Hi C++
0: 42
1: 23
2: 13
3: 12
4: 6
5: 0
6: 0
Bye C++
Destroy IntSorter Instance

Note the reverse order of rusts "Destroy IntSorter Instance" message. The reason is in C we explicitily destroy the IntSorter and in C++ the end of the scope destroys the object.

hour_glass's People

Contributors

dns2utf8 avatar fmorgner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

fmorgner cgmossa

hour_glass's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.