haskell.nix/test/cabal-22/default.nix
Hamish Mackenzie a443611ecf
Add evalSystem and evalPackages project args (#1546)
This adds a way to specify the `evalSystem` or `evalPackages` explicitly when calling the `project` functions.

Currently if we want to make a `flake` that supports multiple systems we have few options:

* Require builders for all the supported systems (even just for `nix flake show`).

* Pass `--impure` so that haskell.nix can see `builtins.currentSystem` to set up `pkgs.evalPackages` to use that.  Unfortunately this prevents nix from caching some of the work it does and often results in it recalculating for each supported system when it would otherwise be cached and take no time at all.

* Add an overlay to replace `evalPackages`.  This works, but it is not straight forward.

* Materialize the nix files for the project.

This change allows `evalSystem = "x86_64-linux";` to be passed telling `haskell.nix` to run `cabal` and `nix-tools` on that system.  The user will have to have a builder for that system, but does not need to have builders for the others (unless building outputs for them).
2022-07-28 20:03:05 +12:00

76 lines
2.8 KiB
Nix

{ stdenv, lib, mkCabalProjectPkgSet, cabalProject', haskellLib, util, recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages }:
with lib;
let
project = cabalProject' {
inherit compiler-nix-name evalPackages;
src = testSrc "cabal-22";
};
packages = project.hsPkgs;
in recurseIntoAttrs {
# When using ghcjs on darwin this test fails with
# ReferenceError: h$hs_clock_darwin_gettime is not defined
# https://github.com/input-output-hk/haskell.nix/issues/925
# Also `hspec` now depends on `ghc`, which breaks this test for cross compilation
meta.disabled = stdenv.hostPlatform.isGhcjs || stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isMusl;
ifdInputs = {
inherit (project) plan-nix;
};
shell = util.addCabalInstall packages.project.components.library;
run = stdenv.mkDerivation {
name = "cabal-22-test";
buildCommand = ''
exe="${packages.project.components.exes.project.exePath}"
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
cat ${haskellLib.check packages.project.components.exes.project}/test-stdout
'' +
# Aarch is statically linked and does not produce a .so file.
# Musl is also statically linked, but it does make a .so file so we should check that still.
optionalString (!stdenv.hostPlatform.isAarch32 && !stdenv.hostPlatform.isAarch64) (''
printf "checking that executable is dynamically linked to system libraries... " >& 2
'' + optionalString (stdenv.isLinux && !stdenv.hostPlatform.isMusl) ''
ldd $exe | grep libgmp
'' + optionalString stdenv.isDarwin ''
otool -L $exe | grep "libSystem.B"
'' + ''
# fixme: posix-specific
printf "checking that dynamic library is produced... " >& 2
'' + optionalString stdenv.isLinux ''
sofile=$(find "${packages.project.components.library}" | grep -e '\.so$')
'' + optionalString stdenv.isDarwin ''
sofile=$(find "${packages.project.components.library}" | grep -e '\.dylib$')
'' + ''
echo "$sofile"
'' + optionalString (!stdenv.hostPlatform.isMusl) (''
printf "checking that dynamic library is dynamically linked to prim... " >& 2
'' + optionalString stdenv.isLinux ''
ldd $sofile | grep libHSghc-prim
'' + optionalString stdenv.isDarwin ''
otool -L $sofile | grep libHSghc-prim
'')) + ''
touch $out
printf "checking whether benchmark ran... " >& 2
cat ${haskellLib.check packages.project.components.benchmarks.project-bench}/test-stdout
printf "checking whether tests ran... " >& 2
cat ${haskellLib.check packages.project.components.tests.unit}/test-stdout
'';
meta.platforms = platforms.all;
passthru = {
inherit project;
};
};
}