Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests.cc-wrapper: run on more compilers #253752

Merged
merged 9 commits into from
Sep 8, 2023
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests.cc-wrapper.gccMultiStdenv fails with

cc-wrapper-test-gcc> checking whether sanitizers are fully functional... ./sanitizers: error while loading shared libraries: libstdc++.so.6: wrong ELF class: ELFCLASS32

Copy link
Member Author

@Artturin Artturin Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests.cc-wrapper.llvmPackages_15.libcxx fails with

cc-wrapper-test-clang-libcxx> checking whether compiler builds valid C++ binaries...
cc-wrapper-test-clang-libcxx> -/nix/store/8zxgqm6d879hskwh5g1l4crysl01kdv0-binutils-2.40/bin/ld: cannot find l: No such file or directory
$ diff pkgs/development/compilers/llvm/15/libcxx/default.nix pkgs/development/compilers/llvm/16/libcxx/default.nix
50,51d49
<   ] ++ lib.optionals stdenv.hostPlatform.isMusl [
<     ../../libcxx-0001-musl-hacks.patch
82,83d79
<       # (Backport fix from 16, which has LIBCXX_ADDITIONAL_LIBRARIES, but 15
<       # does not appear to)
86c82
<       #   -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwind
---
>       #   -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder
89,90c85
<       # "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind"
<       "-DCMAKE_SHARED_LINKER_FLAGS=-lunwind"
---
>       "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind"

the cause does not appear to be any of these diffs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests.cc-wrapper.gcc49Stdenv fails with

cc-wrapper-test-gcc> checking whether sanitizers are fully functional...
cc-wrapper-test-gcc> In file included from /nix/store/3c3vrabg4yy87y4qx8zsy5x2vdg132j5-sanitizers.c:1:0:
cc-wrapper-test-gcc> /nix/store/ix23ggz0k9vrhbl6ig7bwqcgf396rwmx-gcc-4.9.4/lib/gcc/x86_64-unknown-linux-gnu/4.9.4/include/sanitizer/asan_interface.h:53:3: error: unknown type name 'bool'
cc-wrapper-test-gcc>    bool __asan_address_is_poisoned(void const volatile *addr);
cc-wrapper-test-gcc>    ^
cc-wrapper-test-gcc> /nix/store/ix23ggz0k9vrhbl6ig7bwqcgf396rwmx-gcc-4.9.4/lib/gcc/x86_64-unknown-linux-gnu/4.9.4/include/sanitizer/asan_interface.h:66:40: error: unknown type name 'bool'
cc-wrapper-test-gcc>                             void *addr, bool is_write, size_t access_size);
cc-wrapper-test-gcc>                                         ^
cc-wrapper-test-gcc> /nix/store/ix23ggz0k9vrhbl6ig7bwqcgf396rwmx-gcc-4.9.4/lib/gcc/x86_64-unknown-linux-gnu/4.9.4/include/sanitizer/asan_interface.h:88:3: error: unknown type name 'bool'
cc-wrapper-test-gcc>    bool __asan_symbolize(const void *pc, char *out_buffer,
cc-wrapper-test-gcc>    ^
cc-wrapper-test-gcc> /nix/store/ix23ggz0k9vrhbl6ig7bwqcgf396rwmx-gcc-4.9.4/lib/gcc/x86_64-unknown-linux-gnu/4.9.4/include/sanitizer/asan_interface.h:98:3: error: unknown type name 'bool'
cc-wrapper-test-gcc>    bool __asan_get_ownership(const void *p);
cc-wrapper-test-gcc>    ^

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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the jobs.tests are run here because of 36587a5

There's a useful snippet in the comments if we want to run these

      tests = forAllSystems
        (system:
          let pkgs = pkgsFor system; in
          pkgs.callPackages ../test {});

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