Skip to content
0:00 / 0:00

#rust#ffi#build.rs

Crust of Rust: Build Scripts and Foreign-Function Interfaces (FFI)

Jon Gjengset

111K subscribers • 38 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Jon Gjengset

Advanced. Deep dive for people who know the field.

48K views4 years ago2 recommendations

Programming languagesSystems programmingRustCBuild systems and packaging

Jon Gjengset deep dives into Cargo build scripts and Rust foreign-function interfaces, building bindings against the libsodium C library.

This time we go over Cargo build scripts and Rust foreign-function interfaces, including looking at some widely used *-sys crates. We also wrote our own bindings against the libsodium C library: doc.libsodium.org/. You can find the Cargo book entry for build scripts at doc.rust-lang.org/cargo/reference/build-scripts.html, and the nomicon entry for ffi at doc.rust-lang.org/nomicon/ffi.html. Live version with chat: youtu.be/pSTPJ39LsEU Introduction libsodium Build scripts OUT_DIR cargo directives Build script sandboxing libgit2-sys bindgen libssh2-sys openssl-sys libsodium-sys Writing our own libsodium-sys Wrapping crypto_generichash Reverse FFI autocfg cbindgen and cxx The Rustacean Station Discord server is at discord.gg/RJdqQ9n.

Why it's here

2 people recommend this

What people say. Recommended as a comprehensive guide to Rust build scripts, FFI, and using bindgen to interface with C libraries.

Moments people linked to

u/masklinnin r/rust • Recommends

On “Enforce compiler error if init function isn't called?”

IIRC /u/jonhoo’s latest crust uses that method: link to this video On my phone so did not check if I was correct but I think I am.

u/HeroicKatoraimage · oxide-authin r/rust • Recommends

On “Enforce compiler error if init function isn't called?”

Correct. Timestamp 1:33:04. More libraries should work that way! If we could explicitly name the zero-sized type of a function symbol then one could actually turn those into attributes of the token type for some minor sugar if you need the function object iself :) Are zero-sized types guaranteed to be ABI neutral? Wouldn't it be interesting if it was sound to write the *bindings* themselves to reinterprets the symbols as a function requiring the init token like so: // What if this was ABI compatible with fn(*mut u8, u64, …) #unsafe(no_mangle) #repr(transparent) // Syntax proposal? fn crypto_generic_hash(_: Sodium, _: *mut u8, u64, rest of arguments…) {} Not that t…
2View on Reddit