git.iko.soy/typeable/nixpkgs
on master help sign in
ghcjs: properly wrap binaries in environment

This also: 1 Builds Setup.hs with ghcjs, which (among other things) defines __GHCJS__ and ghcjs_HOST_OS during pre-processing. 2 Fixes ghc-paths to point at ghcjs and use NIX_GHCJS_* env-vars. 3 Boots ghcjs into $prefix/lib/$compiler.

commit929dc4199a57b5d21eb72077f735eb33c4c7b09b authorCharles Strahan <charles.c.strahan@gmail.com> dateWed 6 May 2015, 15:56 (12 years ago) parent9cb6ebe
6 files changed+125−46
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+9−9 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+9−9
@@ -114,7 +114,7 @@ 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";
119119
120120in
@@ -186,7 +186,7 @@ stdenv.mkDerivation ({
186186 done
187187
188188 echo setupCompileFlags: $setupCompileFlags
189− ${setupBuilder} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
189+ ${ghcCommand} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
190190
191191 runHook postCompileBuildDriver
192192 '';
@@ -197,7 +197,7 @@ stdenv.mkDerivation ({
197197 unset GHC_PACKAGE_PATH # Cabal complains if this variable is set during configure.
198198
199199 echo configureFlags: $configureFlags
200− ./Setup configure $configureFlags 2>&1 | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log"
200+ ${setupCommand} configure $configureFlags 2>&1 | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log"
201201 if ${gnugrep}/bin/egrep -q '^Warning:.*depends on multiple versions' "$NIX_BUILD_TOP/cabal-configure.log"; then
202202 echo >&2 "*** abort because of serious configure-time warning from Cabal"
203203 exit 1
@@ -210,20 +210,20 @@ stdenv.mkDerivation ({
210210
211211 buildPhase = ''
212212 runHook preBuild
213− ./Setup build ${buildTarget}
213+ ${setupCommand} build ${buildTarget}
214214 runHook postBuild
215215 '';
216216
217217 checkPhase = ''
218218 runHook preCheck
219− ./Setup test ${testTarget}
219+ ${setupCommand} test ${testTarget}
220220 runHook postCheck
221221 '';
222222
223223 haddockPhase = ''
224224 runHook preHaddock
225225 ${optionalString (doHaddock && hasActiveLibrary) ''
226− ./Setup haddock --html \
226+ ${setupCommand} haddock --html \
227227 ${optionalString doHoogle "--hoogle"} \
228228 ${optionalString (hasActiveLibrary && hyperlinkSource) "--hyperlink-source"}
229229 ''}
@@ -233,12 +233,12 @@ stdenv.mkDerivation ({
233233 installPhase = ''
234234 runHook preInstall
235235
236− ${if !hasActiveLibrary then "./Setup install" else ''
237− ./Setup copy
236+ ${if !hasActiveLibrary then "${setupCommand} install" else ''
237+ ${setupCommand} copy
238238 local packageConfDir="$out/lib/${ghc.name}/package.conf.d"
239239 local packageConfFile="$packageConfDir/${pname}-${version}.conf"
240240 mkdir -p "$packageConfDir"
241− ./Setup register --gen-pkg-config=$packageConfFile
241+ ${setupCommand} register --gen-pkg-config=$packageConfFile
242242 local pkgId=$( ${gnused}/bin/sed -n -e 's|^id: ||p' $packageConfFile )
243243 mv $packageConfFile $packageConfDir/$pkgId.conf
244244 ''}
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"}