nixpkgs-tests: add basic test for cc-wrapper

This commit is contained in:
Daiderd Jordan 2017-09-02 14:00:47 +02:00
parent 4d101993bf
commit 19c4673310
No known key found for this signature in database
GPG Key ID: D02435D05B810C96
8 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#include <stdio.h>
int main(int argc, char **argv)
{
fprintf(stderr, "ok\n");
return 0;
}

View File

@ -0,0 +1,10 @@
#include <stdio.h>
#include <foo.h>
int main(int argc, char **argv)
{
if (foo() != 42)
return 1;
fprintf(stderr, "ok\n");
return 0;
}

View File

@ -0,0 +1,7 @@
#include <CoreFoundation/CoreFoundation.h>
int main(int argc, char** argv)
{
CFShow(CFSTR("ok"));
return 0;
}

View File

@ -0,0 +1,7 @@
#include <iostream>
int main(int argc, char **argv)
{
std::cerr << "ok" << std::endl;
return 0;
}

View File

@ -0,0 +1,45 @@
{ stdenv }:
let
shlib = if stdenv.isDarwin then "dylib" else "so";
in
stdenv.mkDerivation {
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
${stdenv.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
''}
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
$CC -shared ${stdenv.lib.optionalString stdenv.isDarwin "-Wl,-install_name,@rpath/libfoo.dylib"} -DVALUE=42 -o foo/lib/libfoo.${shlib} ${./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
touch $out
'';
meta.platforms = stdenv.lib.platforms.all;
}

View File

@ -0,0 +1,4 @@
unsigned int foo(void)
{
return VALUE;
}

View File

@ -0,0 +1,12 @@
#include <stdio.h>
extern unsigned int foo(void);
int main(int argc, char **argv)
{
if (foo() != 42) {
return 1;
}
fprintf(stderr, "ok\n");
return 0;
}

View File

@ -19409,6 +19409,10 @@ with pkgs;
# `recurseIntoAttrs` for sake of hydra, not nix-env
tests = recurseIntoAttrs {
cc-wrapper = callPackage ../test/cc-wrapper { };
cc-wrapper-clang = callPackage ../test/cc-wrapper { stdenv = clangStdenv; };
cc-wrapper-libcxx = callPackage ../test/cc-wrapper { stdenv = libcxxStdenv; };
macOSSierraShared = callPackage ../test/macos-sierra-shared {};
};
}