summary refs log tree commit diff
path: root/pkgs/test/cc-wrapper/default.nix
diff options
context:
space:
mode:
authorNick Cao <nickcao@nichi.co>2022-02-09 18:45:57 +0800
committerRick van Schijndel <Mindavi@users.noreply.github.com>2022-12-25 09:19:28 +0100
commit57ff6191af7821cef3dddc12ca5a373ea015c7bf (patch)
tree69be26fb3d745c61ba8eee15b9fbb850c907facc /pkgs/test/cc-wrapper/default.nix
parent9a68333098e384531160396ae4a38c2d95ead700 (diff)
downloadnixpkgs-57ff6191af7821cef3dddc12ca5a373ea015c7bf.tar
nixpkgs-57ff6191af7821cef3dddc12ca5a373ea015c7bf.tar.gz
nixpkgs-57ff6191af7821cef3dddc12ca5a373ea015c7bf.tar.bz2
nixpkgs-57ff6191af7821cef3dddc12ca5a373ea015c7bf.tar.lz
nixpkgs-57ff6191af7821cef3dddc12ca5a373ea015c7bf.tar.xz
nixpkgs-57ff6191af7821cef3dddc12ca5a373ea015c7bf.tar.zst
nixpkgs-57ff6191af7821cef3dddc12ca5a373ea015c7bf.zip
cc-wrapper-test: support cross compilers
Diffstat (limited to 'pkgs/test/cc-wrapper/default.nix')
-rw-r--r--pkgs/test/cc-wrapper/default.nix23
1 files changed, 12 insertions, 11 deletions
diff --git a/pkgs/test/cc-wrapper/default.nix b/pkgs/test/cc-wrapper/default.nix
index b483372dea0..8a439f07b3a 100644
--- a/pkgs/test/cc-wrapper/default.nix
+++ b/pkgs/test/cc-wrapper/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv, glibc }:
+{ lib, stdenv, glibc, buildPackages }:
 
 let
   # Sanitizers are not supported on Darwin.
@@ -8,6 +8,7 @@ let
     || (stdenv.cc.isGNU && stdenv.isLinux)
   );
   staticLibc = lib.optionalString (stdenv.hostPlatform.libc == "glibc") "-L ${glibc.static}/lib";
+  emulator = stdenv.hostPlatform.emulator buildPackages;
 in stdenv.mkDerivation {
   name = "cc-wrapper-test";
 
@@ -17,28 +18,28 @@ in stdenv.mkDerivation {
 
     printf "checking whether compiler builds valid C binaries... " >&2
     $CC -o cc-check ${./cc-main.c}
-    ./cc-check
+    ${emulator} ./cc-check
 
     printf "checking whether compiler builds valid C++ binaries... " >&2
     $CXX -o cxx-check ${./cxx-main.cc}
-    ./cxx-check
+    ${emulator} ./cxx-check
 
     ${lib.optionalString (stdenv.isDarwin && stdenv.cc.isClang) ''
       printf "checking whether compiler can build with CoreFoundation.framework... " >&2
       mkdir -p foo/lib
       $CC -framework CoreFoundation -o core-foundation-check ${./core-foundation-main.c}
-      ./core-foundation-check
+      ${emulator} ./core-foundation-check
     ''}
 
 
     ${lib.optionalString (!stdenv.isDarwin) ''
       printf "checking whether compiler builds valid static C binaries... " >&2
       $CC ${staticLibc} -static -o cc-static ${./cc-main.c}
-      ./cc-static
+      ${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
         $CC ${staticLibc} -static-pie -o cc-static-pie ${./cc-main.c}
-        ./cc-static-pie
+        ${emulator} ./cc-static-pie
       ''}
     ''}
 
@@ -46,7 +47,7 @@ in stdenv.mkDerivation {
     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}
-    ./cflags-check
+    ${emulator} ./cflags-check
 
     printf "checking whether compiler uses NIX_LDFLAGS... " >&2
     mkdir -p foo/lib
@@ -57,20 +58,20 @@ in stdenv.mkDerivation {
       ${./foo.c}
 
     NIX_LDFLAGS="-L$NIX_BUILD_TOP/foo/lib -rpath $NIX_BUILD_TOP/foo/lib" $CC -lfoo -o ldflags-check ${./ldflags-main.c}
-    ./ldflags-check
+    ${emulator} ./ldflags-check
 
     printf "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}
-    ./nostdinc-main
+    ${emulator} ./nostdinc-main
     $CXX -I std-include -nostdinc++ -o nostdinc-main++ ${./nostdinc-main.c}
-    ./nostdinc-main++
+    ${emulator} ./nostdinc-main++
 
     ${lib.optionalString sanitizersWorking ''
       printf "checking whether sanitizers are fully functional... ">&2
       $CC -o sanitizers -fsanitize=address,undefined ${./sanitizers.c}
-      ./sanitizers
+      ${emulator} ./sanitizers
     ''}
 
     touch $out