Skip to content

Commit

Permalink
multiple-outputs: always build static libraries
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matthewbauer committed Jun 13, 2018
1 parent ea69fba commit 7ba86ce
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkgs/build-support/setup-hooks/multiple-outputs.sh
Expand Up @@ -2,6 +2,7 @@
preConfigureHooks+=(_multioutConfig)
preFixupHooks+=(_multioutDocs)
preFixupHooks+=(_multioutDevs)
preFixupHooks+=(_multioutStatic)
postFixupHooks+=(_multioutPropagateDev)

# Assign the first string containing nonempty variable to the variable named $1
Expand Down Expand Up @@ -37,6 +38,9 @@ _overrideFirst outputInclude "$outputDev"
# so-libs are often among the main things to keep, and so go to $out
_overrideFirst outputLib "lib" "out"

# statically linked libraries
_overrideFirst outputStatic "static" "lib" "out"

_overrideFirst outputDoc "doc" "out"
_overrideFirst outputDevdoc "devdoc" REMOVE # documentation for developers
# man and info pages are small and often useful to distribute with binaries
Expand Down Expand Up @@ -73,6 +77,7 @@ _multioutConfig() {
--docdir=${!outputDoc}/share/doc/${shareDocName} \
--libdir=${!outputLib}/lib --libexecdir=${!outputLib}/libexec \
--localedir=${!outputLib}/share/locale \
--enable-static \

This comment has been minimized.

Copy link
@orivej

orivej Jun 13, 2018

Contributor

AFAIK sometimes this disables building shared libraries, and some projects do not support building the shared and the static libraries simultaneously.

This comment has been minimized.

Copy link
@orivej

orivej Jun 13, 2018

Contributor

Another two issues are that the library output of derivations without static output may double, and that this may cause programs to be linked statically — we don't want that.

$configureFlags"

installFlags="\
Expand Down Expand Up @@ -164,6 +169,11 @@ _multioutDevs() {
done
}

_multioutStatic() {
if [ "$outputs" = "out" ] || [ -z "${moveToStatic-1}" ]; then return; fi;
find lib -name "*.a" -exec moveToOutput "{}" "${!outputStatic}"

This comment has been minimized.

Copy link
@orivej

orivej Jun 13, 2018

Contributor

If the goal is to ship .a files than this is enough. If the goal is to make them usable from another project, that's a different matter. The main issue is that .a files do not list their dependencies. If the library ships a pkg-config definition, that definition is probably usable both with the dynamic and the static versions of the library. If it ships a libtool description in a .la file, that file has to provide accurate dependency information (we don't ensure that) and it has to be placed near the library (hence it should be moved or copied to the static output, and maybe adjusted after that).

}

# Make the "dev" propagate other outputs needed for development.
_multioutPropagateDev() {
if [ "$outputs" = "out" ]; then return; fi;
Expand Down

0 comments on commit 7ba86ce

Please sign in to comment.