Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rust library development workflow

When developing a library in Rust (+ Cargo), how do I achieve the fast recompile/test cycle?

When developing an app, it's easy, I:

  • Make changes in the code

  • Switch to the terminal and run cargo run

  • See the compiler feedback

But now I want to extract parts of my app as a library and publish it on GitHub. I would like to continue developing my app, but now with this library as a dependency. I'm going to develop both the library and the app in parallel.

How do I get same quick feedback now?

Both the library and the app will be developed on the same machine, I would like to make changes to the library, update the app correspondingly and see the compiler feedback.

I'm guessing I could use my library as a dependency in Cargo.toml and run cargo update each time I want to update my app's dependencies, but this will be somewhat slow because it will have to download the code from github each time and recompile all dependencies.

like image 940
Valentin V Avatar asked Aug 11 '14 12:08

Valentin V


People also ask

What is a library in Rust?

A collection of reusable, precompiled programs, scripts, or routines that can be called by the programmer while writing a code is called a Library in Rust.


1 Answers

You can use this somewhat undocumented feature of cargo. Add the following line to ~/.cargo/config file (or /path/to/your/binary/project/.cargo/config to limit the effect to your binary project):

paths = ["/path/to/your/library"]

From now on every cargo package (or those under /path/to/your/binary/project root) which depends on your library will use /path/to/your/library as the source code for it regardless of what is specified in this package manifest, so you can keep Git repo URL in your program manifest. Hopefully this feature will be documented in future.

Update

This is now documented in the Cargo guide.

like image 141
Vladimir Matveev Avatar answered Sep 23 '22 16:09

Vladimir Matveev