If youâre anxious about the size of your binary, thereâs a lot of useful advice on the internet to help you reduce it. In my experience, though, people are reticent to discuss their static libraries. If theyâre mentioned at all, youâll be told not to worry about their size: dead code will be optimized away when linking the final binary, and the final binary size is what matters. But that advice didnât help me, because I wanted to distribute a static library and the size was causing me problems. Specifically, I had a Rust library that I wanted to make available to Go developers. Both Rust and Go can interoperate with C, so I compiled the Rust code into a C-compatible library and made a little Go wrapper package for it. Like most pre-compiled C libraries, I can distribute it either as a static or a dynamic library. Now Go developers are accustomed to static linking, which produces self-contained binaries that are refreshingly easy to deploy. Bundling a pre-compiled static library with our Go package allows Go developers to just go get https://github.com/nickel-lang/go-nickel and get to work. Dynamic libraries, on the other hand, require runtime dependencies, linker paths, and installation instructions. So I really wanted to go the static route, even if it came with a slight size penalty. How large of a penalty are we talking about, anyway? ⯠ls -sh target/release/ 132M libnickel_lang.a 15M libnickel_lang.so đł Ok, thatâs too much. Even if I were morally satisfied with 132MB of library, itâs way beyond GitHubâs 50MB file size limit. (Honestly, even the 15M shared library seems large to me; we havenât put much effort into optimizing code size yet.) The compilation process in a nutshell Back in the day, your compiler or assembler would turn each source file into an âobjectâ file containing the compiled code. In order to allow for source files to call functions defined in other source files, each object file could announce the list of functions that it defines, and the lis...
First seen: 2025-12-02 05:52
Last seen: 2025-12-03 21:00