Where does Rust store the
std libraries to guarantee that they're accessible to
cargo when compiling Rust projects?
rustc know about
core? Or does
cargo implicitly include these at build time as if they're any other crate?
I'm hacking on a domain-specific programming language (very much inspired by Rust) and we've reached the point where we're ready to include the language's
std libraries implicitly (currently, users have to manually specify
core dependencies in their manifest). We don't have a
prelude module yet, but to begin we just want to start by ensuring that
std are accessible without having to manually declare them as dependencies, and this got me curious about Rust's approach
For the most part, rustc just inherently knows about them, and finds compiled versions of them in the sysroot.
However, I would recommend learning from what we're moving towards rather than what we currently do. Just add the logic to always build core and std from source, exactly like any other package, and then separately add logic for caching compiled binaries. Don't special-case the standard library; you may end up regretting that special case later, and it may be hard to fix.
I am pretty new to rust but the standard prelude handles most of that I think.
Is the plan to install a copy of each crate's src in a common, local user directory during installation? And then perhaps sync their
major.minor version with
rustc so that
cargo knows which to use?
I'd imagine the implicit
std crates won't be fetched from crates.io or the rust git repo in order to ensure that folks can build new projects offline.
Yeah, we'd still provide a local copy of the source that exactly matches the version of rustc.
Here's work on moving towards
std being more like a regular crate: