• Stars
    star
    271
  • Rank 151,717 (Top 3 %)
  • Language
    Rust
  • License
    Creative Commons ...
  • Created almost 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A guide for doing FFI using Rust

Using unsafe for Fun and Profit

Build Status Creative Commons Zero License

A guide to traversing the FFI boundary between Rust and other languages. A rendered version is available here. This guide is centred around the idea of building a REST client using Qt (C++) for the GUI and reqwest (Rust) for the business logic.

Building

Building and viewing the book locally is really easy. First you need to get the source code:

$ git clone https://github.com/Michael-F-Bryan/rust-ffi-guide

Make sure you have mdbook installed:

$ cargo install mdbook

Then tell mdbook to build and serve the book:

$ mdbook serve --open

It should now be viewable at http://localhost:3000/ (if it didn't open up automatically).

To build the application itself you'll need the following installed:

  • qt5
  • rust (install with rustup)
  • mdbook (cargo install mdbook)

In this application we're using cmake as the build system. The ci/test.sh script will make a build/ directory and invoke cmake to compile and test everything.

$ ./ci/test.sh

The final application should now be at build/gui.

Alternatively, if you don't want to install all the dependencies I've created a docker image (michaelfbryan/ffi-guide) for compiling Rust and Qt.

$ docker run \
    -v $(pwd):/code \
    -v ~/.cargo:$HOME/.cargo \
    -e CARGO_HOME=$HOME/.cargo \
    --user $UID \
    michaelfbryan/ffi-guide ci/test.sh

Contributing

If there's anything you feel is missing or could be improved, please create an issue. Pull requests are welcome too!

Contributors

More Repositories

1

mdbook-epub

An experimental mdbook backend for creating EPUB documents.
Rust
377
star
2

arcs

A Rust CAD System
Rust
249
star
3

include_dir

The logical evolution of the include_str macro for embedding a directory tree into your binary.
Rust
223
star
4

plugins_in_rust

Implementing plugins with dynamically loaded libraries and Rust
Rust
111
star
5

mdbook-linkcheck

A backend for `mdbook` which will check your links for you.
Rust
109
star
6

gcode-rs

A streaming gcode parser built with embedded applications in mind
G-code
79
star
7

ffi_helpers

A crate to make working with FFI code easier.
Rust
54
star
8

constraints

An experiment in writing algebraic constraint solvers for 3D CAD
Rust
51
star
9

markedit

A library for manipulating unstructured Markdown documents.
Rust
49
star
10

latex-rs

An ergonomic library for programatically generating LaTeX documents and reports.
Rust
47
star
11

noise-gate

A simple Noise Gate algorithm for splitting an audio stream into chunks based on volume/silence
Rust
44
star
12

adventures-in-motion-control

A realistic simulator for a 3D printer motion controller
Rust
32
star
13

gcodes

A basic C# gcode parser and interpreter
C#
29
star
14

scad-rs

A Rust implementation of the OpenSCAD virtual machine.
Rust
25
star
15

lastpass

An unofficial interface to the LastPass API.
Rust
25
star
16

linkcheck

A library for extracting and validating links.
Rust
22
star
17

const-arrayvec

An implementation of the arrayvec crate using const generics
Rust
19
star
18

adventures.michaelfbryan.com

A simple blog for documenting my thoughts and adventures
HTML
15
star
19

iec

A proof-of-concept IEC 61131-3 Compiler.
Rust
15
star
20

rust-closures-and-ffi

Rust
14
star
21

static-analyser-in-rust

An experiment in using literate programming to write a static analysis tool in Rust
Python
14
star
22

repo-backup

A small tool for downloading all your GitHub repositories locally.
Rust
14
star
23

ffi-helpers

Miscellaneous helpers for handling errors in a FFI context
Rust
13
star
24

tinyvm-rs

An incremental port of jakogut/tinyvm to Rust
Rust
13
star
25

github-template

A template project for use with cargo-generate
Rust
12
star
26

calc

Create your own JIT compiled calculator in Rust using LLVM and inkwell.
Rust
11
star
27

non-trivial-macros

Rust
10
star
28

thin-trait-objects

Rust
9
star
29

chmlib

