Skip to content

Adds sublib support #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 13, 2019
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
16 changes: 13 additions & 3 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let

flatDepends =
let
makePairs = map (p: rec { key="${val}"; val=p.components.library; });
makePairs = map (p: rec { key="${val}"; val=(p.components.library or p); });
closure = builtins.genericClosure {
startSet = makePairs component.depends;
operator = {val,...}: makePairs val.config.depends;
Expand Down Expand Up @@ -104,7 +104,7 @@ let
cat > $out/ghc-environment <<EOF
package-db $out/package.conf.d
EOF
${lib.concatMapStringsSep "\n" (p: envDep "--package-db ${p.components.library}/package.conf.d" p.identifier.name) component.depends}
${lib.concatMapStringsSep "\n" (p: envDep "--package-db ${p.components.library or p}/package.conf.d" p.identifier.name) component.depends}
${lib.concatMapStringsSep "\n" (envDep "") (lib.remove "ghc" nonReinstallablePkgs)}

'' + lib.optionalString component.doExactConfig ''
Expand Down Expand Up @@ -294,13 +294,23 @@ stdenv.mkDerivation ({
'';

# Note: Cabal does *not* copy test executables during the `install` phase.
#
# Note 2: if a package contains multiple libs (lib + sublibs) SETUP register will generate a
# folder isntead of a file for the configuration. Therfore if the result is a folder,
# we need to register each and every element of that folder.
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't there only be one package per derivation? Why would there be multiple?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the issue is the all target. If you run the following on a cabal file with a sublibrary:

$ runghc Setup.hs configure # without component target, as we do for `all`.
$ runghc Setup.hs register --gen-pkg-config=pkg.conf

you end up with a folder for pkg.conf that contains the package configuration file for the library as well as the sublibrary.

If you don't have sublibraries, pkg.conf is your package configuration file.

Copy link
Contributor

Choose a reason for hiding this comment

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

@angerman So this only comes up when a package depends on the all component? That shouldn't happen, should it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why should this not happen? Why wouldn't we build the all component? We do allow this right now (and the test case tried to do precisely that).

Thus, unless we want to remove the all component again, I'm afraid we'll need to keep this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@angerman The all component is, to my understanding, only for the sake of users who want a shell for all, plus the novel purpose of building all components in one derivation. The intention is that components will depend on components, not on any all derivation.

installPhase = ''
runHook preInstall
$SETUP_HS copy ${lib.concatStringsSep " " component.setupInstallFlags}
${lib.optionalString (haskellLib.isLibrary componentId || haskellLib.isAll componentId) ''
$SETUP_HS register --gen-pkg-config=${name}.conf
${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
if [ -d "${name}.conf" ]; then
for pkg in ${name}.conf/*; do
${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register "$pkg"
done
else
${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
fi
''}
${lib.optionalString (haskellLib.isTest componentId || haskellLib.isAll componentId) ''
mkdir -p $out/${name}
Expand Down
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ with haskellLib;

componentPrefix = {
# Are all of these right?
sublibs = "sublib";
sublibs = "lib";
foreignlibs = "foreignlib";
exes = "exe";
tests = "test";
Expand Down
5 changes: 3 additions & 2 deletions modules/plan.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ with types;

let m = if revision == null
then (abort "${name} has no revision!")
else revision modArgs;
in m // { flags = lib.mapAttrs (_: lib.mkDefault) (m.flags // revArgs.flags or {}); }
else revision (modArgs // { hsPkgs = hsPkgs // (mapAttrs (l: _: hsPkgs.${name}.components.sublibs.${l}) (m.components.sublibs or {})); });
in
m // { flags = lib.mapAttrs (_: lib.mkDefault) (m.flags // revArgs.flags or {}); }
) (lib.filterAttrs (n: v: v == null || v.revision != null ) module.packages);
};
}
4 changes: 4 additions & 0 deletions test/cabal-sublib/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "Hello, Haskell!"
2 changes: 2 additions & 0 deletions test/cabal-sublib/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
41 changes: 41 additions & 0 deletions test/cabal-sublib/cabal-sublib.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cabal-version: 2.2
-- Initial package description 'cabal-simple.cabal' generated by 'cabal
-- init'. For further documentation, see
-- http://haskell.org/cabal/users-guide/

name: cabal-sublib
version: 0.1.0.0
-- synopsis:
-- description:
-- bug-reports:
license: MIT
author: Moritz Angermann
maintainer: [email protected]
-- category:
build-type: Simple

library
-- exposed-modules:
-- other-modules:
-- other-extensions:
build-depends: base >=4.11 && <4.12
, slib
-- hs-source-dirs:
default-language: Haskell2010

library slib
build-depends: extra
, safe
, aeson
default-language: Haskell2010

executable cabal-sublib
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.11 && <4.12
, cabal-sublib
, extra
, optparse-applicative
-- hs-source-dirs:
default-language: Haskell2010
33 changes: 33 additions & 0 deletions test/cabal-sublib/cabal-sublib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{ system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }:
{
flags = {};
package = {
specVersion = "2.2";
identifier = { name = "cabal-sublib"; version = "0.1.0.0"; };
license = "MIT";
copyright = "";
maintainer = "[email protected]";
author = "Moritz Angermann";
homepage = "";
url = "";
synopsis = "";
description = "";
buildType = "Simple";
};
components = {
"library" = { depends = [ (hsPkgs.base) (hsPkgs.slib) ]; };
sublibs = {
"slib" = { depends = [ (hsPkgs.extra) (hsPkgs.safe) (hsPkgs.aeson) ]; };
};
exes = {
"cabal-sublib" = {
depends = [
(hsPkgs.base)
(hsPkgs.cabal-sublib)
(hsPkgs.extra)
(hsPkgs.optparse-applicative)
];
};
};
};
} // rec { src = (pkgs.lib).mkDefault ./.; }
67 changes: 67 additions & 0 deletions test/cabal-sublib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Test a package set
{ stdenv, util, mkPkgSet }:

with stdenv.lib;

let
## steps to generate local files
# 1. cabal-to-nix cabal-sublib.cabal > cabal-sublib.nix
# 2. cabal new-build
# 3. plan-to-nix ./dist-newstyle/cache/plan.json > plan.nix
pkgSet = mkPkgSet {
pkg-def = import ./plan.nix;
pkg-def-overlays = [
{ cabal-sublib = ./cabal-sublib.nix;
}
];
modules = [
{
# Package has no exposed modules which causes
# haddock: No input file(s)
packages.cabal-sublib.doHaddock = false;
}
];
};

packages = pkgSet.config.hsPkgs;

in
stdenv.mkDerivation {
name = "cabal-sublib-test";

buildCommand = ''
exe="${packages.cabal-sublib.components.exes.cabal-sublib}/bin/cabal-sublib"

size=$(command stat --format '%s' "$exe")
printf "size of executable $exe is $size. \n" >& 2

# fixme: run on target platform when cross-compiled
printf "checking whether executable runs... " >& 2
$exe

printf "checking that executable is dynamically linked to system libraries... " >& 2
'' + optionalString stdenv.isLinux ''
ldd $exe | grep libpthread
'' + optionalString stdenv.isDarwin ''
otool -L $exe |grep .dylib
'' + ''

printf "Checking that \"all\" component has the programs... " >& 2
all_exe="${packages.cabal-sublib.components.all}/bin/cabal-sublib"
test -f "$all_exe"
echo "$all_exe" >& 2

touch $out
'';

meta.platforms = platforms.all;

passthru = {
# Used for debugging with nix repl
inherit pkgSet packages;

# Used for testing externally with nix-shell (../tests.sh).
# This just adds cabal-install to the existing shells.
test-shell = util.addCabalInstall packages.cabal-sublib.components.all;
};
}
111 changes: 111 additions & 0 deletions test/cabal-sublib/plan.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
hackage:
{
packages = {
"binary".revision = hackage."binary"."0.8.5.1".revisions.default;
"ghc-prim".revision = hackage."ghc-prim"."0.5.2.0".revisions.default;
"extra".revision = hackage."extra"."1.6.14".revisions.default;
"stm".revision = hackage."stm"."2.4.5.1".revisions.default;
"unix".revision = hackage."unix"."2.7.2.2".revisions.default;
"rts".revision = hackage."rts"."1.0".revisions.default;
"clock".revision = hackage."clock"."0.7.2".revisions.default;
"clock".flags.llvm = false;
"scientific".revision = hackage."scientific"."0.3.6.2".revisions.default;
"scientific".flags.integer-simple = false;
"scientific".flags.bytestring-builder = false;
"deepseq".revision = hackage."deepseq"."1.4.3.0".revisions.default;
"random".revision = hackage."random"."1.1".revisions.default;
"uuid-types".revision = hackage."uuid-types"."1.0.3".revisions.default;
"optparse-applicative".revision = hackage."optparse-applicative"."0.14.3.0".revisions.default;
"dlist".revision = hackage."dlist"."0.8.0.5".revisions.default;
"directory".revision = hackage."directory"."1.3.1.5".revisions.default;
"transformers-compat".revision = hackage."transformers-compat"."0.6.2".revisions.default;
"transformers-compat".flags.five = false;
"transformers-compat".flags.generic-deriving = true;
"transformers-compat".flags.two = false;
"transformers-compat".flags.five-three = true;
"transformers-compat".flags.mtl = true;
"transformers-compat".flags.four = false;
"transformers-compat".flags.three = false;
"template-haskell".revision = hackage."template-haskell"."2.13.0.0".revisions.default;
"vector".revision = hackage."vector"."0.12.0.2".revisions.default;
"vector".flags.unsafechecks = false;
"vector".flags.internalchecks = false;
"vector".flags.wall = false;
"vector".flags.boundschecks = true;
"primitive".revision = hackage."primitive"."0.6.4.0".revisions.default;
"time-locale-compat".revision = hackage."time-locale-compat"."0.1.1.5".revisions.default;
"time-locale-compat".flags.old-locale = false;
"safe".revision = hackage."safe"."0.3.17".revisions.default;
"base-compat".revision = hackage."base-compat"."0.10.5".revisions.default;
"ansi-terminal".revision = hackage."ansi-terminal"."0.8.2".revisions.default;
"ansi-terminal".flags.example = false;
"tagged".revision = hackage."tagged"."0.8.6".revisions.default;
"tagged".flags.transformers = true;
"tagged".flags.deepseq = true;
"containers".revision = hackage."containers"."0.5.11.0".revisions.default;
"integer-logarithms".revision = hackage."integer-logarithms"."1.0.2.2".revisions.default;
"integer-logarithms".flags.check-bounds = false;
"integer-logarithms".flags.integer-gmp = true;
"bytestring".revision = hackage."bytestring"."0.10.8.2".revisions.default;
"ansi-wl-pprint".revision = hackage."ansi-wl-pprint"."0.6.8.2".revisions.default;
"ansi-wl-pprint".flags.example = false;
"StateVar".revision = hackage."StateVar"."1.1.1.1".revisions.default;
"contravariant".revision = hackage."contravariant"."1.5".revisions.default;
"contravariant".flags.semigroups = true;
"contravariant".flags.tagged = true;
"contravariant".flags.statevar = true;
"contravariant".flags.safe = false;
"text".revision = hackage."text"."1.2.3.1".revisions.default;
"unordered-containers".revision = hackage."unordered-containers"."0.2.9.0".revisions.default;
"unordered-containers".flags.debug = false;
"base".revision = hackage."base"."4.11.1.0".revisions.default;
"time".revision = hackage."time"."1.8.0.2".revisions.default;
"transformers".revision = hackage."transformers"."0.5.5.0".revisions.default;
"hashable".revision = hackage."hashable"."1.2.7.0".revisions.default;
"hashable".flags.sse2 = true;
"hashable".flags.integer-gmp = true;
"hashable".flags.sse41 = false;
"hashable".flags.examples = false;
"attoparsec".revision = hackage."attoparsec"."0.13.2.2".revisions.default;
"attoparsec".flags.developer = false;
"colour".revision = hackage."colour"."2.3.4".revisions.default;
"filepath".revision = hackage."filepath"."1.4.2".revisions.default;
"process".revision = hackage."process"."1.6.3.0".revisions.default;
"pretty".revision = hackage."pretty"."1.1.3.6".revisions.default;
"aeson".revision = hackage."aeson"."1.4.2.0".revisions.default;
"aeson".flags.cffi = false;
"aeson".flags.fast = false;
"aeson".flags.bytestring-builder = false;
"aeson".flags.developer = false;
"ghc-boot-th".revision = hackage."ghc-boot-th"."8.4.4".revisions.default;
"th-abstraction".revision = hackage."th-abstraction"."0.2.10.0".revisions.default;
"array".revision = hackage."array"."0.5.2.0".revisions.default;
"integer-gmp".revision = hackage."integer-gmp"."1.0.2.0".revisions.default;
};
compiler = {
version = "8.4.4";
nix-name = "ghc844";
packages = {
"binary" = "0.8.5.1";
"ghc-prim" = "0.5.2.0";
"stm" = "2.4.5.1";
"unix" = "2.7.2.2";
"rts" = "1.0";
"deepseq" = "1.4.3.0";
"directory" = "1.3.1.5";
"template-haskell" = "2.13.0.0";
"containers" = "0.5.11.0";
"bytestring" = "0.10.8.2";
"text" = "1.2.3.1";
"base" = "4.11.1.0";
"time" = "1.8.0.2";
"transformers" = "0.5.5.0";
"filepath" = "1.4.2";
"process" = "1.6.3.0";
"pretty" = "1.1.3.6";
"ghc-boot-th" = "8.4.4";
"array" = "0.5.2.0";
"integer-gmp" = "1.0.2.0";
};
};
}
1 change: 1 addition & 0 deletions test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let

in {
cabal-simple = callPackage ./cabal-simple { inherit (haskell) mkPkgSet; inherit util; };
cabal-sublib = callPackage ./cabal-sublib { inherit (haskell) mkPkgSet; inherit util; };
cabal-22 = callPackage ./cabal-22 { inherit (haskell) mkPkgSet; };
with-packages = callPackage ./with-packages { inherit (haskell) mkPkgSet; inherit util; };
builder-haddock = callPackage ./builder-haddock { inherit (haskell) mkPkgSet; };
Expand Down