Cargo handling of resource files

I am facing this specific problem: I have a crate library that needs to use some files in order to function. These files are available in the source distribution, so it works out of the box when my crate is included as a dependency, and the user runs their project from source, with e.g. cargo run or cargo test, because the source of my crate is available.

But it breaks the CI of one user, because the project is compiled in one machine and is executed in another, via cargo nextest archive, where the source is no longer available, so my library can't find the files it needs.

The problem is more general than this CI issue, because in the end, it should be possible to distribute the software without the source, so there must be some way to distribute the resource files with it. Is there some cargo facility that allows me to specify what files should be installed with the binaries when installing/distributing?

It would be nice, but no, I don't believe there is.

The next best thing you can do is use the std::include_str! and/or std::include_bytes! macros to embed the files in question into the compiled code. You can't fail to include a file if it's embedded in the executable (taps the side of his head).

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.