2017-08-01 02:02:20 +01:00
|
|
|
{ lib, clangStdenv, clang-sierraHack-stdenv, stdenvNoCC }:
|
2017-07-18 04:36:17 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
makeBigExe = stdenv: prefix: rec {
|
|
|
|
|
2017-07-27 04:28:36 +01:00
|
|
|
count = 500;
|
|
|
|
|
2017-07-18 04:36:17 +01:00
|
|
|
sillyLibs = lib.genList (i: stdenv.mkDerivation rec {
|
|
|
|
name = "${prefix}-fluff-${toString i}";
|
|
|
|
unpackPhase = ''
|
|
|
|
src=$PWD
|
2017-07-27 04:28:36 +01:00
|
|
|
cat << 'EOF' > ${name}.c
|
|
|
|
unsigned int asdf_${toString i}(void) {
|
|
|
|
return ${toString i};
|
|
|
|
}
|
|
|
|
EOF
|
2017-07-18 04:36:17 +01:00
|
|
|
'';
|
|
|
|
buildPhase = ''
|
2017-07-27 04:28:36 +01:00
|
|
|
$CC -std=c99 -shared ${name}.c -o lib${name}.dylib -Wl,-install_name,$out/lib/lib${name}.dylib
|
2017-07-18 04:36:17 +01:00
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p "$out/lib"
|
|
|
|
mv lib${name}.dylib "$out/lib"
|
|
|
|
'';
|
2017-08-01 02:02:20 +01:00
|
|
|
meta.platforms = lib.platforms.darwin;
|
2017-07-27 04:28:36 +01:00
|
|
|
}) count;
|
2017-07-18 04:36:17 +01:00
|
|
|
|
|
|
|
finalExe = stdenv.mkDerivation rec {
|
|
|
|
name = "${prefix}-final-asdf";
|
|
|
|
unpackPhase = ''
|
|
|
|
src=$PWD
|
2017-07-27 04:28:36 +01:00
|
|
|
cat << 'EOF' > main.cxx
|
|
|
|
|
2017-07-27 19:37:24 +01:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
2017-07-27 04:28:36 +01:00
|
|
|
|
2017-07-27 19:15:10 +01:00
|
|
|
${toString (lib.genList (i: "extern \"C\" unsigned int asdf_${toString i}(void); ") count)}
|
2017-07-27 04:28:36 +01:00
|
|
|
|
|
|
|
unsigned int (*funs[])(void) = {
|
|
|
|
${toString (lib.genList (i: "asdf_${toString i},") count)}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2017-07-27 19:37:24 +01:00
|
|
|
bool ret;
|
2017-07-27 04:28:36 +01:00
|
|
|
unsigned int i = 0;
|
|
|
|
for (auto f : funs) {
|
2017-07-27 19:37:24 +01:00
|
|
|
if (f() != i++) {
|
|
|
|
std::cerr << "Failed to get expected response from function #" << i << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2017-07-27 04:28:36 +01:00
|
|
|
}
|
2017-07-27 19:37:24 +01:00
|
|
|
return EXIT_SUCCESS;
|
2017-07-27 04:28:36 +01:00
|
|
|
}
|
|
|
|
EOF
|
2017-07-18 04:36:17 +01:00
|
|
|
'';
|
|
|
|
buildPhase = ''
|
2017-08-01 02:02:20 +01:00
|
|
|
$CXX -std=c++11 main.cxx ${toString (map (x: "-l${x.name}") sillyLibs)} -o ${prefix}-asdf
|
2017-07-18 04:36:17 +01:00
|
|
|
'';
|
|
|
|
buildInputs = sillyLibs;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p "$out/bin"
|
2017-08-01 02:02:20 +01:00
|
|
|
mv ${prefix}-asdf "$out/bin"
|
2017-07-18 04:36:17 +01:00
|
|
|
'';
|
2017-08-01 02:02:20 +01:00
|
|
|
meta.platforms = lib.platforms.darwin;
|
2017-07-18 04:36:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
good = makeBigExe clang-sierraHack-stdenv "good";
|
2017-08-01 02:02:20 +01:00
|
|
|
|
2017-07-18 04:36:17 +01:00
|
|
|
bad = makeBigExe clangStdenv "bad";
|
2017-08-01 02:02:20 +01:00
|
|
|
|
|
|
|
in stdenvNoCC.mkDerivation {
|
|
|
|
name = "macos-sierra-shared-test";
|
|
|
|
buildInputs = [ good.finalExe bad.finalExe ];
|
|
|
|
# TODO(@Ericson2314): Be impure or require exact MacOS version of builder?
|
|
|
|
buildCommand = ''
|
|
|
|
if bad-asdf
|
|
|
|
then echo "bad-asdf can succeed on non-sierra, OK" >&2
|
|
|
|
else echo "bad-asdf should fail on sierra, OK" >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Must succeed on all supported MacOS versions
|
|
|
|
good-asdf
|
|
|
|
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
meta.platforms = lib.platforms.darwin;
|
2017-07-18 04:36:17 +01:00
|
|
|
}
|