When developing a library in node,
if you wish to develop against a library that only exists locally,
before you npm publish
,
you can use npm link /path/to/other/node_library
.
What is the equivalent of this for Rust? How do you create another a foo executable that links to bar library, without pushing bar library to a git remote first?
The official rust tutorial shows how to do this using raw rustc
,
how can this be done in Cargo.toml
?
(The cargo documentation shows you how to build a lib, but now how to link to one that doesn't have a remote repository.)
Example: Let the local-dir is the local directory and project-dir is the project directory and local_module is the local module package you want to install, first go to the local-dir and type npm link and next go to the project directory and type npm link <local_module> this will link your local module to your project.
It is also possible to use git file:
URL if your dependency is in a local git repo:
[dependencies.local_dep]
git = "file:/some/local/path"
There is also a very useful feature when you want to use your own local copy of some package. You can specify a path to such package in ~/.cargo/config
file:
package-name = "/path/to/package"
With this configuration when some other package (let's name it a
) requires package-name
, regardless of what is declared in a
manifest about package-name
location, package-name
will be build from the source tree specified in this config file. This is useful when you need to test your changes in a library which other projects depend on.
You can do:
[dependencies.local_dep]
path = "some/local/path"
Check out https://github.com/gfx-rs/gfx-rs/blob/master/Cargo.toml for an example.
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