New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wip] multiple-outputs: always build static libraries #41935
Conversation
@matthewbauer https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L960-L965 and any other uses of |
@orivej Yeah it shouldn't disable shared libraries but I could see how some packages would think that. @Ericson2314 shouldn't we have a "static" output anyway though? We don't want static libraries winding up in our closures. |
The advantage of something like this is to avoid some of the package-specific hacks we are now using for static flags: https://github.com/NixOS/nixpkgs/search?p=1&q=outputs+static&unscoped_q=outputs+static |
@matthewbauer sorry I meant your thing is better than those old things :). Let's go all in! |
@@ -73,6 +77,7 @@ _multioutConfig() { | |||
--docdir=${!outputDoc}/share/doc/${shareDocName} \ | |||
--libdir=${!outputLib}/lib --libexecdir=${!outputLib}/libexec \ | |||
--localedir=${!outputLib}/share/locale \ | |||
--enable-static \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly this should only be added if there is a static
output. Even then, I fear it is to prescriptive but I'd love to be wrong!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If doing this, we should better also remove the --disable-static
flag (on line ~963).
@@ -164,6 +169,11 @@ _multioutDevs() { | |||
done | |||
} | |||
|
|||
_multioutStatic() { | |||
if [ "$outputs" = "out" ] || [ -z "${moveToStatic-1}" ]; then return; fi; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this to run if there is only [ "out" "lib" ]
? If not, try [[ "$outputs" = *static* ]]
@@ -164,6 +169,11 @@ _multioutDevs() { | |||
done | |||
} | |||
|
|||
_multioutStatic() { | |||
if [ "$outputs" = "out" ] || [ -z "${moveToStatic-1}" ]; then return; fi; | |||
find lib -name "*.a" -exec moveToOutput "{}" "${!outputStatic}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moveToOutput
is not a program, it can't be exec
'ed.
|
Another problem is that the On a side note, in this age where executables are PIE anyway for hardening reasons, what is actually different (with regards to code generation) in shared objects compared to static objects? There's a project (https://github.com/endrazine/wcc) which claims to be able to "[...] to 'unlink' (undo the work of a linker) ELF binaries, either executables or shared libraries, back into relocatable shared objects.". I wonder if that would work as a modern day replacement of getting each and every build system of every single package build both static and dynamic libs correctly? |
I had thought about this years ago, but I concluded that it will be better to do these as separate derivations and e.g. standardize something like There are a few reasons. One is that IIRC often you need to compile the objects twice anyway, due to using different flags, e.g. if you want static I gather you often don't want position-independent code (to prefer performance over some security advantages) – so you don't really save much CPU time by building them at once. And there are some technical problems, like you need to propagate a different set of dependencies, and also this horrible trouble: #12085 |
Yeah I am split on whether this is a good idea as well. I like the standardized ".static" output over the usually not standard "enableStatic" vs "useStatic" vs "static", etc. I want to enforce something like this & have it built by Hydra through something like #39580 with some Hydra release magic but that has stalled. I am closing this for now though because @vcunat raises some good points on the usefulness of this. |
Well, standardizing some name like |
Yes. Which do you prefer? I think enableStatic is the ideal one because it maps well to the very common --enable-static configure flag. The thing is we probably need a corresponding "enableShared" flag so that we can avoid having both in the closure. |
I would expect that by default enabling one would disable the other. |
Is that how the configure flag is supposed to work? I guess when I see --enable-static I had always assumed they weren't mutually exclusive - otherwise it would be something like --link-target=static or --link-target=shared but maybe that is the convention. |
The configure flags probably aren't exclusive (in standard autotools packaging), but for our flags it seems to make more sense, at least if we go this way of preferring to separate the static and shared builds... |
Using multiple outputs we can easily build static libraries. This is a proposal to always statically link things. Needs testing & discussion before merging.
/cc @orivej @nlewo @xeji