cargo loc: count lines of code across all your dependencies
I like having visibility into my dependencies. (That's how I ended up maintaining so many cargo plugins).
The other day I found myself wondering how much code there is in the rustls openssl compatibility layer, inluding all dependencies, to compare it against the notoriously enormous OpenSSL. But I couldn't find a tool to do that! The closest thing is cargo dephell, but it has a bunch of annoying limitations. It also hasn't been updated in 3 years and has accumulated a lot of CVEs in its C dependencies (thanks for letting me know, Cargo plugin I maintain!) So I've built my own tool over the weekend.
Meet cargo loc! So far it's only 88 lines of actual code (not counting dependencies), but it is already more accurate than cargo dephell!
Sample output
This is cargo loc analyzing itself:
Top 20 largest depdendencies:
504205 lines (133025 code): encoding_rs v0.8.34
384808 lines (384747 code): windows-sys v0.52.0
180430 lines (177051 code): winapi v0.3.9
121145 lines (109166 code): libc v0.2.154
54867 lines (51333 code): syn v2.0.63
52523 lines (49170 code): regex-syntax v0.8.3
40453 lines (29483 code): regex-automata v0.4.6
25319 lines (19553 code): rayon v1.10.0
24113 lines (22640 code): pest v2.7.10
23105 lines (18998 code): chrono v0.4.38
20150 lines (16943 code): serde_json v1.0.117
19282 lines (10602 code): wasm-bindgen v0.2.92
17237 lines (10962 code): regex v1.10.4
17095 lines (12062 code): clap v2.34.0
16593 lines (13567 code): crossbeam-channel v0.5.12
16379 lines (13118 code): chrono-tz v0.8.6
15108 lines (11379 code): aho-corasick v1.1.3
14221 lines (11915 code): tera v1.19.1
13421 lines (9231 code): libm v0.2.8
12701 lines (10742 code): serde v1.0.201
Breakdown of the total lines by language:
Rust: 1436510
Plain Text: 369964
Markdown: 35129
TOML: 19082
C: 8803
HTML: 4028
JavaScript: 2790
Python: 2759
JSON: 1432
Makefile: 1361
C Header: 1153
F*: 830
Pest: 735
YAML: 238
Shell: 186
BASH: 183
ReStructuredText: 179
C++: 67
Dockerfile: 9
Pan: 3
Total lines: 1885441
(1355598 code, 444701 comments, 85142 blank lines)
Spooky!
The big question is: does anyone care?
Now that I've satisfied my curiosity, I have to face the fact that this is the 5th Cargo plugin I would be maintaining, if I were to continue its development. And I should probably be working on existing plugins rather than starting all-new ones at this point.
The tool should keep being usable as is without further development. But there is also clearly room for improvement! You can find a list of what works and what doesn't in the README.
If you'd like to make the tool more sophisticated, I'd be happy to hand it over, or accept pull requests. And if nobody wants to do that, then the tool will stay the way it is - but that's probably fine?
Either way, please let me know if you've found the results useful, surprising or anything else! I'd love to hear if it had any value for you, at least. Cheers!