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



This time we go over Cargo build scripts and Rust foreign-function interfaces, including looking at some widely used *-sys crates.

17 Comments

  1. Can't you just use non_exhaustive types or add a private member instead of using empty enums for opaque types? Tbh I'm kinda surprised that even works properly since an empty enum is more or less equivalent to the never type so I'd think the compiler considers it impossible for any such values to exist and would optimize accordingly. I guess if it's always behind a pointer it doesn't make a difference and there's not really anything else you can do wrong but it still seems very odd to me.

  2. Hi Jon! Thanks, I learned something new! I didn't know the "vendored"-feature convention before (seen in the libgit2-sys crate). I'll look deeper into it as I'm also about to create a *-sys-crate for a C library.

    PS: We had a short in-person chat at RustConf 😀

  3. Hey, always nice to see some in-depth Rust from you.

    For the build scripts, I do get that it's slightly concerning that you're literally running arbitrary code any time you compile anything that has some dependency with a build script.. on the other hand it's the same issue you get from just using any external library at all, the only thing of note really is that maybe you shouldn't give cargo full access to your system, assuming you're already sandboxing other programs which realistically, people probably are not doing anyway and probably is the bigger issue here.

    But for sure, there's more room for accidents here since you're likely to have a legitimate purpose to mess around outside of the project directory.

Leave a Reply

© 2023 53GB