summaryrefslogtreecommitdiffstats
path: root/pkgs/test
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2017-09-02 14:00:47 +0200
committerDaiderd Jordan <daiderd@gmail.com>2017-09-10 22:49:39 +0200
commit19c46733104c680267a0a0dd3a2e6be893bd52b4 (patch)
treebd0ed536ebd1932e5088c3d969bd1119f665e9ef /pkgs/test
parent4d101993bfed0a40caf5e1aaa19cc085f2c7192a (diff)
nixpkgs-tests: add basic test for cc-wrapper
Diffstat (limited to 'pkgs/test')
-rw-r--r--pkgs/test/cc-wrapper/cc-main.c7
-rw-r--r--pkgs/test/cc-wrapper/cflags-main.c10
-rw-r--r--pkgs/test/cc-wrapper/core-foundation-main.c7
-rw-r--r--pkgs/test/cc-wrapper/cxx-main.cc7
-rw-r--r--pkgs/test/cc-wrapper/default.nix45
-rw-r--r--pkgs/test/cc-wrapper/foo.c4
-rw-r--r--pkgs/test/cc-wrapper/ldflags-main.c12
7 files changed, 92 insertions, 0 deletions
diff --git a/pkgs/test/cc-wrapper/cc-main.c b/pkgs/test/cc-wrapper/cc-main.c
new file mode 100644
index 000000000000..06f28bc33c69
--- /dev/null
+++ b/pkgs/test/cc-wrapper/cc-main.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ fprintf(stderr, "ok\n");
+ return 0;
+}
diff --git a/pkgs/test/cc-wrapper/cflags-main.c b/pkgs/test/cc-wrapper/cflags-main.c
new file mode 100644
index 000000000000..9491232b5387
--- /dev/null
+++ b/pkgs/test/cc-wrapper/cflags-main.c
@@ -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;
+}
diff --git a/pkgs/test/cc-wrapper/core-foundation-main.c b/pkgs/test/cc-wrapper/core-foundation-main.c
new file mode 100644
index 000000000000..fb3bd3126191
--- /dev/null
+++ b/pkgs/test/cc-wrapper/core-foundation-main.c
@@ -0,0 +1,7 @@
+#include <CoreFoundation/CoreFoundation.h>
+
+int main(int argc, char** argv)
+{
+ CFShow(CFSTR("ok"));
+ return 0;
+}
diff --git a/pkgs/test/cc-wrapper/cxx-main.cc b/pkgs/test/cc-wrapper/cxx-main.cc
new file mode 100644
index 000000000000..83f704617a46
--- /dev/null
+++ b/pkgs/test/cc-wrapper/cxx-main.cc
@@ -0,0 +1,7 @@
+#include <iostream>
+
+int main(int argc, char **argv)
+{
+ std::cerr << "ok" << std::endl;
+ return 0;
+}
diff --git a/pkgs/test/cc-wrapper/default.nix b/pkgs/test/cc-wrapper/default.nix
new file mode 100644
index 000000000000..d8a5e1355815
--- /dev/null
+++ b/pkgs/test/cc-wrapper/default.nix
@@ -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;
+}
diff --git a/pkgs/test/cc-wrapper/foo.c b/pkgs/test/cc-wrapper/foo.c
new file mode 100644
index 000000000000..8be674be3103
--- /dev/null
+++ b/pkgs/test/cc-wrapper/foo.c
@@ -0,0 +1,4 @@
+unsigned int foo(void)
+{
+ return VALUE;
+}
diff --git a/pkgs/test/cc-wrapper/ldflags-main.c b/pkgs/test/cc-wrapper/ldflags-main.c
new file mode 100644
index 000000000000..89832b3bbad2
--- /dev/null
+++ b/pkgs/test/cc-wrapper/ldflags-main.c
@@ -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;
+}