I don’t personally have a good reason to do this and I’m mostly just curious, but two reasons I can think of is if an organization prefers to host their own Crate server for their employees or has proprietary internal dependencies on their company network, or if Mozilla ever decides to shut down crates.io servers or gets sold to a consumer unfriendly company like Facebook or Google.

My questions are whether it’s possible to host Crates in a way that the compiler can understand (for example, if the crates.io backend is open source, or if you can replicate the functionality with a simple file server provided by software like Apache or Nignx), and whether you can configure the Rust compiler to recognize a custom URL to supplement or replace the standard crates.io server.

With JVM languages, you can easily add a URL to a Maven server that you host and pull jar files from there, even a HTTP simple file server can be used if you name the files and directories correctly. Is there a way to do the same in Rust?

Ephera
link
210M

Just to add that it is also possible to have it check out the source code from a Git repository: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories

So, you don’t even necessarily need to run a package registry (which might not be worth it for smaller companies)

@mian
link
110M

Yes, cargo has support for alternate registries. crates.io is the default but you can switch it via global config or on a per-package basis. See https://doc.rust-lang.org/cargo/reference/registries.html for details on configuring cargo and setting up the registry itself.

@Octorine
link
010M

It sounds like you’re looking for something called “vendoring” that was added to cargo in the last couple of years. If you want to store all your dependencies in some path local to your network, you can use the cargo vendor command. If you want an index like crates.io but not crates.io, then you want source replacemtnt.

Rust Programming
!rust
    • 0 users online
    • 4 users / day
    • 11 users / week
    • 12 users / month
    • 55 users / 6 months
    • 1229 subscribers
    • 283 Posts
    • 322 Comments
    • Modlog