Skip to content

Only include files when packaging bevy, rather than excluding #18571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

LikeLakers2
Copy link
Contributor

@LikeLakers2 LikeLakers2 commented Mar 27, 2025

Objective

Reduce the size of .crate files generated by cargo package or cargo publish for the bevy package.

Solution

Change what files are included in a .crate file, by only including necessary folders and files, rather than excluding a few specific folders and keeping the rest.

As a result of this change, several files and folders are no longer included in the generated .crate files:

  • .cargo/ - Only contains config_fast_builds.toml, which does nothing unless renamed to config.toml
  • docs-template/ - Only used for generating documentation
  • examples/wasm/ - Does not contain any examples that would be scraped by rustdoc.
  • examples/no_std/README.md, examples/stress_tests/README.md, examples/README.md - These README files aren't used anywhere in the docs, so they just take up space in the .crate
  • working-migration-guides/, working-release-notes/ - These are only relevant for building up documentation that will be released alongside 0.16 proper.
  • .gitattributes, .gitignore - Only used for the repo, and have no effect on how Cargo handles the package
  • clippy.toml, deny.toml, rustfmt.toml, typos.toml - Only relevant when developing Bevy
  • CODE_OF_CONDUCT.md, CONTRIBUTING.md, CREDITS.md - Only relevant in their latest form as contained on the repo (so there's not much point to packaging these up, since they can quickly become outdated)

Testing

This change was tested following these steps:

  1. Run cargo package at the root of the repo
  2. Rename the resulting .crate file so it isn't overwritten later
  3. Insert the changes from this PR into /Cargo.toml
  4. Run cargo package at the root of the repo
  5. Compare the resulting .crate file sizes

I performed my testing on Windows 10 22H2, with Rust 1.85.1, using commit 0d90da8. Only one change was made from this commit that was unrelated to testing: The removal of an instance of "bevy_internal/bevy_anti_aliasing" from /Cargo.toml. This was done because Cargo would complain about the use of a non-existent feature otherwise - I do not believe it affects the results in any major way.

@IQuick143 IQuick143 added A-Cross-Cutting Impacts the entire engine D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 27, 2025
@mockersf
Copy link
Member

Can you keep the tests and examples as included? They are used as compilation tests front the crates, and examples are used when building docs on docs.rs

@LikeLakers2
Copy link
Contributor Author

LikeLakers2 commented Mar 27, 2025

@mockersf Done.

I will admit, I'm a little bothered by how this brings the resulting file size back up to nearly 600 KB. It's not so bad since it's only downloaded once by Cargo, and I understand the examples are used by the docs, but it still feels... weird to me.

@LikeLakers2 LikeLakers2 changed the title Reduce bevy's packaged size by only including files, rather than excluding Only include files when packaging bevy, rather than excluding Mar 27, 2025
@LikeLakers2 LikeLakers2 force-pushed the project/qol/reduce-package-size branch from a68d569 to 5d926e4 Compare April 6, 2025 09:02
Copy link
Contributor

@greeble-dev greeble-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clicking approve as I've done some basic tests and didn't spot any problems.

Tested cargo package on Win10. I also unpacked the crate and made a new crate with a path dependency on the unpacked folder. I replaced the new crate's main.rs with the 3d_scene example and confirmed it built and ran.

@cart
Copy link
Member

cart commented Apr 9, 2025

One consideration is that switching to includes introduces a new failure case (failing to include something necessary). Given that the size wins are marginal here (8KB), I'm not sure thats worth the added risk. Trimming out "big" things with excludes seems like the better tradeoff.

@mockersf
Copy link
Member

sticking to exclude for now

@mockersf mockersf closed this May 19, 2025
@LikeLakers2 LikeLakers2 deleted the project/qol/reduce-package-size branch May 19, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Cross-Cutting Impacts the entire engine D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants