haskell-generic-builder: re-factor for improved modularity
This commit is contained in:
parent
e6ecb1fb83
commit
54bbfd5440
@ -7,6 +7,7 @@
|
|||||||
, sha256 ? null
|
, sha256 ? null
|
||||||
, src ? fetchurl { url = "mirror://hackage/${pname}-${version}.tar.gz"; inherit sha256; }
|
, src ? fetchurl { url = "mirror://hackage/${pname}-${version}.tar.gz"; inherit sha256; }
|
||||||
, buildDepends ? []
|
, buildDepends ? []
|
||||||
|
, buildTarget ? ""
|
||||||
, buildTools ? []
|
, buildTools ? []
|
||||||
, configureFlags ? []
|
, configureFlags ? []
|
||||||
, description ? ""
|
, description ? ""
|
||||||
@ -50,6 +51,11 @@ let
|
|||||||
inherit (stdenv.lib) optional optionals optionalString versionOlder
|
inherit (stdenv.lib) optional optionals optionalString versionOlder
|
||||||
concatStringsSep enableFeature optionalAttrs;
|
concatStringsSep enableFeature optionalAttrs;
|
||||||
|
|
||||||
|
newCabalFile = fetchurl {
|
||||||
|
url = "http://hackage.haskell.org/package/${pname}-${version}/${pname}.cabal";
|
||||||
|
sha256 = editedCabalFile;
|
||||||
|
};
|
||||||
|
|
||||||
defaultSetupHs = builtins.toFile "Setup.hs" ''
|
defaultSetupHs = builtins.toFile "Setup.hs" ''
|
||||||
import Distribution.Simple
|
import Distribution.Simple
|
||||||
main = defaultMain
|
main = defaultMain
|
||||||
@ -58,7 +64,18 @@ let
|
|||||||
ghc76xOrLater = stdenv.lib.versionOlder "7.6" ghc.version;
|
ghc76xOrLater = stdenv.lib.versionOlder "7.6" ghc.version;
|
||||||
packageDbFlag = if ghc76xOrLater then "package-db" else "package-conf";
|
packageDbFlag = if ghc76xOrLater then "package-db" else "package-conf";
|
||||||
|
|
||||||
|
hasActiveLibrary = isLibrary && (enableStaticLibraries || enableSharedLibraries || enableLibraryProfiling);
|
||||||
|
|
||||||
|
enableParallelBuilding = versionOlder "7.8" ghc.version && !hasActiveLibrary;
|
||||||
|
|
||||||
defaultConfigureFlags = [
|
defaultConfigureFlags = [
|
||||||
|
"--verbose" "--prefix=$out" "--libdir=\\$prefix/lib/\\$compiler" "--libsubdir=\\$pkgid"
|
||||||
|
"--with-gcc=$CC" # Clang won't work without that extra information.
|
||||||
|
"--package-db=$packageConfDir"
|
||||||
|
(optionalString (enableSharedExecutables && stdenv.isLinux) "--ghc-option=-optl=-Wl,-rpath=$out/lib/${ghc.name}/${pname}-${version}")
|
||||||
|
(optionalString (enableSharedExecutables && stdenv.isDarwin) "--ghc-option=-optl=-Wl,-headerpad_max_install_names")
|
||||||
|
(optionalString enableParallelBuilding "--ghc-option=-j$NIX_BUILD_CORES")
|
||||||
|
(optionalString (useCpphs) "--with-cpphs=${cpphs}/bin/cpphs --ghc-options=-cpp --ghc-options=-pgmP${cpphs}/bin/cpphs --ghc-options=-optP--cpp")
|
||||||
(enableFeature enableSplitObjs "split-objs")
|
(enableFeature enableSplitObjs "split-objs")
|
||||||
(enableFeature enableLibraryProfiling "library-profiling")
|
(enableFeature enableLibraryProfiling "library-profiling")
|
||||||
(enableFeature enableSharedLibraries "shared")
|
(enableFeature enableSharedLibraries "shared")
|
||||||
@ -67,21 +84,21 @@ let
|
|||||||
(optionalString (versionOlder "7" ghc.version) (enableFeature doCheck "tests"))
|
(optionalString (versionOlder "7" ghc.version) (enableFeature doCheck "tests"))
|
||||||
];
|
];
|
||||||
|
|
||||||
hasActiveLibrary = isLibrary && (enableStaticLibraries || enableSharedLibraries);
|
setupCompileFlags = [
|
||||||
|
(optionalString (!coreSetup) "-${packageDbFlag}=$packageConfDir")
|
||||||
|
(optionalString (versionOlder "7.8" ghc.version) "-j$NIX_BUILD_CORES")
|
||||||
|
];
|
||||||
|
|
||||||
newCabalFile = fetchurl {
|
isHaskellPkg = x: (x ? pname) && (x ? version) && (x ? env);
|
||||||
url = "http://hackage.haskell.org/package/${pname}-${version}/${pname}.cabal";
|
|
||||||
sha256 = editedCabalFile;
|
|
||||||
};
|
|
||||||
|
|
||||||
isHaskellPkg = x: (x ? pname) && (x ? version);
|
|
||||||
isSystemPkg = x: !isHaskellPkg x;
|
isSystemPkg = x: !isHaskellPkg x;
|
||||||
|
|
||||||
allBuildInputs = stdenv.lib.filter (x: x != null) (
|
propagatedBuildInputs = buildDepends;
|
||||||
buildDepends ++ extraLibraries ++ buildTools ++
|
otherBuildInputs = extraLibraries ++
|
||||||
|
buildTools ++
|
||||||
optionals (pkgconfigDepends != []) ([pkgconfig] ++ pkgconfigDepends) ++
|
optionals (pkgconfigDepends != []) ([pkgconfig] ++ pkgconfigDepends) ++
|
||||||
optionals doCheck testDepends
|
optionals doCheck testDepends;
|
||||||
);
|
allBuildInputs = propagatedBuildInputs ++ otherBuildInputs;
|
||||||
|
|
||||||
haskellBuildInputs = stdenv.lib.filter isHaskellPkg allBuildInputs;
|
haskellBuildInputs = stdenv.lib.filter isHaskellPkg allBuildInputs;
|
||||||
systemBuildInputs = stdenv.lib.filter isSystemPkg allBuildInputs;
|
systemBuildInputs = stdenv.lib.filter isSystemPkg allBuildInputs;
|
||||||
|
|
||||||
@ -91,46 +108,31 @@ in
|
|||||||
stdenv.mkDerivation ({
|
stdenv.mkDerivation ({
|
||||||
name = "${optionalString hasActiveLibrary "haskell-"}${pname}-${version}";
|
name = "${optionalString hasActiveLibrary "haskell-"}${pname}-${version}";
|
||||||
|
|
||||||
|
prePhases = ["setupCompilerEnvironmentPhase"];
|
||||||
|
preConfigurePhases = ["jailbreakPhase" "compileBuildDriverPhase"];
|
||||||
|
preInstallPhases = ["haddockPhase"];
|
||||||
|
|
||||||
inherit src;
|
inherit src;
|
||||||
|
|
||||||
nativeBuildInputs = extraLibraries ++ buildTools ++
|
nativeBuildInputs = otherBuildInputs ++ optionals (!hasActiveLibrary) propagatedBuildInputs;
|
||||||
optionals (pkgconfigDepends != []) ([pkgconfig] ++ pkgconfigDepends) ++
|
propagatedNativeBuildInputs = optionals hasActiveLibrary propagatedBuildInputs;
|
||||||
optionals doCheck testDepends ++
|
|
||||||
optionals (!hasActiveLibrary) buildDepends;
|
|
||||||
propagatedNativeBuildInputs = optionals hasActiveLibrary buildDepends;
|
|
||||||
|
|
||||||
# GHC needs the locale configured during the Haddock phase.
|
LANG = "en_US.UTF-8"; # GHC needs the locale configured during the Haddock phase.
|
||||||
LANG = "en_US.UTF-8";
|
|
||||||
LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive";
|
LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive";
|
||||||
|
|
||||||
configurePhase = ''
|
setupCompilerEnvironmentPhase = ''
|
||||||
runHook preConfigure
|
runHook preSetupCompilerEnvironment
|
||||||
|
|
||||||
echo "Building with ${ghc}."
|
echo "Building with ${ghc}."
|
||||||
export PATH="${ghc}/bin:$PATH"
|
export PATH="${ghc}/bin:$PATH"
|
||||||
${optionalString (hasActiveLibrary && hyperlinkSource) "export PATH=${hscolour}/bin:$PATH"}
|
${optionalString (hasActiveLibrary && hyperlinkSource) "export PATH=${hscolour}/bin:$PATH"}
|
||||||
|
|
||||||
configureFlags="--verbose --prefix=$out --libdir=\$prefix/lib/\$compiler --libsubdir=\$pkgid $configureFlags"
|
|
||||||
configureFlags+=' ${concatStringsSep " " defaultConfigureFlags}'
|
|
||||||
${optionalString (enableSharedExecutables && stdenv.isLinux) ''
|
|
||||||
configureFlags+=" --ghc-option=-optl=-Wl,-rpath=$out/lib/${ghc.name}/${pname}-${version}"
|
|
||||||
''}
|
|
||||||
${optionalString (enableSharedExecutables && stdenv.isDarwin) ''
|
|
||||||
configureFlags+=" --ghc-option=-optl=-Wl,-headerpad_max_install_names"
|
|
||||||
''}
|
|
||||||
${optionalString (versionOlder "7.8" ghc.version && !isLibrary) ''
|
|
||||||
configureFlags+=" --ghc-option=-j$NIX_BUILD_CORES"
|
|
||||||
setupCompileFlags="-j$NIX_BUILD_CORES"
|
|
||||||
''}${optionalString stdenv.isDarwin ''
|
|
||||||
configureFlags+=" --with-gcc=$CC" # Cabal won't find clang without help.
|
|
||||||
''}${optionalString useCpphs ''
|
|
||||||
configureFlags+=" --with-cpphs=${cpphs}/bin/cpphs"
|
|
||||||
configureFlags+=" --ghc-options=-cpp --ghc-options=-pgmP${cpphs}/bin/cpphs --ghc-options=-optP--cpp"
|
|
||||||
''}
|
|
||||||
|
|
||||||
packageConfDir="$TMP/package.conf.d"
|
packageConfDir="$TMP/package.conf.d"
|
||||||
mkdir -p $packageConfDir
|
mkdir -p $packageConfDir
|
||||||
|
|
||||||
|
setupCompileFlags="${concatStringsSep " " setupCompileFlags}"
|
||||||
|
configureFlags="${concatStringsSep " " defaultConfigureFlags} $configureFlags"
|
||||||
|
|
||||||
local inputClosure=""
|
local inputClosure=""
|
||||||
for i in $propagatedNativeBuildInputs $nativeBuildInputs; do
|
for i in $propagatedNativeBuildInputs $nativeBuildInputs; do
|
||||||
findInputs $i inputClosure propagated-native-build-inputs
|
findInputs $i inputClosure propagated-native-build-inputs
|
||||||
@ -150,25 +152,43 @@ stdenv.mkDerivation ({
|
|||||||
done
|
done
|
||||||
done
|
done
|
||||||
ghc-pkg --${packageDbFlag}="$packageConfDir" recache
|
ghc-pkg --${packageDbFlag}="$packageConfDir" recache
|
||||||
configureFlags+=" --package-db=$packageConfDir"
|
|
||||||
|
runHook postSetupCompilerEnvironment
|
||||||
|
'';
|
||||||
|
|
||||||
|
jailbreakPhase = ''
|
||||||
|
runHook preJailbreak
|
||||||
|
|
||||||
${optionalString (editedCabalFile != null) ''
|
${optionalString (editedCabalFile != null) ''
|
||||||
echo "Replacing Cabal file with edited version ${newCabalFile}."
|
echo "Replacing Cabal file with edited version ${newCabalFile}."
|
||||||
cp ${newCabalFile} ${pname}.cabal
|
cp ${newCabalFile} ${pname}.cabal
|
||||||
''}
|
''}${optionalString jailbreak ''
|
||||||
|
|
||||||
${optionalString jailbreak ''
|
|
||||||
echo "Running jailbreak-cabal to lift version restrictions on build inputs."
|
echo "Running jailbreak-cabal to lift version restrictions on build inputs."
|
||||||
${jailbreak-cabal}/bin/jailbreak-cabal ${pname}.cabal
|
${jailbreak-cabal}/bin/jailbreak-cabal ${pname}.cabal
|
||||||
''}
|
''}
|
||||||
|
|
||||||
|
runHook postJailbreak
|
||||||
|
'';
|
||||||
|
|
||||||
|
compileBuildDriverPhase = ''
|
||||||
|
runHook preCompileBuildDriver
|
||||||
|
|
||||||
for i in Setup.hs Setup.lhs ${defaultSetupHs}; do
|
for i in Setup.hs Setup.lhs ${defaultSetupHs}; do
|
||||||
test -f $i && break
|
test -f $i && break
|
||||||
done
|
done
|
||||||
ghc ${optionalString (! coreSetup) "-${packageDbFlag}=$packageConfDir "}$setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
|
|
||||||
|
echo setupCompileFlags: $setupCompileFlags
|
||||||
|
ghc $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
|
||||||
|
|
||||||
|
runHook postCompileBuildDriver
|
||||||
|
'';
|
||||||
|
|
||||||
|
configurePhase = ''
|
||||||
|
runHook preConfigure
|
||||||
|
|
||||||
|
unset GHC_PACKAGE_PATH # Cabal complains if this variable is set during configure.
|
||||||
|
|
||||||
echo configureFlags: $configureFlags
|
echo configureFlags: $configureFlags
|
||||||
unset GHC_PACKAGE_PATH # Cabal complains if this variable is set during configure.
|
|
||||||
./Setup configure $configureFlags 2>&1 | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log"
|
./Setup configure $configureFlags 2>&1 | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log"
|
||||||
if ${gnugrep}/bin/egrep -q '^Warning:.*depends on multiple versions' "$NIX_BUILD_TOP/cabal-configure.log"; then
|
if ${gnugrep}/bin/egrep -q '^Warning:.*depends on multiple versions' "$NIX_BUILD_TOP/cabal-configure.log"; then
|
||||||
echo >&2 "*** abort because of serious configure-time warning from Cabal"
|
echo >&2 "*** abort because of serious configure-time warning from Cabal"
|
||||||
@ -182,12 +202,7 @@ stdenv.mkDerivation ({
|
|||||||
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
runHook preBuild
|
runHook preBuild
|
||||||
./Setup build
|
./Setup build ${buildTarget}
|
||||||
${optionalString (!noHaddock && hasActiveLibrary) ''
|
|
||||||
./Setup haddock --html \
|
|
||||||
${optionalString doHoogle "--hoogle"} \
|
|
||||||
${optionalString (hasActiveLibrary && hyperlinkSource) "--hyperlink-source"}
|
|
||||||
''}
|
|
||||||
runHook postBuild
|
runHook postBuild
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@ -197,6 +212,16 @@ stdenv.mkDerivation ({
|
|||||||
runHook postCheck
|
runHook postCheck
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
haddockPhase = ''
|
||||||
|
runHook preHaddock
|
||||||
|
${optionalString (!noHaddock && hasActiveLibrary) ''
|
||||||
|
./Setup haddock --html \
|
||||||
|
${optionalString doHoogle "--hoogle"} \
|
||||||
|
${optionalString (hasActiveLibrary && hyperlinkSource) "--hyperlink-source"}
|
||||||
|
''}
|
||||||
|
runHook postHaddock
|
||||||
|
'';
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
|
|
||||||
@ -242,10 +267,11 @@ stdenv.mkDerivation ({
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
meta = { inherit homepage license platforms hydraPlatforms; }
|
meta = { inherit homepage license platforms; }
|
||||||
// optionalAttrs broken { inherit broken; }
|
// optionalAttrs broken { inherit broken; }
|
||||||
// optionalAttrs (description != "") { inherit description; }
|
// optionalAttrs (description != "") { inherit description; }
|
||||||
// optionalAttrs (maintainers != []) { inherit maintainers; }
|
// optionalAttrs (maintainers != []) { inherit maintainers; }
|
||||||
|
// optionalAttrs (hydraPlatforms != platforms) { inherit hydraPlatforms; }
|
||||||
;
|
;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ let
|
|||||||
libDir = "$out/lib/ghc-${ghc.version}";
|
libDir = "$out/lib/ghc-${ghc.version}";
|
||||||
docDir = "$out/share/doc/ghc/html";
|
docDir = "$out/share/doc/ghc/html";
|
||||||
packageCfgDir = "${libDir}/package.conf.d";
|
packageCfgDir = "${libDir}/package.conf.d";
|
||||||
isHaskellPkg = x: (x ? pname) && (x ? version);
|
isHaskellPkg = x: (x ? pname) && (x ? version) && (x ? env);
|
||||||
paths = stdenv.lib.filter isHaskellPkg (stdenv.lib.closePropagation packages);
|
paths = stdenv.lib.filter isHaskellPkg (stdenv.lib.closePropagation packages);
|
||||||
in
|
in
|
||||||
if paths == [] then ghc else
|
if paths == [] then ghc else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user