Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link against a local Rust library? (similar to npm link)

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.)

like image 497
bguiz Avatar asked Aug 04 '14 13:08

bguiz


People also ask

How do I link to a local npm package?

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.


2 Answers

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.

like image 140
Vladimir Matveev Avatar answered Oct 05 '22 00:10

Vladimir Matveev


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.

like image 36
abject_error Avatar answered Oct 05 '22 00:10

abject_error