mirror of
https://github.com/ilyakooo0/haskell.nix.git
synced 2024-09-11 06:55:40 +03:00
Adds sublib support (#63)
This commit is contained in:
parent
de64d0c510
commit
8ffa7cd939
@ -46,7 +46,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;
|
||||
@ -105,7 +105,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 ''
|
||||
@ -299,13 +299,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.
|
||||
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}
|
||||
|
@ -31,7 +31,7 @@ with haskellLib;
|
||||
|
||||
componentPrefix = {
|
||||
# Are all of these right?
|
||||
sublibs = "sublib";
|
||||
sublibs = "lib";
|
||||
foreignlibs = "foreignlib";
|
||||
exes = "exe";
|
||||
tests = "test";
|
||||
|
@ -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
test/cabal-sublib/Main.hs
Normal file
4
test/cabal-sublib/Main.hs
Normal file
@ -0,0 +1,4 @@
|
||||
module Main where
|
||||
|
||||
main :: IO ()
|
||||
main = putStrLn "Hello, Haskell!"
|
2
test/cabal-sublib/Setup.hs
Normal file
2
test/cabal-sublib/Setup.hs
Normal file
@ -0,0 +1,2 @@
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
41
test/cabal-sublib/cabal-sublib.cabal
Normal file
41
test/cabal-sublib/cabal-sublib.cabal
Normal file
@ -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: moritz.angermann@iohk.io
|
||||
-- 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
test/cabal-sublib/cabal-sublib.nix
Normal file
33
test/cabal-sublib/cabal-sublib.nix
Normal file
@ -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 = "moritz.angermann@iohk.io";
|
||||
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
test/cabal-sublib/default.nix
Normal file
67
test/cabal-sublib/default.nix
Normal file
@ -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
test/cabal-sublib/plan.nix
Normal file
111
test/cabal-sublib/plan.nix
Normal file
@ -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";
|
||||
};
|
||||
};
|
||||
}
|
@ -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; };
|
||||
|
Loading…
Reference in New Issue
Block a user