ldc: 1.3.0 -> 1.5.0

- Bootstrap with ldc lts (0.17.5) instead of dmd.
- Enable unittests by using a fixed-output derivation for runtime tests.
This commit is contained in:
Thomas Mader 2017-11-25 22:51:51 +01:00
parent 54f1b753b3
commit 66860af01a

View File

@ -1,95 +1,172 @@
{ stdenv, fetchFromGitHub, cmake, llvm, dmd, curl, tzdata, python, { stdenv, fetchgit, fetchurl, cmake, llvm, curl, tzdata
lit, gdb, unzip, darwin }: , python, libconfig, lit, gdb, unzip, darwin, bash
, callPackage
, bootstrapVersion ? false
, version ? "1.5.0"
, ldcSha256 ? "1150sgns03vplni2wd4afk3rgw3rap8rsiipspw0rzxgki5rlr83"
}:
stdenv.mkDerivation rec { let
name = "ldc-${version}";
version = "1.3.0";
srcs = [ bootstrapLdc = if !bootstrapVersion then
(fetchFromGitHub { # LDC 0.17.x is the last version which doesn't need a working D compiler to
owner = "ldc-developers"; # build so we use that version to bootstrap the actual build.
repo = "ldc"; callPackage ./default.nix {
rev = "v${version}"; bootstrapVersion = true;
sha256 = "1ac3j4cwwgjpayhijxx4d6478bc3iqksjxkd7xp7byx7k8w1ppdl"; version = "0.17.5";
name = "ldc-v${version}-src"; ldcSha256 = "0200r5y8hs5yv2cx24csgyh00dlg18877b9cfblixypr6nhl19bs";
}) }
(fetchFromGitHub { else
owner = "ldc-developers"; "";
repo = "druntime";
rev = "ldc-v${version}"; ldcBuild = stdenv.mkDerivation rec {
sha256 = "1m13370wnj3sizqk3sdpzi9am5d24srf27d613qblhqa9n8vwz30"; name = "ldcBuild-${version}";
name = "druntime-ldc-v${version}-src";
}) enableParallelBuilding = true;
(fetchFromGitHub {
owner = "ldc-developers"; src = fetchurl {
repo = "phobos"; url = "https://github.com/ldc-developers/ldc/releases/download/v${version}/ldc-${version}-src.tar.gz";
rev = "ldc-v${version}"; sha256 = ldcSha256;
sha256 = "0fhcdfi7a00plwj27ysfyv783nhk0kspq7hawf6vbsl3s1nyvn8g"; };
name = "phobos-ldc-v${version}-src";
})
(fetchFromGitHub {
owner = "ldc-developers";
repo = "dmd-testsuite";
rev = "ldc-v${version}";
sha256 = "0dmdkp220gqhxjrmrjfkf0vsvylwfaj70hswavq4q3v4dg17pzmj";
name = "dmd-testsuite-ldc-v${version}-src";
})
];
sourceRoot = "."; sourceRoot = ".";
postUnpack = '' postUnpack = ''
mv ldc-v${version}-src/* . cd ldc-${version}-src/
mv druntime-ldc-v${version}-src/* runtime/druntime patchShebangs .
mv phobos-ldc-v${version}-src/* runtime/phobos
mv dmd-testsuite-ldc-v${version}-src/* tests/d2/dmd-testsuite
# Remove cppa test for now because it doesn't work. # Remove cppa test for now because it doesn't work.
rm tests/d2/dmd-testsuite/runnable/cppa.d rm tests/d2/dmd-testsuite/runnable/cppa.d
rm tests/d2/dmd-testsuite/runnable/extra-files/cppb.cpp rm tests/d2/dmd-testsuite/runnable/extra-files/cppb.cpp
''
+ stdenv.lib.optionalString (bootstrapVersion) ''
# ... runnable/variadic.d ()
#Test failed. The logged output:
#/tmp/nix-build-ldcBuild-0.17.5.drv-0/ldc-0.17.5-src/build/bin/ldmd2 -conf= -m64 -Irunnable -od/tmp/nix-build-ldcBuild-0.17.5.drv-0/ldc-0.17.5-src/build/dmd-testsuite/runnable -of/tmp/nix-build-ldcBuild-0.17.5.drv-0/ldc-0.17.5-src/build/dmd-testsuite/runnable/variadic_0 runnable/variadic.d
#Error: integer constant expression expected instead of <cant>
#Error: integer constant expression expected instead of <cant>
#Error: integer constant expression expected instead of <cant>
#Error: integer constant expression expected instead of <cant>
#Error: integer constant expression expected instead of <cant>
#runnable/variadic.d(84): Error: template instance variadic.Foo3!(int, int, int) error instantiating
#
#
#==============================
#Test failed: expected rc == 0, exited with rc == 1
rm tests/d2/dmd-testsuite/runnable/variadic.d
''
+ stdenv.lib.optionalString (!bootstrapVersion) ''
# https://github.com/NixOS/nixpkgs/issues/29611
rm tests/sanitizers/asan_*
''; '';
ROOT_HOME_DIR = "$(echo ~root)";
datetimePath = if bootstrapVersion then
"phobos/std/datetime.d"
else
"phobos/std/datetime/timezone.d";
postPatch = '' postPatch = ''
substituteInPlace cmake/Modules/FindLLVM.cmake \
--replace "llvm_set(LIBRARY_DIRS" "#llvm_set(LIBRARY_DIRS"
substituteInPlace runtime/${datetimePath} \
--replace "import core.time;" "import core.time;import std.path;"
substituteInPlace runtime/${datetimePath} \
--replace "tzName == \"leapseconds\"" "baseName(tzName) == \"leapseconds\""
substituteInPlace runtime/phobos/std/net/curl.d \ substituteInPlace runtime/phobos/std/net/curl.d \
--replace libcurl.so ${curl.out}/lib/libcurl.so --replace libcurl.so ${curl.out}/lib/libcurl.so
# Ugly hack to fix the hardcoded path to zoneinfo in the source file. # Ugly hack to fix the hardcoded path to zoneinfo in the source file.
# https://issues.dlang.org/show_bug.cgi?id=15391 # https://issues.dlang.org/show_bug.cgi?id=15391
substituteInPlace runtime/phobos/std/datetime.d \ substituteInPlace runtime/${datetimePath} \
--replace /usr/share/zoneinfo/ ${tzdata}/share/zoneinfo/ --replace /usr/share/zoneinfo/ ${tzdata}/share/zoneinfo/
substituteInPlace tests/d2/dmd-testsuite/Makefile \
--replace "SHELL=/bin/bash" "SHELL=${bash}/bin/bash"
'' ''
+ stdenv.lib.optionalString stdenv.hostPlatform.isDarwin '' + stdenv.lib.optionalString stdenv.hostPlatform.isLinux ''
substituteInPlace driver/tool.cpp \ # See https://github.com/NixOS/nixpkgs/issues/29443
substituteInPlace runtime/phobos/std/path.d \
--replace "\"/root" "\"${ROOT_HOME_DIR}"
# TODO
substituteInPlace runtime/druntime/src/core/memory.d \
--replace "assert(z is null);" "//assert(z is null);"
''
+ stdenv.lib.optionalString (bootstrapVersion && stdenv.hostPlatform.isDarwin) ''
# https://github.com/ldc-developers/ldc/pull/2306
# Can be removed on bootstrap version > 0.17.5
substituteInPlace gen/programs.cpp \
--replace "gcc" "clang" --replace "gcc" "clang"
# Was not able to compile on darwin due to "__inline_isnanl"
# being undefined.
substituteInPlace dmd2/root/port.c --replace __inline_isnanl __inline_isnan
''
+ stdenv.lib.optionalString (stdenv.hostPlatform.isLinux && bootstrapVersion) ''
substituteInPlace dmd2/root/port.c \
--replace "#include <bits/mathdef.h>" "#include <complex.h>"
''
+ stdenv.lib.optionalString (bootstrapVersion) ''
substituteInPlace runtime/${datetimePath} \
--replace "import std.traits;" "import std.traits;import std.path;"
substituteInPlace runtime/${datetimePath} \
--replace "tzName == \"+VERSION\"" "baseName(tzName) == \"leapseconds\" || tzName == \"+VERSION\""
''; '';
nativeBuildInputs = [ cmake llvm dmd python lit gdb unzip ] nativeBuildInputs = [ cmake llvm bootstrapLdc python lit gdb unzip ]
++ stdenv.lib.optional (bootstrapVersion) [
libconfig
]
++ stdenv.lib.optional stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [ ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [
Foundation Foundation
]); ]);
buildInputs = [ curl tzdata stdenv.cc ]; buildInputs = [ curl tzdata stdenv.cc ];
preConfigure = '' preConfigure = ''
cmakeFlagsArray=("-DINCLUDE_INSTALL_DIR=$out/include/dlang/ldc") cmakeFlagsArray=("-DINCLUDE_INSTALL_DIR=$out/include/dlang/ldc"
"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_SKIP_RPATH=ON"
"-DBUILD_SHARED_LIBS=OFF"
"-DLDC_WITH_LLD=OFF"
# Xcode 9.0.1 fixes that bug according to ldc release notes
"-DRT_ARCHIVE_WITH_LDC=OFF"
"-DLLVM_LIBRARY_DIRS=${llvm}/lib"
)
''; '';
postConfigure = '' postConfigure = ''
export DMD=$PWD/bin/ldc2 export DMD=$PWD/bin/ldmd2
''; '';
makeFlags = [ "DMD=$DMD" ]; makeFlags = [ "DMD=$DMD" ];
# disable check phase because some tests are not working with sandboxing doCheck = true;
doCheck = false;
checkPhase = '' checkPhase = ''
ctest -j $NIX_BUILD_CORES -V DMD=$DMD # Build and run LDC D unittests.
ctest --output-on-failure -R "ldc2-unittest"
# Run LIT testsuite.
ctest -V -R "lit-tests"
# Run DMD testsuite.
DMD_TESTSUITE_MAKE_ARGS=-j$NIX_BUILD_CORES ctest -V -R "dmd-testsuite"
''; '';
meta = with stdenv.lib; { meta = with stdenv.lib; {
@ -98,6 +175,84 @@ stdenv.mkDerivation rec {
# from https://github.com/ldc-developers/ldc/blob/master/LICENSE # from https://github.com/ldc-developers/ldc/blob/master/LICENSE
license = with licenses; [ bsd3 boost mit ncsa gpl2Plus ]; license = with licenses; [ bsd3 boost mit ncsa gpl2Plus ];
maintainers = with maintainers; [ ThomasMader ]; maintainers = with maintainers; [ ThomasMader ];
platforms = platforms.unix; platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" ];
}; };
};
# Need to test Phobos in a fixed-output derivation, otherwise the
# network stuff in Phobos would fail if sandbox mode is enabled.
ldcUnittests = stdenv.mkDerivation rec {
name = "ldcUnittests-${version}";
enableParallelBuilding = ldcBuild.enableParallelBuilding;
preferLocalBuild = true;
inputString = ldcBuild.outPath;
outputHashAlgo = "sha256";
outputHash = builtins.hashString "sha256" inputString;
src = ldcBuild.src;
sourceRoot = ".";
postUnpack = ldcBuild.postUnpack;
postPatch = ldcBuild.postPatch;
nativeBuildInputs = ldcBuild.nativeBuildInputs
++ [
ldcBuild
];
buildInputs = ldcBuild.buildInputs;
preConfigure = ''
cmakeFlagsArray=( "-DINCLUDE_INSTALL_DIR=$out/include/dlang/ldc"
"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_SKIP_RPATH=ON"
"-DBUILD_SHARED_LIBS=OFF"
"-DLDC_WITH_LLD=OFF"
# Xcode 9.0.1 fixes that bug according to ldc release notes
"-DRT_ARCHIVE_WITH_LDC=OFF"
"-DLLVM_LIBRARY_DIRS=${llvm}/lib"
"-DD_COMPILER=${ldcBuild}/bin/ldmd2"
)
'';
postConfigure = ldcBuild.postConfigure;
makeFlags = ldcBuild.makeFlags;
buildCmd = if bootstrapVersion then
"ctest -V -R \"build-druntime-ldc-unittest|build-phobos2-ldc-unittest\""
else
"make -j$NIX_BUILD_CORES DMD=${ldcBuild}/bin/ldc2 druntime-test-runner druntime-test-runner-debug phobos2-test-runner phobos2-test-runner-debug";
testCmd = if bootstrapVersion then
"ctest -j$NIX_BUILD_CORES --output-on-failure -E \"dmd-testsuite|lit-tests|ldc2-unittest|llvm-ir-testsuite\""
else
"ctest -j$NIX_BUILD_CORES --output-on-failure -E \"dmd-testsuite|lit-tests|ldc2-unittest\"";
buildPhase = ''
${buildCmd}
${testCmd}
'';
installPhase = ''
echo -n $inputString > $out
'';
};
in
stdenv.mkDerivation rec {
inherit ldcUnittests;
name = "ldc-${version}";
phases = "installPhase";
installPhase = ''
mkdir $out
cp -r --symbolic-link ${ldcBuild}/* $out/
'';
} }