This post is the first part in a planned series on linking Rust crates. My desire is to get informal feedback on these posts, and then turn it into more structured content suitable for the Rust reference, or maybe the Rustonomicon (or a book on its own.) Working on the Rust compiler, one topic that I come across from time to time is “what is supposed to happen when we use these particular features of my tools?” More specifically, Rust has various metaphorical knobs that allow fine-grained control of the object code generated by the compiler, several of which are related to the process of linking that code to other object code.
From Linkage chapter of the Rust Reference, we can see there are seven
kinds of crates:
I had originally intended to cover all seven, but the time got late and the post got long
and I decided that
proc-macro can be dealt with another day.
What this post is going to do is walk through the first six of the crate types listed above and demonstrate: how to build an example of such a crate, how to link to it, and how to run with that linked crate.