Skip to content
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] haskell: try to fix #41340 #56608

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions pkgs/development/haskell-modules/cabal-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Adds hooks to run for each dependency to the generic-builder.nix. There are two types of dependencies that Cabal needs to know about.

# - Haskell dependencies have a $package.conf.d directory that stores
# all necessary information for using the package as a dependency. -

# - External dependencies don’t have a package.conf.d directory. Cabal
# needs the --extra-include-dirs, --extra-lib-dirs, and
# --extra-framework-dirs to detect them. We only want to set
# --extra-lib-dirs when we know that there are actual libraries
# available and not meta information like cmake or pkgconfig data.

setupPackageConfDir="$TMPDIR/setup-package.conf.d"
mkdir -p $setupPackageConfDir

packageConfDir="$TMPDIR/package.conf.d"
mkdir -p $packageConfDir

# We build the Setup.hs on the *build* machine, and as such should
# only add dependencies for the build machine.

addCabalPkgDb() {
if [ -n "$(echo $1/lib/*/package.conf.d)" ]; then
cp -f $1/lib/*/package.conf.d/*.conf "$packageConfDir"
fi
}

addCabalSetupPkgDb() {
if [ -n "$(echo $1/lib/*/package.conf.d)" ]; then
cp -f $1/lib/*/package.conf.d/*.conf "$setupPackageConfDir"
fi
}

addCabalConfigureFlags() {
if [ -z "$(echo $1/lib/*/package.conf.d)" ]; then
if [ -d "$1/include" ]; then
configureFlags+=" --extra-include-dirs=$1/include"
fi
if [ -n "$(echo $1/lib/lib*)" ]; then
configureFlags+=" --extra-lib-dirs=$1/lib"
fi
if [ -d "$1/Library/Frameworks" ]; then
configureFlags+=" --extra-framework-dirs=$1/Library/Frameworks"
fi
fi
}

addEnvHooks "$hostOffset" addCabalSetupPkgDb
addEnvHooks "$targetOffset" addCabalPkgDb
addEnvHooks "$targetOffset" addCabalConfigureFlags
43 changes: 3 additions & 40 deletions pkgs/development/haskell-modules/generic-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ let

nativeGhcCommand = "${nativeGhc.targetPrefix}ghc";

buildPkgDb = ghcName: packageConfDir: ''
if [ -d "$p/lib/${ghcName}/package.conf.d" ]; then
cp -f "$p/lib/${ghcName}/package.conf.d/"*.conf ${packageConfDir}/
continue
fi
'';
in stdenv.lib.fix (drv:

assert allPkgconfigDepends != [] -> pkgconfig != null;
Expand All @@ -235,7 +229,8 @@ stdenv.mkDerivation ({

inherit src;

inherit depsBuildBuild nativeBuildInputs;
inherit depsBuildBuild;
nativeBuildInputs = [ ./cabal-hook.sh ] ++ nativeBuildInputs;
buildInputs = otherBuildInputs ++ optionals (!isLibrary) propagatedBuildInputs;
propagatedBuildInputs = optionals isLibrary propagatedBuildInputs;

Expand All @@ -258,43 +253,11 @@ stdenv.mkDerivation ({
echo "Build with ${ghc}."
${optionalString (isLibrary && hyperlinkSource) "export PATH=${hscolour}/bin:$PATH"}

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
+ ''
for p in "''${pkgsBuildBuild[@]}" "''${pkgsBuildHost[@]}" "''${pkgsBuildTarget[@]}"; do
${buildPkgDb nativeGhc.name "$setupPackageConfDir"}
done

${nativeGhcCommand}-pkg --${nativePackageDbFlag}="$setupPackageConfDir" recache
''
# For normal components
+ ''
for p in "''${pkgsHostHost[@]}" "''${pkgsHostTarget[@]}"; do
${buildPkgDb ghc.name "$packageConfDir"}
if [ -d "$p/include" ]; then
configureFlags+=" --extra-include-dirs=$p/include"
fi
if [ -d "$p/lib" ]; then
configureFlags+=" --extra-lib-dirs=$p/lib"
fi
''
# It is not clear why --extra-framework-dirs does work fine on Linux
+ optionalString (!stdenv.buildPlatform.isDarwin || versionAtLeast nativeGhc.version "8.0") ''
if [[ -d "$p/Library/Frameworks" ]]; then
configureFlags+=" --extra-framework-dirs=$p/Library/Frameworks"
fi
'' + ''
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
Expand Down