Tricky build scenario

I have a build scenario that's not completely straightforward because I'm using rust on Windows to build a dll with a C API for use with a non-rust application. Everything is working correctly except that I have to manually copy some files to different locations. I'd rather have these copies done by cargo.

I have the following to build my package:
src/lib.rs
src/main.rs
build.rs // prints "cargo:rustc-link-search=..." so lib directory is used for linker input

lib/static-support-lib.lib
lib/support2.lib // support2.dll import library
lib/support2.dll

The build artifacts under target are
my-test-app.exe
my-dll.dll
my-dll.dll.lib // my-dll.dll import library

So what I'd really like to happen is:
lib.rs is built to generate my-dll.dll and my-dll.dll.lib
my-dll.dll.lib is copied to lib/
main.rs is built to generate my-test.app.exe
support2.dll is copied to appropriate target subdirectory

What would be the best practice to accomplish this?

Do I need to go to a cargo workspace?

Should I bring in a tool like just?

Also, although it's working, I'm not sure if what I'm doing with build.rs is best practice since I didn't do a deep dive on this. The build.rs mechanism seems powerful but a bit cumbersome to specify a fixed bit of configuration.

I woudon't say you "need to", but personally I would use a workspace in such case since the individual crates are logically parts of a bigger project so a workspace makes sense.

just is a good fit for such automation, but if you don't want to rely on third party tools, you can use the xtask pattern/workflow, and write your "scripts" in rust:

the trade-off, obviously, is you have to write verbose code, as opposed to succinct shell commands.

EDIT:

I should say, when the tasks are (a sequence of) simple operations like creating directories, copying/renaming files, etc, shell scripts is definitely more succinct.

but for complex tasks (with complex control flow logic) such as (advanced) build target detection, shell scripts tend to be hard to read and maintain, in which case rust code could actually be "simpler" (and more familiar).

1 Like

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.