Skip to content

Commit

Permalink
Merge pull request #253752 from Artturin/testsccwrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Artturin authored Sep 8, 2023
2 parents 57095e2 + 2d15039 commit b540334
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 49 deletions.
26 changes: 15 additions & 11 deletions pkgs/test/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,41 @@ 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
''}
${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
''}
Expand All @@ -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
Expand All @@ -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"} \
Expand All @@ -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}
Expand All @@ -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
''}
Expand Down
96 changes: 79 additions & 17 deletions pkgs/test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,85 @@
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
(filter (n: n != "llvmPackages_15"))
] ++ 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 { };

Expand Down
42 changes: 21 additions & 21 deletions pkgs/top-level/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ let

# Tests
/*
jobs.tests.cc-wrapper.x86_64-darwin
jobs.tests.cc-wrapper-clang.x86_64-darwin
jobs.tests.cc-wrapper-libcxx.x86_64-darwin
jobs.tests.cc-wrapper.default.x86_64-darwin
jobs.tests.cc-wrapper.llvmPackages.clang.x86_64-darwin
jobs.tests.cc-wrapper.llvmPackages.libcxx.x86_64-darwin
jobs.tests.stdenv-inputs.x86_64-darwin
jobs.tests.macOSSierraShared.x86_64-darwin
jobs.tests.stdenv.hooks.patch-shebangs.x86_64-darwin
Expand Down Expand Up @@ -124,18 +124,18 @@ let
jobs.cachix.x86_64-linux

/*
jobs.tests.cc-wrapper.x86_64-linux
jobs.tests.cc-wrapper-gcc7.x86_64-linux
jobs.tests.cc-wrapper-gcc8.x86_64-linux
jobs.tests.cc-wrapper.default.x86_64-linux
jobs.tests.cc-wrapper.gcc7Stdenv.x86_64-linux
jobs.tests.cc-wrapper.gcc8Stdenv.x86_64-linux
# broken see issue #40038
jobs.tests.cc-wrapper-clang.x86_64-linux
jobs.tests.cc-wrapper-libcxx.x86_64-linux
jobs.tests.cc-wrapper-clang-5.x86_64-linux
jobs.tests.cc-wrapper-libcxx-5.x86_64-linux
jobs.tests.cc-wrapper-clang-6.x86_64-linux
jobs.tests.cc-wrapper-libcxx-6.x86_64-linux
jobs.tests.cc-wrapper.llvmPackages.clang.x86_64-linux
jobs.tests.cc-wrapper.llvmPackages.libcxx.x86_64-linux
jobs.tests.cc-wrapper.llvmPackages_5.clang.x86_64-linux
jobs.tests.cc-wrapper.llvmPackages_5.libcxx.x86_64-linux
jobs.tests.cc-wrapper.llvmPackages_6.clang.x86_64-linux
jobs.tests.cc-wrapper.llvmPackages_6.libcxx.x86_64-linux
jobs.tests.cc-multilib-gcc.x86_64-linux
jobs.tests.cc-multilib-clang.x86_64-linux
jobs.tests.stdenv-inputs.x86_64-linux
Expand All @@ -158,15 +158,15 @@ let
jobs.inkscape.x86_64-darwin
jobs.qt5.qtmultimedia.x86_64-darwin
/*
jobs.tests.cc-wrapper.x86_64-darwin
jobs.tests.cc-wrapper-gcc7.x86_64-darwin
# jobs.tests.cc-wrapper-gcc8.x86_64-darwin
jobs.tests.cc-wrapper-clang.x86_64-darwin
jobs.tests.cc-wrapper-libcxx.x86_64-darwin
jobs.tests.cc-wrapper-clang-5.x86_64-darwin
jobs.tests.cc-wrapper-libcxx-6.x86_64-darwin
jobs.tests.cc-wrapper-clang-6.x86_64-darwin
jobs.tests.cc-wrapper-libcxx-6.x86_64-darwin
jobs.tests.cc-wrapper.default.x86_64-darwin
jobs.tests.cc-wrapper.gcc7Stdenv.x86_64-darwin
jobs.tests.cc-wrapper.gcc8Stdenv.x86_64-darwin
jobs.tests.cc-wrapper.llvmPackages.clang.x86_64-darwin
jobs.tests.cc-wrapper.llvmPackages.libcxx.x86_64-darwin
jobs.tests.cc-wrapper.llvmPackages_5.clang.x86_64-darwin
jobs.tests.cc-wrapper.llvmPackages_5.libcxx.x86_64-darwin
jobs.tests.cc-wrapper.llvmPackages_6.clang.x86_64-darwin
jobs.tests.cc-wrapper.llvmPackages_6.libcxx.x86_64-darwin
jobs.tests.stdenv-inputs.x86_64-darwin
jobs.tests.macOSSierraShared.x86_64-darwin
jobs.tests.stdenv.hooks.patch-shebangs.x86_64-darwin
Expand Down

0 comments on commit b540334

Please sign in to comment.