Thank you for your response.
I've tried setting opt-level = 'z', but the effect is not significant.
I tried using rust-strip, and the size reduced to 242KB from 699KB before stripping. Although it became smaller, it's still quite large compared to a library compiled with C under the same conditions.
One day, if operating systems carry the rust standard libraries, this might be useful -- but for now, it's mostly for esoteric use cases.
Edit: We have an embedded arm platform that needs to carry a few rust binaries, and we use dynamic linking. While the standard library .so file is quite massive we still save space by using dynamic linking because each binary is so huge when it statically links the standard library.
Why are you having this in a lib.rs instead of a main.rs?
Where is the entry point to your program?
And how are you compiling?
Are you maybe including the test harness and that makes the file big?
And maybe change the category of your question to embedded
When you link the final program you may want to use --gc-sections. This tells the linker to discard any unused functions when -ffunction-sections is used (which rustc always does) strip = "debuginfo" doesn't have any effect when building a static library. All it does is passing --strip-debug when invoking the linker, but building a static library doesn't invoke the linker. You have to manually pass it when linking your program (or strip the program after linking it)