Rust bindings to the CHMLib C library
Rust
8
star
30

mdbook-docker-image

A docker image with `mdbook` and common plugins.
Dockerfile
8
star
31

kaleidoscope

Yet another implementation of the LLVM Kaleidoscope tutorial, in Rust.
Rust
8
star
32

wit-lsp

A Language Server implementation for the WIT interface definition language
Rust
8
star
33

deserializing-binary-data-files

Rust
6
star
34

sum_type

A convenience macro for creating a wrapper enum which may be one of several distinct types
Rust
6
star
35

mcc

A toy compiler for a subset of the C programming language.
Rust
6
star
36

rustc-internal-docs

Internal documentation for the Rust compiler including librustc, liballoc, libstd and friends
Rust
5
star
37

spider_board

A blackboard scraper for Curtin University students
Python
4
star
38

unsafe-tips-and-tricks

Miscellaneous tips and tricks I've picked up in my time writing unsafe Rust code
Rust
4
star
39

aioscraper

A web scraper building on top of Python's asyncio library
Python
3
star
40

cdir

Continuous Deployment in Rust
Rust
3
star
41

workflow-timer

Keep an eye on how long your GitHub Actions jobs are taking.
TypeScript
3
star
42

mdbook-test

An experimental backend for testing an mdbook document
Rust
3
star
43

keep-a-changelog-parser

A parser for the Keep-A-Changelog format
Rust
3
star
44

stepperfin

Proof-of-concept 3D printer firmware written on top of the Rust embedded-hal.
Rust
2
star
45

MIPS

A MIPS emulator written in Rust
Rust
2
star
46

pid

Rust
2
star
47

libloading-bindgen

Rust
2
star
48

dotfiles

Configuration files specific to my Arch Linux installation.
Python
2
star
49

sched

Cron for Humans... In Rust!
Rust
2
star
50

iec-parser

Rust
2
star
51

cheat-sheets

A bunch of super useful snippets and notes
TeX
2
star
52

lib3mf

Rust
2
star
53

serde-spanned

Rust
2
star
54

modern-webassembly

Code to accompany my Using WebAssembly in the Modern World article.
Rust
2
star
55

stateful-native-library

Rust
2
star
56

cargo-metrics

A small guide to using `rustc` for building tools to analyse Rust code.
Rust
2
star
57

xsd-rs

Generate Rust types from an XML Schema.
C#
1
star
58

anpp-ts

A TypeScript port of the Advanced Navigation Packet Protocol
TypeScript
1
star
59

advent-of-code-2020

Rust
1
star
60

accel-stepper

A mirror of the accel-stepper crate
Rust
1
star
61

cheesecake_kwalitee_index

A system that evaluates the kwalitee of all the packages on PyPI
Python
1
star
62

io-callisto

A space-based realtime strategy game focused on territorial expansion, colonialism, and defence.
TypeScript
1
star
63

backlight

A simple Linux utility for changing your laptop screen's brightness
Rust
1
star
64

mdbook-html

An alternate HTML backend for mdbook.
Rust
1
star
65

ansible_setup

The setup I use for my home computers and web server
HTML
1
star
66

llvm-config

An interface to the llvm-config tool from Rust
Rust
1
star
67

blog

A blog created using Pelican, sitting at http://michaelfbryan.com/
CSS
1
star
68

airbrush

Rust
1
star
69

wasmer-borealis

Rust
1
star
70

sieve-of-zakiya

An attempt at implementing the Segmented Sieve of Zakiya in Rust.
Forth
1
star
71

mini_wiki

A lightweight wiki framework designed created using Flask
Python
1
star
72

irc_bot

A proof-of-concept IRC bot built using the actor model
Rust
1
star
73

futhark-rs

Utilities for embedding Futhark code in Rust projects.
Rust
1
star
74

json-stream

Rust
1
star
75

create-a-botnet

Rust
1
star
76

wasm-game-of-life

An implementation of Conway's Game of Life using Rust and WASM
Rust
1
star
77

cxx-experiment

Rust
1
star
78

json-eater

Rust
1
star
79

github-workspace-template

A template project for creating a workspace project use with cargo-generate
Rust
1
star