Reducing closure dependencies in qtbase

Hi folks! I was recently working on solving issue #49287 (" vlc closure size inflated due to saving ./configure output"), and I noticed that VLC had a dependency on qtbase-5.11.1-dev. After a bit of digging, I think that this is because of the fact that the Qt header files use the __FILE__ macro in assert and error messages, which means that any downstream project that depends on Qt will depend on the -dev output at runtime.

Assuming I’m not entirely off-base here (still rebuilding everything on my laptop, which will take some time), has there been any previous attempts to solve issues with the __FILE__ macro in Nixpkgs? It’s not as simple as replacing it with the actual file, since you want: #define MY_MACRO __FILE__ to expand where the macro is used, but static char *my_func() { return __FILE__; } to expand to the header file the function is defined in.

Any thoughts appreciated!

Unbaked thought: patch cpp to strip the store path should one be
present in __FILE__.

Oh, that’s a good idea - I’ll look into how hard that is. It looks like GCC 8 supports -ffile-prefix-map, which would allow overriding individual path prefixes in __FILE__ and debug information. Clang doesn’t support it yet, though there’s a proposed patch. Either way, it looks like patching the compiler may be the right approach here, since presumably we don’t want to have to pass a flag for every store path input.

Well, if there is a flag, then said flag could potentially go into
stdenv :slight_smile:

I think my main question with putting it into stdenv is what exactly we want to replace? Something like qtbase could add the appropriate flag to a setupHook, but I’m not sure we’d want to generate a flag for every single (transitive) build input?

Either way, here’s a patch that may work for cpp. I haven’t tested it yet - I’ll try to do that at some point - but curious what peoples’ opinions are.

In other places like in pkgs/development/go-modules/generic/default.nix, we use removeReferencesTo to rewrite the output. It replaces the hash of the target with XXXXX. And then add a disallowedReferences to enforce and double-check the output.

It’s not super elegant but it works very well :slight_smile:

1 Like

I’ve at least once used this half-hack: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/boost/generic.nix#L169