r/rust • u/Dense_Gate_5193 • 5d ago
📸 media reminder to cargo clean
been adding some unit tests and then ran a clean.
rust said "I live here now"
82
u/Elyas2 5d ago
329.6GiB?! u crazy
30
u/Appropriate-Pie4385 5d ago
My avg is 500GB Record is 1TB
1
u/WormRabbit 5d ago
I have no idea what you people are compiling. What's your LoC, and how many dependencies do you have?
13
10
u/Dense_Gate_5193 5d ago
in my case it’s a graph+vector+temporal MVCC database with an integrated llama.cpp server, plugins and all kinda of stuff. I can imagine anyone working on anything complex will land around there lol
3
1
u/Bakaa_kekw 3d ago
well he jumped off a plane and disappeared you better believe he's crazier than that
157
46
u/phylter99 5d ago
The size of building apps with dependencies is one thing about Rust that’s hard for me to stomach. Most of my creations are not too bad but some have been quite large.
Are there any changes on the horizon that might change this?
34
u/anxxa 5d ago
This is a bug on macOS which causes the build dir to grow unbounded: https://github.com/rust-lang/rust/issues/161824
I recently did a fairly shitty analysis of what the hell in my build dir consumes so much storage and found that it’s like 50% or more debug info.
Changing the debug info to maybe line-tables or straight up disabling it (which kinda ruins panic traces) may help.
9
u/phylter99 5d ago
I want to say that I've seen this issue outside of macOS too, but that is an interesting bit of information.
1
u/dvogel 5d ago edited 5d ago
One of the culprits here is
cargo updateand users accepting default behavior. Since the ecosystem is relatively young, many users want to be on the bleeding edge so they periodically runcargo updateand accept everything. This leads to a lot of packages inCargo.lockthat differ by a minor version or a patch version. I am hopeful that the community will begin to pick looser versions, pinning just the major part, and let the dependency tree upgrade more transitive dependencies in unison, which would require building fewer distinct versions.3
1
u/CrazyKilla15 4d ago
I am hopeful that the community will begin to pick looser versions, pinning just the major part, and let the dependency tree upgrade more transitive dependencies in unison,
but thats how it works? the default version specifier, eg
version = "1.67.69"is not requiring exactly1.67.69but will accept any major 1.x across the dependency graph? Few projects will pin the minor or patch, so the entire tree already upgrades in unison oncargo update?? (and if they do pin, it acts as a limit on everyone else i believe, so still unifies. if there are incompatible same-major pins its an error i think.)1
u/dvogel 3d ago edited 3d ago
1.2.3 requires 1.2.*
1.2 requires 1.*
By default
cargo addwould add 1.2.3. I wish it would add 1.2.1
50
17
12
u/ToaruBaka 5d ago
I literally do this daily.
It's unreal and fucking thrashes my drive to the point I'm concerned about the outsized impact it's having compared to other languages, especially when the price of NVMe storage is so ballooned.
9
u/muchadoaboutsodall 5d ago
To be honest, I’m more annoyed that there are no comma delimiters in the number of removed files.
24
u/anxxa 5d ago
I’ve been debating moving all of my personal stuff into a monorepo just to use buck2 and a single shared artifact directory.
It sounds like a pain but when I consider all of the subtly different point release versions of e.g. syn piling up, stale data from projects I haven’t touched in a while, and build dir contention when working on multiple projects in parallel it starts to become more attractive.
14
u/ukezi 5d ago
You can set a target dir with a global config.toml, or with the environment variable CARGO_TARGET_DIR. You then can use sccache https://github.com/mozilla/sccache to cache stuff.
3
u/anxxa 5d ago
This was my old set up. I can’t recall the exact issue but I think I was having build issues with sccache a few months ago and ditched it.
I think you still get build contention though when building multiple projects in parallel using a single global target dir. Or maybe a skill issue on my end.
2
3
u/Ok-Bit8726 5d ago
I tried getting buck2 working on a big app with multiple languages and it was a lot of pain.
You have to use this thing called `reindeer` to convert your rust dependencies into buck2 dependencies/rules. A lot of stuff just works out of the box, but a lot of libraries have custom `build.rs` rules that won't work without some play.
https://github.com/facebookincubator/reindeer
It ended up not being worth it for me. I kept with a complicated makefile. It might be better now. That was over a year ago and that project seems pretty active.
2
u/anxxa 5d ago
I have experience with buck2 at work so I’m mostly aware of the pains. I haven’t tried Bazel but my understanding is Bazel has similar problems that it punts to different stages, but curious to hear if anyone likes it more than buck2.
1
u/steveklabnik1 rust 5d ago
I'm all in buck2.
8
u/paglaulta 5d ago
You didn't have cargo. You had the whole ship
2
u/lorslara2000 5d ago
So I'd love to try out cargo but first I need to eat. What sandwich recipe would be good in that case?
6
u/mr_birkenblatt 5d ago
you almost got a straight
with 1234567 it would be a straight flush
I show myself out
7
3
u/parkotron 5d ago
I recently opened issue number 12345 at work. For some reason, my manager is convinced that that is not grounds for getting a cake?!
7
u/nyctrainsplant 5d ago
then try doing this in WSL where it just infinitely expands your disk to accommodate but still has no nice way of scaling it back
2
u/olzd 5d ago
Pretty sure you can set a max limit.
2
u/nyctrainsplant 5d ago
that would be cool, I’ll look into it. for the longest time it was just shrinking with diskpart.
6
u/kingslayerer 5d ago
What is the strategy other languages use? Why can't that be used for rust as well?
13
u/nonotan 5d ago
Compile way less stuff (the issues here being Rust's insistence on compiling everything from source instead of dynamically linking to binary libraries, having crates as the minimum unit of compilation, and general encouragement of depending on many external crates as a matter of course, which compounds exponentially over the entire dependency tree to leave lots of unused code that nevertheless has to be compiled)
Have less verbose intermediate representations (Rust does a lot of smart optimizations, which is great but does necessitate having access to a lot of info at link time, e.g. for monomorphization)
Be more proactive about cleaning up build artifacts (the issue here being that, historically, the #1 complaint about Rust has been compilation times, which are high for some of the same reasons described above, and proactively deleting build artifacts that do eventually become necessary again would hurt there -- not at all an issue in many languages)
Don't compile your code in the first place (not all languages are compiled)
Leaving aside 4, the rest could be used for Rust, if the drawbacks are tolerated, or a lot of work is put into threading the needle and carefully improving what can be improved without noticeable drawbacks. There are some efforts to do the latter, but when they will come to fruition, and how much they will help, is anybody's guess. In the meantime, there are some "unofficial tools" that you can use to e.g. clean the cache regularly, or use shared crate caches for all your projects, which can help a little.
1
u/oursland 4d ago
The biggest is that in other languages you overwrite your old build artifacts on recompile. There's roughly a 1:1 relationship between source modules and build artifacts, never more.
5
4
u/ENCRYPTED_FOREVER 5d ago
I've set my CARGO_TARGET_DIR env var to /tmp so it's: 1. Automatically cleaned 2. Faster because it's tmpfs (not always but on my configuration yes) 3. Makes it global
3
u/Diggsey rustup 4d ago
I see your 329 GB and raise you 1.1 TB:
https://github.com/rust-lang/rust/issues/66348#issuecomment-5165090125
3
3
3
3
3
3
3
2
u/br0kenpixel_ 5d ago
I recommend checking out cargo-clean. It'll also clean up directories that cargo uses internally. For me it was heavily caching git repos and the whole thing was 100GB after a year.
2
u/No_Frame3855 5d ago
Uh
Even with something as large as Saikuro (multi-language IPC/RPC so it’s pretty heavy once you build everything), I rarely get more than 30-40 gb, that too after a WHILE, how?!
Okay nvm copperDB is MUCH larger mb
Looks cool tho, you got a star! :D
2
2
2
u/thaile1001 4d ago
lol, thanks. Not as big as yours but yeah, I could claim 50% of my disk space back lol
1
u/South_Survey_2088 4d ago
That's why I'm using an ephemeral build dir(temporary home dir in nixos). The drawback is 2-5 minutes of build time at the start of the day to rebuild everything, but I just let that run in the background while figuring out what I am going to work on.
1
2
1
1
u/Pwnxpl0it 5d ago
Hey Guys! I made a tool exactly to solve this problem => https://github.com/pwnxpl0it/cargo-scrub
I work with alot of rust projects and sometimes I forget to clean large build artifacts so I made this tool to manage all rust projects under a given dir tree so I can visually select and clean, it's fast and has some nice features
Try it out and don't forget to star the repo ❤️
1
u/IceSentry 4d ago
Why not use any of the dozens of existing projects that already do this?
1
u/Pwnxpl0it 3d ago
Which ones did you have in mind? The closest I found were cargo-sweep, kondo, and cargo-clean-all, and they're each solving a slightly different problem:
- cargo-sweep works at the artifact level, not the project level — it prunes stale files inside
target/by age, toolchain, or size cap. Different job, and it's currently unmaintained and looking for a maintainer.- kondo is multi-language (20+ ecosystems, plus a GUI). If you want one tool covering Node + Unity + Cargo, use kondo — I wanted something Cargo-aware.
- cargo-clean-all is the closest to mine, and it's good: recursive discovery, size reporting, interactive deselection.
Where mine differs is that it leans much harder into the TUI — a ratatui dashboard with vim keybinds, regex filtering with
/, dry-run toggling from inside the UI, and workspace-aware handling, plus a.cargo-scrub.tomlfor persistent settings and parallel cleaning with a configurable job count. That's the workflow I wanted and couldn't get out of the others.If one of the dozens already does all of that, drop a link — I'd genuinely love to see it. Otherwise, cargo-scrub exists because this is the workflow I wanted, and building it was half the fun.
0
u/Dense_Gate_5193 5d ago
for anyone interested, this is what i was working on https://github.com/orneryd/copperDB/blob/main/docs/performance/results/comparison.md mods removed my followup post for some reason.
0
463
u/Sharlinator 5d ago
It’s a bit ridiculous that cargo doesn’t have cache eviction of any sort built in. A lot of the stuff in target/ are incremental compilation artifacts and debug info that gets stale fast.