How to reuse pre-built crate library across multiple projects/apps?

I am trying to speed up the build when many of my app projects have many of the shared libraries. These apps and libs are not necessary in the same repo.

I would like to achieve the following:

Let's say I have lib1, app1 and app2 cargo.toml based projects.
First, I would like to go and cargo build lib1. It would save build output in lib1/target folder.
Next I would like to go and build app1 project, which uses lib1 crate. However, I do not want cargo build for the app1 to build lib1 again. At very most, I want it to only copy the pre-built result from lib1/target folder to app1/target.
app2 has the same dependency to lib1, and I want the same 'reuse of prebuilt lib1' during building of the app2.

I am aware about cargo workspaces, but it does not allow me to do what I want, because app1 and app2 would be in different workspaces as such.

I am aware that I can publish to a crate registry, however, it stops iterative development when lib1 and app1 needs to be modified simultaneously and many publishing actions there is not a good idea. Although, it could work as a workaround if I could publish lib1 to a local folder registry, if it is even possible.

Could you please point me in the right direction what tools and configs to use to achieve the above?

I would use sccache for this. You can think of it as having a shared target/ folder across your entire computer.

Thanks. I will explore this option. What I do not like about it is that it will reevaluate if lib1 needs to be built when I build app1 or app2 let's say. I do not want this analysis happening when I build apps because there are quite a lot of libs and we know some have many and deep shared dependencies.

But the tool is certainly good to optimize builds of individual projects, like lib1 in my example

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.