Skip to content
Merged
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
7 changes: 6 additions & 1 deletion pkgs/development/haskell-modules/generic-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,12 @@ stdenv.mkDerivation ({
installPhase = ''
runHook preInstall

${if !isLibrary then "${setupCommand} install" else ''
${if !isLibrary && buildTarget == "" then "${setupCommand} install"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdepillabout This line is what should preserve existing packages without rebuilds.

# ^^ 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
local packageConfDir="$out/lib/${ghc.name}/package.conf.d"
local packageConfFile="$packageConfDir/${pname}-${version}.conf"
Expand Down
10 changes: 10 additions & 0 deletions pkgs/development/haskell-modules/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ rec {
appendPatch = drv: x: appendPatches drv [x];
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; });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing buildTarget with a list parameter called buildTargets would be nice, but I'm not sure to what extent buildTarget may be considered public API?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, that is a good idea. Although I'd argue that it shouldn't block this PR getting merged in as it currently as.

As for whether it would be considered a public API, I'm not sure. I've wondered about that as well. We have the functions in pkgs/development/haskell-modules/lib.nix that allow us to set the arguments in generic-builder.nix, but we don't have a function in pkgs/development/haskell-modules/lib.nix for every argument in generic-builder.nix, so sometimes you have to set them directly. It is also more convenient to set the arguments directly sometimes rather than going through the functions in pkgs/development/haskell-modules/lib.nix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this hasn't been working properly until now, we probably can change stuff about it without to much problems, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you're saying. Since buildTarget hasn't actually been working correctly, then we don't really need to consider it part of the public API.

I think that makes sense, and it sounds like it makes sense to make that change.

Although I don't think it should necessarily stop this PR from being merged in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been working correctly for libraries

setBuildTarget = drv: x: setBuildTargets drv [x];

doHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = true; });
dontHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = false; });

Expand Down
1 change: 1 addition & 0 deletions pkgs/test/haskell/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
lib.recurseIntoAttrs {
shellFor = callPackage ./shellFor { };
documentationTarball = callPackage ./documentationTarball { };
setBuildTarget = callPackage ./setBuildTarget { };
}
4 changes: 4 additions & 0 deletions pkgs/test/haskell/setBuildTarget/Bar.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "Hello, Bar!"
4 changes: 4 additions & 0 deletions pkgs/test/haskell/setBuildTarget/Foo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "Hello, Foo!"
2 changes: 2 additions & 0 deletions pkgs/test/haskell/setBuildTarget/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
38 changes: 38 additions & 0 deletions pkgs/test/haskell/setBuildTarget/default.nix
Original file line number Diff line number Diff line change
@@ -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"
''

16 changes: 16 additions & 0 deletions pkgs/test/haskell/setBuildTarget/haskell-setBuildTarget.cabal
Original file line number Diff line number Diff line change
@@ -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