<div dir="ltr"><div class="gmail_quote"><div>(Capturing some investigation I dumped into IRC)</div><div><br></div><div dir="ltr">On Wed, 27 Jul 2016 at 09:54 Ximin Luo <<a href="mailto:infinity0@debian.org">infinity0@debian.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">librustc_llvm-xx.so is approx 30MB, taking about half the space of libstd-rust-xx.<br>
Upstream tells me that this is due to embedding pretty much all of LLVM.<br>
<br>
We should explore options to make it instead dynamically link against LLVM,<br>
since that is the Debian convention. (Upstream probably won't spend too much<br>
time on this.) This would reduce the size of libstd-rust-xx by about half.<br></blockquote><div><br></div><div>The relevant piece of code looks like it's src/librustc_llvm/<a href="http://build.rs">build.rs</a>:</div><div><div>        let kind = if name.starts_with("LLVM") {</div><div>            "static"</div><div>        } else {</div><div>            "dylib"</div><div>        };</div></div><div><br></div><div>I suspect if we remove this block (and the following cargo:rustc-link-lib print statement), then the linker would just find shared versions of the LLVM libs if available.</div><div><br></div><div>*However:* It seems our LLVM (or upstream llvm-config?) isn't ready to help users use dynamic libraries.  Specifically the output of `llvm-config-3.8 --libs` mentions a bunch of libraries for which we only have .a versions.</div><div><br></div><div>Some old-ish (2010-2012) LLVM upstream discussion supports the idea that llvm-config needs more work before this will "just work":</div><div>- <a href="https://groups.google.com/forum/#!topic/llvm-dev/g81Hcoy0stw">https://groups.google.com/forum/#!topic/llvm-dev/g81Hcoy0stw</a></div><div>- <a href="https://llvm.org/bugs/show_bug.cgi?id=3201">https://llvm.org/bugs/show_bug.cgi?id=3201</a></div><div>- <a href="http://llvm.org/viewvc/llvm-project?revision=96559&view=revision">http://llvm.org/viewvc/llvm-project?revision=96559&view=revision</a></div><div><br></div><div>The conclusion in the above threads seems to be that we should just ignore llvm-config, use what we (Debian) know about the build environment, and manually specify something like "-<span style="font-family:monospace;line-height:1.5">L/usr/lib/llvm-$v/lib -lLLVM"</span><span style="line-height:1.5">.  This seems an easy decision for us (and other distros with controlled build environments), but inappropriate for Rust upstream IMO.</span></div><div><br></div><div>The discussion in/around <a href="https://github.com/rust-lang/rust/pull/27937">https://github.com/rust-lang/rust/pull/27937</a> seems to imply that support *does* exist in some form for dynamic linking libLLVM (and perhaps gentoo are already using it?), but I still think we may need some changes to Debian's LLVM packaging in addition to rustc.deb build tweaks.  Closer analysis of this discussion needed.<br></div><div><br></div><div>I agree that we will get little prioritisation from upstream on this, as static linking LLVM is the *right* approach when using the vendored LLVM sources.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
(The size could further be reduced by splitting dev vs runtime shared objects,<br>
but upstream don't seem to be doing this themselves yet, and any work we do<br>
here should definitely be consulted with them first.)<br></blockquote><div><br></div><div><div>If you're suggesting just moving some "dev only" libstd libraries (librustc_*.so ?) entirely to the -dev (or rustc) package, then this is an interesting thought.  I think trying to separate run-time from dev-time quickly becomes equivalent to breaking libstd-rust-x.y into several separate packages and just letting shlibdeps do its thing.  That seems quite reasonable once we have non-rustc Rust applications and libstd-rust-x.y size is a concern.</div><div><br></div></div><div>See the discussion in <a href="https://github.com/rust-lang/rust/issues/23366">https://github.com/rust-lang/rust/issues/23366</a> for some related discussion on reducing the size of libstd runtime libs by stripping the (large!) .note.rustc section.  I think this is a separate bug/issue, but note that breaking the current symlinks and having different link-time (libstd-rust-dev) and run-time (libstd-rust-x.y) lib files actually results in a *larger* on-disk size for rustc users.  I don't think this is useful to explore until we have Rust application packages whose users might not also have rustc installed.</div><div><br></div><div><span style="line-height:1.5"> - Gus</span><br></div></div></div>