about summary refs log tree commit diff
path: root/pkgs/test
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/test')
-rw-r--r--pkgs/test/cc-wrapper/default.nix26
-rw-r--r--pkgs/test/default.nix95
2 files changed, 93 insertions, 28 deletions
diff --git a/pkgs/test/cc-wrapper/default.nix b/pkgs/test/cc-wrapper/default.nix
index 43e8e7a21426..8809030989e6 100644
--- a/pkgs/test/cc-wrapper/default.nix
+++ b/pkgs/test/cc-wrapper/default.nix
@@ -9,25 +9,29 @@ let
   );
   staticLibc = lib.optionalString (stdenv.hostPlatform.libc == "glibc") "-L ${glibc.static}/lib";
   emulator = stdenv.hostPlatform.emulator buildPackages;
+  libcxxStdenvSuffix = lib.optionalString (stdenv.cc.libcxx != null) "-libcxx";
 in stdenv.mkDerivation {
-  name = "cc-wrapper-test";
+  pname = "cc-wrapper-test-${stdenv.cc.cc.pname}${libcxxStdenvSuffix}";
+  version = stdenv.cc.version;
 
   buildCommand = ''
+    echo "Testing: ${stdenv.cc.name}" >&2
+    echo "With libc: ${stdenv.cc.libc.name}" >&2
     set -o pipefail
 
     NIX_DEBUG=1 $CC -v
     NIX_DEBUG=1 $CXX -v
 
-    printf "checking whether compiler builds valid C binaries... " >&2
+    echo "checking whether compiler builds valid C binaries... " >&2
     $CC -o cc-check ${./cc-main.c}
     ${emulator} ./cc-check
 
-    printf "checking whether compiler builds valid C++ binaries... " >&2
+    echo "checking whether compiler builds valid C++ binaries... " >&2
     $CXX -o cxx-check ${./cxx-main.cc}
     ${emulator} ./cxx-check
 
     ${lib.optionalString (stdenv.isDarwin && stdenv.cc.isClang) ''
-      printf "checking whether compiler can build with CoreFoundation.framework... " >&2
+      echo "checking whether compiler can build with CoreFoundation.framework... " >&2
       mkdir -p foo/lib
       $CC -framework CoreFoundation -o core-foundation-check ${./core-foundation-main.c}
       ${emulator} ./core-foundation-check
@@ -35,11 +39,11 @@ in stdenv.mkDerivation {
 
 
     ${lib.optionalString (!stdenv.isDarwin) ''
-      printf "checking whether compiler builds valid static C binaries... " >&2
+      echo "checking whether compiler builds valid static C binaries... " >&2
       $CC ${staticLibc} -static -o cc-static ${./cc-main.c}
       ${emulator} ./cc-static
       ${lib.optionalString (stdenv.cc.isGNU && lib.versionAtLeast (lib.getVersion stdenv.cc.name) "8.0.0") ''
-        printf "checking whether compiler builds valid static pie C binaries... " >&2
+        echo "checking whether compiler builds valid static pie C binaries... " >&2
         $CC ${staticLibc} -static-pie -o cc-static-pie ${./cc-main.c}
         ${emulator} ./cc-static-pie
       ''}
@@ -48,7 +52,7 @@ in stdenv.mkDerivation {
     ${# See: https://github.com/llvm/llvm-project/commit/ed1d07282cc9d8e4c25d585e03e5c8a1b6f63a74
       # `gcc` does not support this so we gate the test on `clang`
       lib.optionalString stdenv.cc.isClang ''
-        printf "checking whether cc-wrapper accepts -- followed by positional (file) args..." >&2
+        echo "checking whether cc-wrapper accepts -- followed by positional (file) args..." >&2
         mkdir -p positional
 
         # Make sure `--` is not parsed as a "non flag arg"; we should get an
@@ -66,13 +70,13 @@ in stdenv.mkDerivation {
         ${emulator} ./positional/main
     ''}
 
-    printf "checking whether compiler uses NIX_CFLAGS_COMPILE... " >&2
+    echo "checking whether compiler uses NIX_CFLAGS_COMPILE... " >&2
     mkdir -p foo/include
     cp ${./foo.c} foo/include/foo.h
     NIX_CFLAGS_COMPILE="-Ifoo/include -DVALUE=42" $CC -o cflags-check ${./cflags-main.c}
     ${emulator} ./cflags-check
 
-    printf "checking whether compiler uses NIX_LDFLAGS... " >&2
+    echo "checking whether compiler uses NIX_LDFLAGS... " >&2
     mkdir -p foo/lib
     $CC -shared \
       ${lib.optionalString stdenv.isDarwin "-Wl,-install_name,@rpath/libfoo.dylib"} \
@@ -83,7 +87,7 @@ in stdenv.mkDerivation {
     NIX_LDFLAGS="-L$NIX_BUILD_TOP/foo/lib -rpath $NIX_BUILD_TOP/foo/lib" $CC -lfoo -o ldflags-check ${./ldflags-main.c}
     ${emulator} ./ldflags-check
 
-    printf "Check whether -nostdinc and -nostdinc++ is handled correctly" >&2
+    echo "Check whether -nostdinc and -nostdinc++ is handled correctly" >&2
     mkdir -p std-include
     cp ${./stdio.h} std-include/stdio.h
     NIX_DEBUG=1 $CC -I std-include -nostdinc -o nostdinc-main ${./nostdinc-main.c}
@@ -92,7 +96,7 @@ in stdenv.mkDerivation {
     ${emulator} ./nostdinc-main++
 
     ${lib.optionalString sanitizersWorking ''
-      printf "checking whether sanitizers are fully functional... ">&2
+      echo "checking whether sanitizers are fully functional... ">&2
       $CC -o sanitizers -fsanitize=address,undefined ${./sanitizers.c}
       ASAN_OPTIONS=use_sigaltstack=0 ${emulator} ./sanitizers
     ''}
diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix
index c479070c6078..b914ec26ae00 100644
--- a/pkgs/test/default.nix
+++ b/pkgs/test/default.nix
@@ -3,23 +3,84 @@
 with pkgs;
 
 {
-  cc-wrapper = callPackage ./cc-wrapper { };
-  cc-wrapper-gcc = callPackage ./cc-wrapper { stdenv = gccStdenv; };
-  cc-wrapper-gcc7 = callPackage ./cc-wrapper { stdenv = gcc7Stdenv; };
-  cc-wrapper-gcc8 = callPackage ./cc-wrapper { stdenv = gcc8Stdenv; };
-  cc-wrapper-gcc9 = callPackage ./cc-wrapper { stdenv = gcc9Stdenv; };
-  cc-wrapper-clang = callPackage ./cc-wrapper { stdenv = llvmPackages.stdenv; };
-  cc-wrapper-libcxx = callPackage ./cc-wrapper { stdenv = llvmPackages.libcxxStdenv; };
-  cc-wrapper-clang-5 = callPackage ./cc-wrapper { stdenv = llvmPackages_5.stdenv; };
-  cc-wrapper-libcxx-5 = callPackage ./cc-wrapper { stdenv = llvmPackages_5.libcxxStdenv; };
-  cc-wrapper-clang-6 = callPackage ./cc-wrapper { stdenv = llvmPackages_6.stdenv; };
-  cc-wrapper-libcxx-6 = callPackage ./cc-wrapper { stdenv = llvmPackages_6.libcxxStdenv; };
-  cc-wrapper-clang-7 = callPackage ./cc-wrapper { stdenv = llvmPackages_7.stdenv; };
-  cc-wrapper-libcxx-7 = callPackage ./cc-wrapper { stdenv = llvmPackages_7.libcxxStdenv; };
-  cc-wrapper-clang-8 = callPackage ./cc-wrapper { stdenv = llvmPackages_8.stdenv; };
-  cc-wrapper-libcxx-8 = callPackage ./cc-wrapper { stdenv = llvmPackages_8.libcxxStdenv; };
-  cc-wrapper-clang-9 = callPackage ./cc-wrapper { stdenv = llvmPackages_9.stdenv; };
-  cc-wrapper-libcxx-9 = callPackage ./cc-wrapper { stdenv = llvmPackages_9.libcxxStdenv; };
+  cc-wrapper = with builtins; let
+    pkgNames = (attrNames pkgs);
+    llvmTests = let
+      pkgSets = lib.pipe pkgNames [
+        (filter (lib.hasPrefix "llvmPackages"))
+        (filter (n: n != "llvmPackages_rocm"))
+        (filter (n: n != "llvmPackages_latest"))
+        (filter (n: n != "llvmPackages_git"))
+      ];
+      tests = lib.genAttrs pkgSets (name: recurseIntoAttrs {
+        clang = callPackage ./cc-wrapper { stdenv = pkgs.${name}.stdenv; };
+        libcxx = callPackage ./cc-wrapper { stdenv = pkgs.${name}.libcxxStdenv; };
+      });
+    in
+      tests;
+    gccTests = let
+      pkgSets = lib.pipe (attrNames pkgs) ([
+        (filter (lib.hasPrefix "gcc"))
+        (filter (lib.hasSuffix "Stdenv"))
+        (filter (n: n != "gccCrossLibcStdenv"))
+      ] ++ lib.optionals (!(
+        (stdenv.buildPlatform.isLinux && stdenv.buildPlatform.isx86_64) &&
+        (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86_64)
+      )) [
+        (filter (n: !lib.hasSuffix "MultiStdenv" n))
+      ]);
+    in lib.genAttrs pkgSets (name: callPackage ./cc-wrapper { stdenv = pkgs.${name}; });
+  in recurseIntoAttrs {
+    default = callPackage ./cc-wrapper { };
+
+    supported = stdenv.mkDerivation {
+      name = "cc-wrapper-supported";
+      builtGCC =
+        let
+          names = lib.pipe (attrNames gccTests) ([
+            (filter (n: lib.meta.availableOn stdenv.hostPlatform pkgs.${n}.cc))
+            # Broken
+            (filter (n: n != "gcc49Stdenv"))
+            (filter (n: n != "gccMultiStdenv"))
+          ] ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
+            # fails with things like
+            # ld: warning: ld: warning: object file (trunctfsf2_s.o) was built for newer macOS version (11.0) than being linked (10.5)
+            # ld: warning: ld: warning: could not create compact unwind for ___fixunstfdi: register 20 saved somewhere other than in frame
+            (filter (n: n != "gcc11Stdenv"))
+          ]);
+        in
+        toJSON (lib.genAttrs names (name: { name = pkgs.${name};  }));
+
+      builtLLVM =
+        let
+          names = lib.pipe (attrNames llvmTests) ([
+            (filter (n: lib.meta.availableOn stdenv.hostPlatform pkgs.${n}.stdenv.cc))
+            (filter (n: lib.meta.availableOn stdenv.hostPlatform pkgs.${n}.libcxxStdenv.cc))
+
+            # libcxxStdenv broken
+            # fix in https://github.com/NixOS/nixpkgs/pull/216273
+          ] ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
+            # libcxx does not build for some reason on aarch64-linux
+            (filter (n: n != "llvmPackages_7"))
+          ] ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
+            (filter (n: n != "llvmPackages_5"))
+            (filter (n: n != "llvmPackages_6"))
+            (filter (n: n != "llvmPackages_7"))
+            (filter (n: n != "llvmPackages_8"))
+            (filter (n: n != "llvmPackages_9"))
+            (filter (n: n != "llvmPackages_10"))
+          ]);
+        in
+        toJSON (lib.genAttrs names (name: { stdenv = pkgs.${name}.stdenv; libcxx = pkgs.${name}.libcxxStdenv;  }));
+        buildCommand = ''
+          touch $out
+        '';
+    };
+
+    llvmTests = recurseIntoAttrs llvmTests;
+    inherit gccTests;
+  };
+
   stdenv-inputs = callPackage ./stdenv-inputs { };
   stdenv = callPackage ./stdenv { };