diff options
author | John Ericson <Ericson2314@yahoo.com> | 2018-05-25 11:09:07 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-25 11:09:07 -0400 |
commit | ce0180dfd56cc00223daa5ad99d4b5611f09c542 (patch) | |
tree | 34758a88217c178ec3ba6d6e9ddb336d4b8addbb /pkgs/development/haskell-modules | |
parent | a0c480ab1ff65aee2b817ed5c480553bb6ef95c1 (diff) | |
parent | fe1eec9e24ba24f468649c14529be9d7a7c720d4 (diff) | |
download | nixlib-ce0180dfd56cc00223daa5ad99d4b5611f09c542.tar nixlib-ce0180dfd56cc00223daa5ad99d4b5611f09c542.tar.gz nixlib-ce0180dfd56cc00223daa5ad99d4b5611f09c542.tar.bz2 nixlib-ce0180dfd56cc00223daa5ad99d4b5611f09c542.tar.lz nixlib-ce0180dfd56cc00223daa5ad99d4b5611f09c542.tar.xz nixlib-ce0180dfd56cc00223daa5ad99d4b5611f09c542.tar.zst nixlib-ce0180dfd56cc00223daa5ad99d4b5611f09c542.zip |
Merge pull request #40996 from obsidiansystems/cross-ghc
ghc, haskell-infra: #40929 take 2
Diffstat (limited to 'pkgs/development/haskell-modules')
-rw-r--r-- | pkgs/development/haskell-modules/configuration-nix.nix | 2 | ||||
-rw-r--r-- | pkgs/development/haskell-modules/generic-builder.nix | 72 | ||||
-rw-r--r-- | pkgs/development/haskell-modules/lib.nix | 2 |
3 files changed, 58 insertions, 18 deletions
diff --git a/pkgs/development/haskell-modules/configuration-nix.nix b/pkgs/development/haskell-modules/configuration-nix.nix index 469b249010fa..2f1eb1ad97a8 100644 --- a/pkgs/development/haskell-modules/configuration-nix.nix +++ b/pkgs/development/haskell-modules/configuration-nix.nix @@ -128,7 +128,7 @@ self: super: builtins.intersectAttrs super { # Prevents needing to add security_tool as a build tool to all of x509-system's # dependencies. - x509-system = if pkgs.stdenv.isDarwin && !pkgs.stdenv.cc.nativeLibc + x509-system = if pkgs.stdenv.targetPlatform.isDarwin && !pkgs.stdenv.cc.nativeLibc then let inherit (pkgs.darwin) security_tool; in pkgs.lib.overrideDerivation (addBuildDepend super.x509-system security_tool) (drv: { postPatch = (drv.postPatch or "") + '' diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index f08130a3157a..8d9b596276c3 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -19,6 +19,7 @@ in , buildTarget ? "" , buildTools ? [], libraryToolDepends ? [], executableToolDepends ? [], testToolDepends ? [], benchmarkToolDepends ? [] , configureFlags ? [] +, buildFlags ? [] , description ? "" , doCheck ? !isCross && stdenv.lib.versionOlder "7.4" ghc.version , doBenchmark ? false @@ -31,7 +32,7 @@ in , enableSharedExecutables ? false , enableSharedLibraries ? ((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version) , enableDeadCodeElimination ? (!stdenv.isDarwin) # TODO: use -dead_strip for darwin -, enableStaticLibraries ? true +, enableStaticLibraries ? !hostPlatform.isWindows , enableHsc2hsViaAsm ? hostPlatform.isWindows && stdenv.lib.versionAtLeast ghc.version "8.4" , extraLibraries ? [], librarySystemDepends ? [], executableSystemDepends ? [] , homepage ? "http://hackage.haskell.org/package/${pname}" @@ -68,6 +69,10 @@ in assert editedCabalFile != null -> revision != null; +# --enable-static does not work on windows. This is a bug in GHC. +# --enable-static will pass -staticlib to ghc, which only works for mach-o and elf. +assert hostPlatform.isWindows -> enableStaticLibraries == false; + let inherit (stdenv.lib) optional optionals optionalString versionOlder versionAtLeast @@ -126,6 +131,8 @@ let crossCabalFlagsString = stdenv.lib.optionalString isCross (" " + stdenv.lib.concatStringsSep " " crossCabalFlags); + buildFlagsString = optionalString (buildFlags != []) (" " + concatStringsSep " " buildFlags); + defaultConfigureFlags = [ "--verbose" "--prefix=$out" "--libdir=\\$prefix/lib/\\$compiler" "--libsubdir=\\$pkgid" (optionalString enableSeparateDataOutput "--datadir=$data/share/${ghc.name}") @@ -169,18 +176,22 @@ let optionals doCheck testPkgconfigDepends ++ optionals doBenchmark benchmarkPkgconfigDepends; nativeBuildInputs = [ ghc nativeGhc removeReferencesTo ] ++ optional (allPkgconfigDepends != []) pkgconfig ++ + setupHaskellDepends ++ buildTools ++ libraryToolDepends ++ executableToolDepends; propagatedBuildInputs = buildDepends ++ libraryHaskellDepends ++ executableHaskellDepends; - otherBuildInputs = setupHaskellDepends ++ extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++ + otherBuildInputs = extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++ allPkgconfigDepends ++ optionals doCheck (testDepends ++ testHaskellDepends ++ testSystemDepends ++ testToolDepends) ++ optionals doBenchmark (benchmarkDepends ++ benchmarkHaskellDepends ++ benchmarkSystemDepends ++ benchmarkToolDepends); + allBuildInputs = propagatedBuildInputs ++ otherBuildInputs; haskellBuildInputs = stdenv.lib.filter isHaskellPkg allBuildInputs; systemBuildInputs = stdenv.lib.filter isSystemPkg allBuildInputs; - ghcEnv = ghc.withPackages (p: haskellBuildInputs); + # When not cross compiling, also include Setup.hs dependencies. + ghcEnv = ghc.withPackages (p: + haskellBuildInputs ++ stdenv.lib.optional (!isCross) setupHaskellDepends); setupCommand = "./Setup"; @@ -190,6 +201,22 @@ let nativeGhcCommand = "${nativeGhc.targetPrefix}ghc"; + buildPkgDb = ghcName: '' + if [ -d "$p/lib/${ghcName}/package.conf.d" ]; then + cp -f "$p/lib/${ghcName}/package.conf.d/"*.conf $packageConfDir/ + continue + fi + if [ -d "$p/include" ]; then + configureFlags+=" --extra-include-dirs=$p/include" + fi + if [ -d "$p/lib" ]; then + configureFlags+=" --extra-lib-dirs=$p/lib" + fi + if [[ -d "$p/Library/Frameworks" ]]; then + configureFlags+=" --extra-framework-dirs=$p/Library/Frameworks" + fi + ''; + in assert allPkgconfigDepends != [] -> pkgconfig != null; @@ -230,30 +257,37 @@ stdenv.mkDerivation ({ echo "Build with ${ghc}." ${optionalString (hasActiveLibrary && hyperlinkSource) "export PATH=${hscolour}/bin:$PATH"} + '' + (optionalString (setupHaskellDepends != []) '' + setupPackageConfDir="$TMPDIR/setup-package.conf.d" + mkdir -p $setupPackageConfDir + '') + '' packageConfDir="$TMPDIR/package.conf.d" mkdir -p $packageConfDir setupCompileFlags="${concatStringsSep " " setupCompileFlags}" configureFlags="${concatStringsSep " " defaultConfigureFlags} $configureFlags" + '' + # We build the Setup.hs on the *build* machine, and as such should only add + # dependencies for the build machine. + # + # pkgs* arrays defined in stdenv/setup.hs + + (optionalString (setupHaskellDepends != []) '' + for p in "''${pkgsBuildBuild[@]}" "''${pkgsBuildHost[@]}" "''${pkgsBuildTarget[@]}"; do + ${buildPkgDb nativeGhc.name} + done + ${nativeGhcCommand}-pkg --${nativePackageDbFlag}="$setupPackageConfDir" recache + '') - # host.*Pkgs defined in stdenv/setup.hs + # For normal components + + '' for p in "''${pkgsHostHost[@]}" "''${pkgsHostTarget[@]}"; do - if [ -d "$p/lib/${ghc.name}/package.conf.d" ]; then - cp -f "$p/lib/${ghc.name}/package.conf.d/"*.conf $packageConfDir/ - continue - fi - if [ -d "$p/include" ]; then - configureFlags+=" --extra-include-dirs=$p/include" - fi - if [ -d "$p/lib" ]; then - configureFlags+=" --extra-lib-dirs=$p/lib" - fi + ${buildPkgDb ghc.name} done '' # only use the links hack if we're actually building dylibs. otherwise, the # "dynamic-library-dirs" point to nonexistent paths, and the ln command becomes # "ln -s $out/lib/links", which tries to recreate the links dir and fails - + (optionalString (stdenv.isDarwin && enableSharedLibraries) '' + + (optionalString (stdenv.isDarwin && (enableSharedLibraries || enableSharedExecutables)) '' # Work around a limit in the macOS Sierra linker on the number of paths # referenced by any one dynamic library: # @@ -282,7 +316,11 @@ stdenv.mkDerivation ({ done echo setupCompileFlags: $setupCompileFlags - ${nativeGhcCommand} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i + ${optionalString (setupHaskellDepends != []) + '' + echo GHC_PACKAGE_PATH="$setupPackageConfDir:" + GHC_PACKAGE_PATH="$setupPackageConfDir:" '' + }${nativeGhcCommand} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i runHook postCompileBuildDriver ''; @@ -310,7 +348,7 @@ stdenv.mkDerivation ({ buildPhase = '' runHook preBuild - ${setupCommand} build ${buildTarget}${crossCabalFlagsString} + ${setupCommand} build ${buildTarget}${crossCabalFlagsString}${buildFlagsString} runHook postBuild ''; diff --git a/pkgs/development/haskell-modules/lib.nix b/pkgs/development/haskell-modules/lib.nix index 55e45bd6559d..fb1302f60ea5 100644 --- a/pkgs/development/haskell-modules/lib.nix +++ b/pkgs/development/haskell-modules/lib.nix @@ -131,6 +131,8 @@ rec { */ appendConfigureFlag = drv: x: overrideCabal drv (drv: { configureFlags = (drv.configureFlags or []) ++ [x]; }); + appendBuildFlag = drv: x: overrideCabal drv (drv: { buildFlags = (drv.buildFlags or []) ++ [x]; }); + appendBuildFlags = drv: xs: overrideCabal drv (drv: { buildFlags = (drv.buildFlags or []) ++ xs; }); /* removeConfigureFlag drv x is a Haskell package like drv, but with all cabal configure arguments that are equal to x removed. |