Should rustc have split outputs?

So today I ran into:

https://github.com/NixOS/nixpkgs/issues/95568

Which shows how a rust based package may reference rustc’s libraries. We split gcc to different outputs, why don’t we do it for Rust? Just curios.

1 Like

Good catch! Yeah, we probably should split out the libs into a different output. I didn’t even know it was possible to dynamically link to Rust’s standard library. Maybe it was just an oversight?

It looks like this will be an issue in any package that uses crate-type = ["dylib"] in it’s Cargo.toml file.

1 Like

Hmm, I’m not sure whether that will bring much benefit, even with lib as a separate output, almost all of it is what the closure size is all about:

$ du -csh /nix/store/1r7l5brzhjjm1lnx04f4gszy1xgjm1gi-rustc-1.45.0/
1.1G
$ du -csh /nix/store/1r7l5brzhjjm1lnx04f4gszy1xgjm1gi-rustc-1.45.0/lib
1.1G

A patch upstream might do it though… @kira-bruneau Texlab doesn’t have cargo-type = ["dylib"] in it’s Cargo.toml - https://github.com/latex-lsp/texlab/blob/3e8e0e5d0c4632acdb6d1bd5c0bfe2359df368e1/Cargo.toml . I’m not experienced in Rust at all, do you have any idea whether that’s avoidable?

The issue is that one of its dependencies (html2md) does: Cargo.toml · e4bf2b4b00a34e21958ba4aa466cc977c9e2c2ea · Kanedias / html2md · GitLab

I don’t know of a way to workaround this yet, but I will look into it. html2md also seems to generate a rlib (essentially a static rust library), maybe there is some way to force texlab to use that instead?

@doronbehar Maybe we could just move the standard library into its own output? It’s only about 3.6M:

$ ls -lh /nix/store/1r7l5brzhjjm1lnx04f4gszy1xgjm1gi-rustc-1.45.0/lib/libstd*
-r--r--r-- 1 root root 3.6M Dec 31  1969 /nix/store/1r7l5brzhjjm1lnx04f4gszy1xgjm1gi-rustc-1.45.0/lib/libstd-d29202198fbfe533.so

I personally fear of brakage but you may want to try this out, note the situation is already a bit complicated:

So staticlib is the culprit… I wonder how rude that would be to ask them right here:

Why did they add staticlib.

@doronbehar Why is staticlib the culprit? From what I know, staticlib won’t be used in a Rust build, it’s created so C, C++, etc… can link to the library.

You are probably correct and I probably misunderstood you and the Rust reference - Linkage - The Rust Reference .