Add haskell.lib.setBuiltTarget, and support non library compiling of a single target

This commit is contained in:
Isaac Shapira
2021-04-23 13:55:38 -06:00
committed by (cdep)illabout
parent 111151c4bc
commit d725ac7942
8 changed files with 69 additions and 1 deletions

View File

@@ -3,4 +3,5 @@
lib.recurseIntoAttrs {
shellFor = callPackage ./shellFor { };
documentationTarball = callPackage ./documentationTarball { };
setBuildTarget = callPackage ./setBuildTarget { };
}

View File

@@ -0,0 +1,4 @@
module Main where
main :: IO ()
main = putStrLn "Hello, Bar!"

View File

@@ -0,0 +1,4 @@
module Main where
main :: IO ()
main = putStrLn "Hello, Foo!"

View File

@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

View File

@@ -0,0 +1,26 @@
{ pkgs, haskellPackages }: with pkgs.haskell.lib;
let
drv = haskellPackages.callCabal2nix "haskell-setBuildTarget" ./. {};
test = target: excluded:
let only = 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"
''

View File

@@ -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