git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #7734 from cstrahan/ghcjs-improvements

ghcjs: properly wrap binaries in environment

commit7fd7cf69af23ae4c63981bfc7e72aedc38836447 authorPeter Simons <simons@cryp.to> dateFri 8 May 2015, 18:26 (12 years ago) parent3f88df131dde16
6 files changed+131−51
pkgs/development/compilers/ghcjs/default.nix+9−8 pkgs/development/compilers/ghcjs/ghcjs.patch+13−7 pkgs/development/haskell-modules/configuration-ghcjs.nix+4 pkgs/development/haskell-modules/generic-builder.nix+15−14 pkgs/development/haskell-modules/ghc-paths-nix-ghcjs.patch+65 pkgs/development/haskell-modules/with-packages-wrapper.nix+25−22
pkgs/development/compilers/ghcjs/default.nix+9−8
@@ -39,10 +39,6 @@
3939}:
4040let
4141 version = "0.1.0";
42− ghcArch = if pkgs.stdenv.system == "i686-linux"
43− then "i386-linux"
44− else pkgs.stdenv.system;
45− libDir = "share/ghcjs/${ghcArch}-${version}-${ghc.version}/ghcjs";
4642 ghcjsBoot = fetchgit {
4743 url = git://github.com/ghcjs/ghcjs-boot.git;
4844 rev = "ab8765edcb507b8b810e3c324fd5bd5af2b69d8f"; # 7.10 branch
@@ -84,14 +80,19 @@ in mkDerivation (rec {
8480 ];
8581 patches = [ ./ghcjs.patch ];
8682 postPatch = ''
87− substituteInPlace Setup.hs --replace "/usr/bin/env" "${coreutils}/bin/env"
88− substituteInPlace src/Compiler/Info.hs --replace "@PREFIX@" "$out"
83+ substituteInPlace Setup.hs \
84+ --replace "/usr/bin/env" "${coreutils}/bin/env"
85+
86+ substituteInPlace src/Compiler/Info.hs \
87+ --replace "@PREFIX@" "$out" \
88+ --replace "@VERSION@" "${version}"
89+
8990 substituteInPlace src-bin/Boot.hs \
9091 --replace "@PREFIX@" "$out" \
9192 --replace "@CC@" "${stdenv.cc}/bin/cc"
9293 '';
9394 preBuild = ''
94− local topDir=$out/${libDir}
95+ local topDir=$out/lib/ghcjs-${version}
9596 mkdir -p $topDir
9697
9798 cp -r ${ghcjsBoot} $topDir/ghcjs-boot
@@ -116,9 +117,9 @@ in mkDerivation (rec {
116117 --with-gmp-libraries ${gmp}/lib
117118 '';
118119 passthru = {
119− inherit libDir;
120120 isGhcjs = true;
121121 nativeGhc = ghc;
122+ inherit nodejs;
122123 };
123124
124125 homepage = "https://github.com/ghcjs/ghcjs";
pkgs/development/compilers/ghcjs/ghcjs.patch+13−7
@@ -60,15 +60,21 @@ index 3c68dcf..64f3cf7 100644
6060 , "--haddock-html"
6161 -- workaround for hoogle support being broken in haddock for GHC 7.10RC1
6262diff --git a/src/Compiler/Info.hs b/src/Compiler/Info.hs
63−index 33a401f..5d09c86 100644
63+index 33a401f..79833c5 100644
6464--- a/src/Compiler/Info.hs
6565+++ b/src/Compiler/Info.hs
66−@@ -49,7 +49,7 @@ compilerInfo nativeToo dflags = do
66+@@ -48,13 +48,7 @@ compilerInfo nativeToo dflags = do
67+
6768 -- | the directory to use if started without -B flag
6869 getDefaultTopDir :: IO FilePath
69− getDefaultTopDir = do
70+-getDefaultTopDir = do
7071- appdir <- getAppUserDataDirectory "ghcjs"
71−+ let appdir = "@PREFIX@/share/ghcjs"
72− return (appdir </> subdir </> "ghcjs")
73− where
74− targetARCH = arch
72+- return (appdir </> subdir </> "ghcjs")
73+- where
74+- targetARCH = arch
75+- targetOS = os
76+- subdir = targetARCH ++ '-':targetOS ++ '-':getFullCompilerVersion
77++getDefaultTopDir = return "@PREFIX@/lib/ghcjs-@VERSION@"
78+
79+ getDefaultLibDir :: IO FilePath
80+ getDefaultLibDir = getDefaultTopDir
pkgs/development/haskell-modules/configuration-ghcjs.nix+4
@@ -99,4 +99,8 @@ self: super: {
9999 buildDepends = [ self.base self.mtl self.text self.ghcjs-base ];
100100 });
101101
102+ ghc-paths = overrideCabal super.ghc-paths (drv: {
103+ patches = [ ./ghc-paths-nix-ghcjs.patch ];
104+ });
105+
102106}
pkgs/development/haskell-modules/generic-builder.nix+15−14
@@ -51,7 +51,7 @@ assert editedCabalFile != null -> revision != null;
5151let
5252
5353 inherit (stdenv.lib) optional optionals optionalString versionOlder
54− concatStringsSep enableFeature optionalAttrs;
54+ concatStringsSep enableFeature optionalAttrs toUpper;
5555
5656 isGhcjs = ghc.isGhcjs or false;
5757
@@ -114,8 +114,9 @@ let
114114
115115 ghcEnv = ghc.withPackages (p: haskellBuildInputs);
116116
117− setupBuilder = if isGhcjs then "${ghc.nativeGhc}/bin/ghc" else "ghc";
117+ setupCommand = if isGhcjs then "${ghc.nodejs}/bin/node ./Setup.jsexe/all.js" else "./Setup";
118118 ghcCommand = if isGhcjs then "ghcjs" else "ghc";
119+ ghcCommandCaps = toUpper ghcCommand;
119120
120121in
121122stdenv.mkDerivation ({
@@ -186,7 +187,7 @@ stdenv.mkDerivation ({
186187 done
187188
188189 echo setupCompileFlags: $setupCompileFlags
189− ${setupBuilder} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
190+ ${ghcCommand} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
190191
191192 runHook postCompileBuildDriver
192193 '';
@@ -197,7 +198,7 @@ stdenv.mkDerivation ({
197198 unset GHC_PACKAGE_PATH # Cabal complains if this variable is set during configure.
198199
199200 echo configureFlags: $configureFlags
200− ./Setup configure $configureFlags 2>&1 | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log"
201+ ${setupCommand} configure $configureFlags 2>&1 | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log"
201202 if ${gnugrep}/bin/egrep -q '^Warning:.*depends on multiple versions' "$NIX_BUILD_TOP/cabal-configure.log"; then
202203 echo >&2 "*** abort because of serious configure-time warning from Cabal"
203204 exit 1
@@ -210,20 +211,20 @@ stdenv.mkDerivation ({
210211
211212 buildPhase = ''
212213 runHook preBuild
213− ./Setup build ${buildTarget}
214+ ${setupCommand} build ${buildTarget}
214215 runHook postBuild
215216 '';
216217
217218 checkPhase = ''
218219 runHook preCheck
219− ./Setup test ${testTarget}
220+ ${setupCommand} test ${testTarget}
220221 runHook postCheck
221222 '';
222223
223224 haddockPhase = ''
224225 runHook preHaddock
225226 ${optionalString (doHaddock && hasActiveLibrary) ''
226− ./Setup haddock --html \
227+ ${setupCommand} haddock --html \
227228 ${optionalString doHoogle "--hoogle"} \
228229 ${optionalString (hasActiveLibrary && hyperlinkSource) "--hyperlink-source"}
229230 ''}
@@ -233,12 +234,12 @@ stdenv.mkDerivation ({
233234 installPhase = ''
234235 runHook preInstall
235236
236− ${if !hasActiveLibrary then "./Setup install" else ''
237− ./Setup copy
237+ ${if !hasActiveLibrary then "${setupCommand} install" else ''
238+ ${setupCommand} copy
238239 local packageConfDir="$out/lib/${ghc.name}/package.conf.d"
239240 local packageConfFile="$packageConfDir/${pname}-${version}.conf"
240241 mkdir -p "$packageConfDir"
241− ./Setup register --gen-pkg-config=$packageConfFile
242+ ${setupCommand} register --gen-pkg-config=$packageConfFile
242243 local pkgId=$( ${gnused}/bin/sed -n -e 's|^id: ||p' $packageConfFile )
243244 mv $packageConfFile $packageConfDir/$pkgId.conf
244245 ''}
@@ -264,10 +265,10 @@ stdenv.mkDerivation ({
264265 LANG = "en_US.UTF-8";
265266 LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive";
266267 shellHook = ''
267− export NIX_GHC="${ghcEnv}/bin/${ghcCommand}"
268− export NIX_GHCPKG="${ghcEnv}/bin/${ghcCommand}-pkg"
269− export NIX_GHC_DOCDIR="${ghcEnv}/share/doc/ghc/html"
270− export NIX_GHC_LIBDIR="${ghcEnv}/lib/${ghcEnv.name}"
268+ export NIX_${ghcCommandCaps}="${ghcEnv}/bin/${ghcCommand}"
269+ export NIX_${ghcCommandCaps}PKG="${ghcEnv}/bin/${ghcCommand}-pkg"
270+ export NIX_${ghcCommandCaps}_DOCDIR="${ghcEnv}/share/doc/ghc/html"
271+ export NIX_${ghcCommandCaps}_LIBDIR="${ghcEnv}/lib/${ghcEnv.name}"
271272 '';
272273 };
273274
pkgs/development/haskell-modules/ghc-paths-nix-ghcjs.patchnew file+65
@@ -0,0 +1,65 @@
1+diff --git a/GHC/Paths.hs b/GHC/Paths.hs
2+index c87565d..88b3db4 100644
3+--- a/GHC/Paths.hs
4++++ b/GHC/Paths.hs
5+@@ -1,13 +1,35 @@
6+ {-# LANGUAGE CPP #-}
7++{-# LANGUAGE ScopedTypeVariables #-}
8+
9+ module GHC.Paths (
10+ ghc, ghc_pkg, libdir, docdir
11+ ) where
12+
13++import Control.Exception as E
14++import Data.Maybe
15++import System.Environment
16++import System.IO.Unsafe
17++
18++-- Yes, there's lookupEnv now, but we want to be compatible
19++-- with older GHCs.
20++checkEnv :: String -> IO (Maybe String)
21++checkEnv var = E.catch (fmap Just (getEnv var))
22++ (\ (e :: IOException) -> return Nothing)
23++
24++nixLibdir, nixDocdir, nixGhc, nixGhcPkg :: Maybe FilePath
25++nixLibdir = unsafePerformIO (checkEnv "NIX_GHCJS_LIBDIR")
26++nixDocdir = unsafePerformIO (checkEnv "NIX_GHCJS_DOCDIR")
27++nixGhc = unsafePerformIO (checkEnv "NIX_GHCJS")
28++nixGhcPkg = unsafePerformIO (checkEnv "NIX_GHCJSPKG")
29++{-# NOINLINE nixLibdir #-}
30++{-# NOINLINE nixDocdir #-}
31++{-# NOINLINE nixGhc #-}
32++{-# NOINLINE nixGhcPkg #-}
33++
34+ libdir, docdir, ghc, ghc_pkg :: FilePath
35+
36+-libdir = GHC_PATHS_LIBDIR
37+-docdir = GHC_PATHS_DOCDIR
38++libdir = fromMaybe GHC_PATHS_LIBDIR nixLibdir
39++docdir = fromMaybe GHC_PATHS_DOCDIR nixDocdir
40+
41+-ghc = GHC_PATHS_GHC
42+-ghc_pkg = GHC_PATHS_GHC_PKG
43++ghc = fromMaybe GHC_PATHS_GHC nixGhc
44++ghc_pkg = fromMaybe GHC_PATHS_GHC_PKG nixGhcPkg
45+diff --git a/Setup.hs b/Setup.hs
46+index fad5026..1651650 100644
47+--- a/Setup.hs
48++++ b/Setup.hs
49+@@ -27,13 +27,13 @@ main = defaultMainWithHooks simpleUserHooks {
50+ defaultPostConf :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
51+ defaultPostConf args flags pkgdescr lbi = do
52+ libdir_ <- rawSystemProgramStdoutConf (fromFlag (configVerbosity flags))
53+- ghcProgram (withPrograms lbi) ["--print-libdir"]
54++ ghcjsProgram (withPrograms lbi) ["--print-libdir"]
55+ let libdir = reverse $ dropWhile isSpace $ reverse libdir_
56+
57+- ghc_pkg = case lookupProgram ghcPkgProgram (withPrograms lbi) of
58++ ghc_pkg = case lookupProgram ghcjsPkgProgram (withPrograms lbi) of
59+ Just p -> programPath p
60+ Nothing -> error "ghc-pkg was not found"
61+- ghc = case lookupProgram ghcProgram (withPrograms lbi) of
62++ ghc = case lookupProgram ghcjsProgram (withPrograms lbi) of
63+ Just p -> programPath p
64+ Nothing -> error "ghc was not found"
65+
pkgs/development/haskell-modules/with-packages-wrapper.nix+25−22
@@ -32,6 +32,7 @@ let
3232 ghc761OrLater = isGhcjs || lib.versionOlder "7.6.1" ghc.version;
3333 packageDBFlag = if ghc761OrLater then "--global-package-db" else "--global-conf";
3434 ghcCommand = if isGhcjs then "ghcjs" else "ghc";
35+ ghcCommandCaps= lib.toUpper ghcCommand;
3536 libDir = "$out/lib/${ghcCommand}-${ghc.version}";
3637 docDir = "$out/share/doc/ghc/html";
3738 packageCfgDir = "${libDir}/package.conf.d";
@@ -51,10 +52,6 @@ buildEnv {
5152 postBuild = ''
5253 . ${makeWrapper}/nix-support/setup-hook
5354
54− ${lib.optionalString isGhcjs ''
55− cp -r "${ghc}/${ghc.libDir}/"* ${libDir}/
56− ''}
57−
5855 if test -L "$out/bin"; then
5956 binTarget="$(readlink -f "$out/bin")"
6057 rm "$out/bin"
@@ -62,30 +59,36 @@ buildEnv {
6259 chmod u+w "$out/bin"
6360 fi
6461
65− for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
66− rm -f $out/bin/$prg
67− makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
68− --add-flags '"-B$NIX_GHC_LIBDIR"' \
69− --set "NIX_GHC" "$out/bin/${ghcCommand}" \
70− --set "NIX_GHCPKG" "$out/bin/${ghcCommand}-pkg" \
71− --set "NIX_GHC_DOCDIR" "${docDir}" \
72− --set "NIX_GHC_LIBDIR" "${libDir}" \
73− ${lib.optionalString withLLVM ''--prefix "PATH" ":" "${llvm}"''}
62+ for prg in ${ghcCommand} ${ghcCommand}i ${ghcCommand}-${ghc.version} ${ghcCommand}i-${ghc.version}; do
63+ if [[ -x "${ghc}/bin/$prg" ]]; then
64+ rm -f $out/bin/$prg
65+ makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
66+ --add-flags '"-B$NIX_${ghcCommandCaps}_LIBDIR"' \
67+ --set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \
68+ --set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \
69+ --set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
70+ --set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}" \
71+ ${lib.optionalString withLLVM ''--prefix "PATH" ":" "${llvm}"''}
72+ fi
7473 done
7574
7675 for prg in runghc runhaskell; do
77− rm -f $out/bin/$prg
78− makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
79− --add-flags "-f $out/bin/ghc" \
80− --set "NIX_GHC" "$out/bin/${ghcCommand}" \
81− --set "NIX_GHCPKG" "$out/bin/${ghcCommand}-pkg" \
82− --set "NIX_GHC_DOCDIR" "${docDir}" \
83− --set "NIX_GHC_LIBDIR" "${libDir}"
76+ if [[ -x "${ghc}/bin/$prg" ]]; then
77+ rm -f $out/bin/$prg
78+ makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
79+ --add-flags "-f $out/bin/${ghcCommand}" \
80+ --set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \
81+ --set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \
82+ --set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
83+ --set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
84+ fi
8485 done
8586
8687 for prg in ${ghcCommand}-pkg ${ghcCommand}-pkg-${ghc.version}; do
87− rm -f $out/bin/$prg
88− makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "${packageDBFlag}=${packageCfgDir}"
88+ if [[ -x "${ghc}/bin/$prg" ]]; then
89+ rm -f $out/bin/$prg
90+ makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "${packageDBFlag}=${packageCfgDir}"
91+ fi
8992 done
9093
9194 ${lib.optionalString hasLibraries "$out/bin/${ghcCommand}-pkg recache"}