Merge pull request #120249 from Fresheyeball/haskell-target
add build target support
This commit is contained in:
commit
c2f9d2ca53
8 changed files with 81 additions and 1 deletions
|
@ -464,7 +464,12 @@ stdenv.mkDerivation ({
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
|
|
||||||
${if !isLibrary then "${setupCommand} install" else ''
|
${if !isLibrary && buildTarget == "" then "${setupCommand} install"
|
||||||
|
# ^^ if the project is not a library, and no build target is specified, we can just use "install".
|
||||||
|
else if !isLibrary then "${setupCommand} copy ${buildTarget}"
|
||||||
|
# ^^ if the project is not a library, and we have a build target, then use "copy" to install
|
||||||
|
# just the target specified; "install" will error here, since not all targets have been built.
|
||||||
|
else ''
|
||||||
${setupCommand} copy
|
${setupCommand} copy
|
||||||
local packageConfDir="$out/lib/${ghc.name}/package.conf.d"
|
local packageConfDir="$out/lib/${ghc.name}/package.conf.d"
|
||||||
local packageConfFile="$packageConfDir/${pname}-${version}.conf"
|
local packageConfFile="$packageConfDir/${pname}-${version}.conf"
|
||||||
|
|
|
@ -196,6 +196,16 @@ rec {
|
||||||
appendPatch = drv: x: appendPatches drv [x];
|
appendPatch = drv: x: appendPatches drv [x];
|
||||||
appendPatches = drv: xs: overrideCabal drv (drv: { patches = (drv.patches or []) ++ xs; });
|
appendPatches = drv: xs: overrideCabal drv (drv: { patches = (drv.patches or []) ++ xs; });
|
||||||
|
|
||||||
|
/* Set a specific build target instead of compiling all targets in the package.
|
||||||
|
* For example, imagine we have a .cabal file with a library, and 2 executables "dev" and "server".
|
||||||
|
* We can build only "server" and not wait on the compilation of "dev" by using setBuildTarget as follows:
|
||||||
|
*
|
||||||
|
* setBuildTarget (callCabal2nix "thePackageName" thePackageSrc {}) "server"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
setBuildTargets = drv: xs: overrideCabal drv (drv: { buildTarget = lib.concatStringsSep " " xs; });
|
||||||
|
setBuildTarget = drv: x: setBuildTargets drv [x];
|
||||||
|
|
||||||
doHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = true; });
|
doHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = true; });
|
||||||
dontHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = false; });
|
dontHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = false; });
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,5 @@
|
||||||
lib.recurseIntoAttrs {
|
lib.recurseIntoAttrs {
|
||||||
shellFor = callPackage ./shellFor { };
|
shellFor = callPackage ./shellFor { };
|
||||||
documentationTarball = callPackage ./documentationTarball { };
|
documentationTarball = callPackage ./documentationTarball { };
|
||||||
|
setBuildTarget = callPackage ./setBuildTarget { };
|
||||||
}
|
}
|
||||||
|
|
4
pkgs/test/haskell/setBuildTarget/Bar.hs
Normal file
4
pkgs/test/haskell/setBuildTarget/Bar.hs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = putStrLn "Hello, Bar!"
|
4
pkgs/test/haskell/setBuildTarget/Foo.hs
Normal file
4
pkgs/test/haskell/setBuildTarget/Foo.hs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = putStrLn "Hello, Foo!"
|
2
pkgs/test/haskell/setBuildTarget/Setup.hs
Normal file
2
pkgs/test/haskell/setBuildTarget/Setup.hs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import Distribution.Simple
|
||||||
|
main = defaultMain
|
38
pkgs/test/haskell/setBuildTarget/default.nix
Normal file
38
pkgs/test/haskell/setBuildTarget/default.nix
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
{ pkgs, haskellPackages }:
|
||||||
|
|
||||||
|
let
|
||||||
|
# This can be regenerated by running `cabal2nix .` in the current directory.
|
||||||
|
pkgDef =
|
||||||
|
{ mkDerivation, base, lib }:
|
||||||
|
mkDerivation {
|
||||||
|
pname = "haskell-setBuildTarget";
|
||||||
|
version = "0.1.0.0";
|
||||||
|
src = ./.;
|
||||||
|
isLibrary = false;
|
||||||
|
isExecutable = true;
|
||||||
|
executableHaskellDepends = [ base ];
|
||||||
|
license = lib.licenses.bsd3;
|
||||||
|
};
|
||||||
|
|
||||||
|
drv = haskellPackages.callPackage pkgDef {};
|
||||||
|
|
||||||
|
test = target: excluded:
|
||||||
|
let only = pkgs.haskell.lib.setBuildTarget drv target;
|
||||||
|
in ''
|
||||||
|
if [[ ! -f "${only}/bin/${target}" ]]; then
|
||||||
|
echo "${target} was not built"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f "${only}/bin/${excluded}" ]]; then
|
||||||
|
echo "${excluded} was built, when it should not have been"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
|
||||||
|
in pkgs.runCommand "test haskell.lib.setBuildTarget" {} ''
|
||||||
|
${test "foo" "bar"}
|
||||||
|
${test "bar" "foo"}
|
||||||
|
touch "$out"
|
||||||
|
''
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
cabal-version: >=1.10
|
||||||
|
name: haskell-setBuildTarget
|
||||||
|
version: 0.1.0.0
|
||||||
|
author: Isaac Shapira
|
||||||
|
maintainer: fresheyeball@protonmail.com
|
||||||
|
build-type: Simple
|
||||||
|
|
||||||
|
executable foo
|
||||||
|
main-is: Foo.hs
|
||||||
|
build-depends: base
|
||||||
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
executable bar
|
||||||
|
main-is: Bar.hs
|
||||||
|
build-depends: base
|
||||||
|
default-language: Haskell2010
|
Loading…
Reference in a new issue