How do I add non dependent libraries from my workspace in to a subdirectory of the output folder during compile?

48 views Asked by At

I have been working on a software than needs to dynamically load libraries at runtime from a specific folder in Rust 1.72.1. For this am experimenting with ways to test this functionality for CI, but I am running into the problem that I have not been successful at changing the directory to which to compile the libraries while not changing the target directory for the main application.

Example workspace layout:

workspace_root
├── Cargo.toml
├── lib_a
│  ├── Cargo.toml
│  └── src
│     └── lib.rs
├── lib_b
│  ├── Cargo.toml
│  └── src
│     └── lib.rs
├── main_program
│  ├── Cargo.toml
│  └── src
│     └── main.rs
└── master_lib
   ├── Cargo.toml
   └── src
      └── lib.rs

lib_a and lib_b do have master_lib as a dependency, but not the other way around and main program only depends on master_lib. What I would want this to result in is the following:

target
├── libraries
│  ├── lib_a.dll
│  └── lib_b.dll
└── main_program.exe

I have tried using the build.rs functionality of cargo but the only way I found to do it in there is to use std::process::command to invoke cargo to compile each library resulting in the need to recompile master_lib for every library which seems redundant.

I am also aware of the cargo_make plugin but I have not ried it as I suspect it will have the same problem as the build.rs in that it will need to recompile master_lib for every library.

TL;DR: Is there a way to define the compile output folder for each member of a workspace individually?

0

There are 0 answers