2017-09-02 13:00:47 +01:00
|
|
|
{ stdenv }:
|
2018-05-31 02:48:42 +01:00
|
|
|
with stdenv.lib;
|
|
|
|
let
|
2018-06-06 08:59:59 +01:00
|
|
|
# Sanitizers are not supported on Darwin.
|
2018-05-31 02:48:42 +01:00
|
|
|
# Sanitizer headers aren't available in older libc++ stdenvs due to a bug
|
2018-06-18 20:05:23 +01:00
|
|
|
sanitizersWorking =
|
2018-06-18 20:30:39 +01:00
|
|
|
(stdenv.cc.isClang && versionAtLeast (getVersion stdenv.cc.name) "5.0.0")
|
2018-06-18 20:05:23 +01:00
|
|
|
|| (stdenv.cc.isGNU && stdenv.isLinux);
|
2018-05-31 02:48:42 +01:00
|
|
|
in stdenv.mkDerivation {
|
2017-09-02 13:00:47 +01:00
|
|
|
name = "cc-wrapper-test";
|
|
|
|
|
|
|
|
buildCommand = ''
|
|
|
|
NIX_DEBUG=1 $CC -v
|
|
|
|
NIX_DEBUG=1 $CXX -v
|
|
|
|
|
|
|
|
printf "checking whether compiler builds valid C binaries... " >&2
|
|
|
|
$CC -o cc-check ${./cc-main.c}
|
|
|
|
./cc-check
|
|
|
|
|
|
|
|
printf "checking whether compiler builds valid C++ binaries... " >&2
|
|
|
|
$CXX -o cxx-check ${./cxx-main.cc}
|
|
|
|
./cxx-check
|
|
|
|
|
2018-05-31 02:48:42 +01:00
|
|
|
${optionalString (stdenv.isDarwin && stdenv.cc.isClang) ''
|
2017-09-02 13:00:47 +01:00
|
|
|
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
|
|
|
|
''}
|
|
|
|
|
|
|
|
printf "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}
|
|
|
|
./cflags-check
|
|
|
|
|
|
|
|
printf "checking whether compiler uses NIX_LDFLAGS... " >&2
|
|
|
|
mkdir -p foo/lib
|
2017-09-12 20:36:41 +01:00
|
|
|
$CC -shared \
|
2018-05-31 02:48:42 +01:00
|
|
|
${optionalString stdenv.isDarwin "-Wl,-install_name,@rpath/libfoo.dylib"} \
|
2017-09-12 20:36:41 +01:00
|
|
|
-DVALUE=42 \
|
|
|
|
-o foo/lib/libfoo${stdenv.hostPlatform.extensions.sharedLibrary} \
|
|
|
|
${./foo.c}
|
|
|
|
|
2017-09-02 13:00:47 +01:00
|
|
|
NIX_LDFLAGS="-L$NIX_BUILD_TOP/foo/lib -rpath $NIX_BUILD_TOP/foo/lib" $CC -lfoo -o ldflags-check ${./ldflags-main.c}
|
|
|
|
./ldflags-check
|
2018-05-07 21:22:50 +01:00
|
|
|
|
2020-07-01 21:55:06 +01:00
|
|
|
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
|
|
|
|
$CXX -I std-include -nostdinc++ -o nostdinc-main++ ${./nostdinc-main.c}
|
|
|
|
./nostdinc-main++
|
|
|
|
|
2018-06-18 20:05:23 +01:00
|
|
|
${optionalString sanitizersWorking ''
|
2018-05-31 02:48:42 +01:00
|
|
|
printf "checking whether sanitizers are fully functional... ">&2
|
|
|
|
$CC -o sanitizers -fsanitize=address,undefined ${./sanitizers.c}
|
|
|
|
./sanitizers
|
|
|
|
''}
|
2017-09-02 13:00:47 +01:00
|
|
|
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
|
2018-05-31 02:48:42 +01:00
|
|
|
meta.platforms = platforms.all;
|
2017-09-02 13:00:47 +01:00
|
|
|
}
|