[Pre-RFC] `cargo package` should include fewer files by default
Rust Internals [Unofficial]
April 24, 2026
decathorpe:
However, it currently appears to be "best practice" (or at the very least, "usual practice") to extensively use
include_bytes!orinclude_str!macros in test code to include that test data into tests,
Tangential to the rest of the thread, but I think that this should be considered poor practice. It has several disadvantages:
- Fails compilation if the file is missing, as you note.
- Requires recompilation whenever the file contents change. (Only relevant when working on that specific test.)
- Passes the entire file contents through rustc and the linker, which is unnecessary effort and puts copies of the file in intermediate artifacts and the binary. (Only relevant if the file is large.)
I expect that the main reasons people use include_bytes! are that it is very convenient: it is concise, available with zero imports, and takes a file-relative path. It's also "more statically checked" in that it is guaranteed not to fail at run time — but that creates a packaging hazard, as you have seen.
Discussion in the ATmosphere