I am practicing rust (1.36) by creating small program using rand crate. but the problem is whenever i create new project using cargo new and then add rand dependency in cargo.toml. it connects to internet and download same rand package again.
In contrast to Python, installed packages go to site_package folder and become available for import/use to any program. Don't required to download again.
My question is, how do I tell cargo to look for already installed local crate rather than downloading again?
Even in modern Python, one wouldn't just use the globally available site_packages directory and "pollute" the globally available packages, but one would use virtual environments to maintain proper versioning per project -- similar to what cargo does.
With cargo, once all the packages downloaded and their versions specified explicitly in a project, one can pass the new
--offline flag while one compiles one's project, in which case cargo runs without accessing the network:
$ cargo build --offline
That being said, doing something of what you described is of course perfectly possible:
$ mkdir offline_resources
$ cd offline_resources
$ git clone https://github.com/rust-random/rand.git
$ cd rand
$ cargo build
$ cd ../..
$ cargo new use_offline
$ cd use_offline
Cargo.toml:
[dependencies]
rand = { path="../offline_resources/rand", version="0.7.0" }
$ cargo build --offline
rand dependency.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With