summary refs log tree commit diff
path: root/pkgs/test/stdenv-inputs/default.nix
blob: d1eb8b9bfe2499f9fc5fd97af7e616094be4b09d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{ stdenv }:

let
  shlib = if stdenv.isDarwin then "dylib" else "so";

  foo = stdenv.mkDerivation {
    name = "foo-test";

    unpackPhase = ":";

    installPhase = ''
      mkdir -p $out/bin $out/include $out/lib
      $CC -o $out/bin/foo ${./cc-main.c}
      chmod +x $out/bin/foo
      cp ${./foo.c} $out/include/foo.h
      $CC -shared ${stdenv.lib.optionalString stdenv.isDarwin "-Wl,-install_name,$out/lib/libfoo.dylib"} -o $out/lib/libfoo.${shlib} ${./foo.c}
    '';
  };

  bar = stdenv.mkDerivation {
    name = "bar-test";
    outputs = [ "out" "dev" ];

    unpackPhase = ":";

    installPhase = ''
      mkdir -p $out/bin $dev/include $dev/lib
      $CC -o $out/bin/bar ${./cc-main.c}
      chmod +x $out/bin/bar
      cp ${./bar.c} $dev/include/bar.h
      $CC -shared ${stdenv.lib.optionalString stdenv.isDarwin "-Wl,-install_name,$dev/lib/libbar.dylib"} -o $dev/lib/libbar.${shlib} ${./bar.c}
    '';
  };
in

stdenv.mkDerivation {
  name = "stdenv-inputs-test";
  phases = [ "buildPhase" ];

  buildInputs = [ foo bar ];

  buildPhase = ''
    env

    printf "checking whether binaries are available... " >&2
    foo && bar

    printf "checking whether compiler can find headers... " >&2
    $CC -o include-check ${./include-main.c}
    ./include-check

    printf "checking whether compiler can find headers... " >&2
    $CC -o include-check ${./include-main.c}
    ./include-check

    printf "checking whether compiler can find libraries... " >&2
    $CC -lfoo -lbar -o lib-check ${./lib-main.c}
    ./lib-check

    touch $out
  '';

  meta.platforms = stdenv.lib.platforms.all;
}