Merge pull request #28943 from LnL7/stdenv-tests
tests: add some basic stdenv/cc-wrapper tests
This commit is contained in:
commit
33c99ab2fb
7
pkgs/test/cc-wrapper/cc-main.c
Normal file
7
pkgs/test/cc-wrapper/cc-main.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
fprintf(stderr, "ok\n");
|
||||
return 0;
|
||||
}
|
10
pkgs/test/cc-wrapper/cflags-main.c
Normal file
10
pkgs/test/cc-wrapper/cflags-main.c
Normal 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;
|
||||
}
|
7
pkgs/test/cc-wrapper/core-foundation-main.c
Normal file
7
pkgs/test/cc-wrapper/core-foundation-main.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
CFShow(CFSTR("ok"));
|
||||
return 0;
|
||||
}
|
7
pkgs/test/cc-wrapper/cxx-main.cc
Normal file
7
pkgs/test/cc-wrapper/cxx-main.cc
Normal file
@ -0,0 +1,7 @@
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::cerr << "ok" << std::endl;
|
||||
return 0;
|
||||
}
|
45
pkgs/test/cc-wrapper/default.nix
Normal file
45
pkgs/test/cc-wrapper/default.nix
Normal 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;
|
||||
}
|
4
pkgs/test/cc-wrapper/foo.c
Normal file
4
pkgs/test/cc-wrapper/foo.c
Normal file
@ -0,0 +1,4 @@
|
||||
unsigned int foo(void)
|
||||
{
|
||||
return VALUE;
|
||||
}
|
12
pkgs/test/cc-wrapper/ldflags-main.c
Normal file
12
pkgs/test/cc-wrapper/ldflags-main.c
Normal 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;
|
||||
}
|
3
pkgs/test/stdenv-inputs/bar.c
Normal file
3
pkgs/test/stdenv-inputs/bar.c
Normal file
@ -0,0 +1,3 @@
|
||||
unsigned int bar(void) {
|
||||
return 42;
|
||||
}
|
7
pkgs/test/stdenv-inputs/cc-main.c
Normal file
7
pkgs/test/stdenv-inputs/cc-main.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
fprintf(stderr, "ok\n");
|
||||
return 0;
|
||||
}
|
64
pkgs/test/stdenv-inputs/default.nix
Normal file
64
pkgs/test/stdenv-inputs/default.nix
Normal file
@ -0,0 +1,64 @@
|
||||
{ stdenv }:
|
||||
|
||||
let
|
||||
shlib = if stdenv.isDarwin then "dylib" else "so";
|
||||
|
||||
foo = stdenv.mkDerivation {
|
||||
name = "foo-test";
|
||||
|
||||
unpackPhase = ":";
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin $out/include $out/lib
|
||||
$CC -o $out/bin/foo ${./cc-main.c}
|
||||
chmod +x $out/bin/foo
|
||||
cp ${./foo.c} $out/include/foo.h
|
||||
$CC -shared ${stdenv.lib.optionalString stdenv.isDarwin "-Wl,-install_name,$out/lib/libfoo.dylib"} -o $out/lib/libfoo.${shlib} ${./foo.c}
|
||||
'';
|
||||
};
|
||||
|
||||
bar = stdenv.mkDerivation {
|
||||
name = "bar-test";
|
||||
outputs = [ "out" "dev" ];
|
||||
|
||||
unpackPhase = ":";
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin $dev/include $dev/lib
|
||||
$CC -o $out/bin/bar ${./cc-main.c}
|
||||
chmod +x $out/bin/bar
|
||||
cp ${./bar.c} $dev/include/bar.h
|
||||
$CC -shared ${stdenv.lib.optionalString stdenv.isDarwin "-Wl,-install_name,$dev/lib/libbar.dylib"} -o $dev/lib/libbar.${shlib} ${./bar.c}
|
||||
'';
|
||||
};
|
||||
in
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "stdenv-inputs-test";
|
||||
phases = [ "buildPhase" ];
|
||||
|
||||
buildInputs = [ foo bar ];
|
||||
|
||||
buildPhase = ''
|
||||
env
|
||||
|
||||
printf "checking whether binaries are available... " >&2
|
||||
foo && bar
|
||||
|
||||
printf "checking whether compiler can find headers... " >&2
|
||||
$CC -o include-check ${./include-main.c}
|
||||
./include-check
|
||||
|
||||
printf "checking whether compiler can find headers... " >&2
|
||||
$CC -o include-check ${./include-main.c}
|
||||
./include-check
|
||||
|
||||
printf "checking whether compiler can find libraries... " >&2
|
||||
$CC -lfoo -lbar -o lib-check ${./lib-main.c}
|
||||
./lib-check
|
||||
|
||||
touch $out
|
||||
'';
|
||||
|
||||
meta.platforms = stdenv.lib.platforms.all;
|
||||
}
|
3
pkgs/test/stdenv-inputs/foo.c
Normal file
3
pkgs/test/stdenv-inputs/foo.c
Normal file
@ -0,0 +1,3 @@
|
||||
unsigned int foo(void) {
|
||||
return 42;
|
||||
}
|
13
pkgs/test/stdenv-inputs/include-main.c
Normal file
13
pkgs/test/stdenv-inputs/include-main.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <foo.h>
|
||||
#include <bar.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (foo() != 42)
|
||||
return 1;
|
||||
if (bar() != 42)
|
||||
return 1;
|
||||
fprintf(stderr, "ok\n");
|
||||
return 0;
|
||||
}
|
14
pkgs/test/stdenv-inputs/lib-main.c
Normal file
14
pkgs/test/stdenv-inputs/lib-main.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
extern unsigned int foo(void);
|
||||
extern unsigned int bar(void);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (foo() != 42)
|
||||
return 1;
|
||||
if (bar() != 42)
|
||||
return 1;
|
||||
fprintf(stderr, "ok\n");
|
||||
return 0;
|
||||
}
|
@ -19409,6 +19409,11 @@ 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; };
|
||||
stdenv-inputs = callPackage ../test/stdenv-inputs { };
|
||||
|
||||
macOSSierraShared = callPackage ../test/macos-sierra-shared {};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user