about summary refs log tree commit diff
path: root/pkgs/development/compilers/ldc/default.nix
diff options
context:
space:
mode:
authorThomas Mader <thomas.mader@gmail.com>2019-01-22 23:00:35 +0100
committerThomas Mader <thomas.mader@gmail.com>2019-02-21 22:44:52 +0100
commit98c6d9d799bbb295148f5c252b30881c408f0ea6 (patch)
tree70b33ea024270c715f2152b5b43a0c7c3f0315eb /pkgs/development/compilers/ldc/default.nix
parenta44784e81181c971a41c588d93a6cf4bbd1a394c (diff)
downloadnixlib-98c6d9d799bbb295148f5c252b30881c408f0ea6.tar
nixlib-98c6d9d799bbb295148f5c252b30881c408f0ea6.tar.gz
nixlib-98c6d9d799bbb295148f5c252b30881c408f0ea6.tar.bz2
nixlib-98c6d9d799bbb295148f5c252b30881c408f0ea6.tar.lz
nixlib-98c6d9d799bbb295148f5c252b30881c408f0ea6.tar.xz
nixlib-98c6d9d799bbb295148f5c252b30881c408f0ea6.tar.zst
nixlib-98c6d9d799bbb295148f5c252b30881c408f0ea6.zip
ldc: 1.12.0 -> 1.14.0
Diffstat (limited to 'pkgs/development/compilers/ldc/default.nix')
-rw-r--r--pkgs/development/compilers/ldc/default.nix288
1 files changed, 118 insertions, 170 deletions
diff --git a/pkgs/development/compilers/ldc/default.nix b/pkgs/development/compilers/ldc/default.nix
index 80ccb0dbbd30..a290d2b6cfe6 100644
--- a/pkgs/development/compilers/ldc/default.nix
+++ b/pkgs/development/compilers/ldc/default.nix
@@ -2,8 +2,8 @@
 , python, libconfig, lit, gdb, unzip, darwin, bash
 , callPackage, makeWrapper, targetPackages
 , bootstrapVersion ? false
-, version ? "1.12.0"
-, ldcSha256 ? "1fdma1w8j37wkr0pqdar11slkk36qymamxnk6d9k8ybhjmxaaawm"
+, version ? "1.14.0"
+, ldcSha256 ? "147vlzzzjx2n6zyz9wj54gj046i1mw5p5wixwzi5wkllgxghyy9c"
 }:
 
 let
@@ -18,208 +18,156 @@ let
   else
     "";
 
-  ldcBuild = stdenv.mkDerivation rec {
-    name = "ldcBuild-${version}";
+in
 
-    enableParallelBuilding = true;
+stdenv.mkDerivation rec {
+  name = "ldc-${version}";
 
-    src = fetchurl {
-      url = "https://github.com/ldc-developers/ldc/releases/download/v${version}/ldc-${version}-src.tar.gz";
-      sha256 = ldcSha256;
-    };
+  enableParallelBuilding = true;
 
-    postUnpack = ''
-        patchShebangs .
-    ''
+  src = fetchurl {
+    url = "https://github.com/ldc-developers/ldc/releases/download/v${version}/ldc-${version}-src.tar.gz";
+    sha256 = ldcSha256;
+  };
 
-    + stdenv.lib.optionalString (!bootstrapVersion && stdenv.hostPlatform.isDarwin) ''
-        # http://forum.dlang.org/thread/xtbbqthxutdoyhnxjhxl@forum.dlang.org
-        rm -r ldc-${version}-src/tests/dynamiccompile
+  # https://issues.dlang.org/show_bug.cgi?id=19553
+  hardeningDisable = [ "fortify" ];
 
-        # https://github.com/NixOS/nixpkgs/issues/34817
-        rm -r ldc-${version}-src/tests/plugins/addFuncEntryCall
+  postUnpack = ''
+      patchShebangs .
+  ''
 
-        # https://github.com/NixOS/nixpkgs/pull/36378#issuecomment-385034818
-        rm -r ldc-${version}-src/tests/debuginfo/classtypes_gdb.d
-        rm -r ldc-${version}-src/tests/debuginfo/nested_gdb.d
+  + stdenv.lib.optionalString (!bootstrapVersion && stdenv.hostPlatform.isDarwin) ''
+      # https://github.com/NixOS/nixpkgs/issues/34817
+      rm -r ldc-${version}-src/tests/plugins/addFuncEntryCall
+  ''
 
-        rm ldc-${version}-src/tests/d2/dmd-testsuite/runnable/test16096.sh
-        rm ldc-${version}-src/tests/d2/dmd-testsuite/compilable/ldc_output_filenames.sh
-        rm ldc-${version}-src/tests/d2/dmd-testsuite/compilable/crlf.sh
-        rm ldc-${version}-src/tests/d2/dmd-testsuite/compilable/issue15574.sh
-        rm ldc-${version}-src/tests/d2/dmd-testsuite/compilable/test6461.sh
-    ''
+  + stdenv.lib.optionalString (!bootstrapVersion) ''
+      echo ${tzdata}/share/zoneinfo/ > ldc-${version}-src/TZDatabaseDirFile
 
-    + stdenv.lib.optionalString (!bootstrapVersion) ''
-        echo ${tzdata}/share/zoneinfo/ > ldc-${version}-src/TZDatabaseDirFile
+      echo ${curl.out}/lib/libcurl${stdenv.hostPlatform.extensions.sharedLibrary} > ldc-${version}-src/LibcurlPathFile
+  '';
 
-        # Remove cppa test for now because it doesn't work.
-        rm ldc-${version}-src/tests/d2/dmd-testsuite/runnable/cppa.d
-        rm ldc-${version}-src/tests/d2/dmd-testsuite/runnable/extra-files/cppb.cpp
-    '';
+  postPatch = ''
+      # Setting SHELL=$SHELL when dmd testsuite is run doesn't work on Linux somehow
+      substituteInPlace tests/d2/dmd-testsuite/Makefile --replace "SHELL=/bin/bash" "SHELL=${bash}/bin/bash"
+    ''
 
-    datetimePath = if bootstrapVersion then
-      "phobos/std/datetime.d"
-    else
-      "phobos/std/datetime/timezone.d";
+  + stdenv.lib.optionalString (!bootstrapVersion && stdenv.hostPlatform.isLinux) ''
+      substituteInPlace runtime/phobos/std/socket.d --replace "assert(ih.addrList[0] == 0x7F_00_00_01);" ""
+  ''
 
-    postPatch = ''
-        # https://issues.dlang.org/show_bug.cgi?id=15391
-        substituteInPlace runtime/phobos/std/net/curl.d \
-            --replace libcurl.so ${curl.out}/lib/libcurl.so
+  + stdenv.lib.optionalString (!bootstrapVersion && stdenv.hostPlatform.isDarwin) ''
+      substituteInPlace runtime/phobos/std/socket.d --replace "foreach (name; names)" "names = []; foreach (name; names)"
+  ''
 
-        substituteInPlace tests/d2/dmd-testsuite/Makefile \
-            --replace "SHELL=/bin/bash" "SHELL=${bash}/bin/bash"
-    ''
+  + stdenv.lib.optionalString (bootstrapVersion && stdenv.hostPlatform.isDarwin) ''
+      # Was not able to compile on darwin due to "__inline_isnanl"
+      # being undefined.
+      # TODO Remove with version > 0.17.6
+      substituteInPlace dmd2/root/port.c --replace __inline_isnanl __inline_isnan
+  '';
 
-    + stdenv.lib.optionalString (bootstrapVersion && stdenv.hostPlatform.isDarwin) ''
-        # Was not able to compile on darwin due to "__inline_isnanl"
-        # being undefined.
-        substituteInPlace dmd2/root/port.c --replace __inline_isnanl __inline_isnan
-    '';
-
-    nativeBuildInputs = [ cmake makeWrapper llvm bootstrapLdc python lit gdb unzip ]
-
-    ++ stdenv.lib.optional (bootstrapVersion) [
-      libconfig
-    ]
-
-    ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [
-      Foundation
-    ]);
-
-
-    buildInputs = [ curl tzdata ];
-
-    #"-DINCLUDE_INSTALL_DIR=$out/include/dlang/ldc"
-    # Xcode 9.0.1 fixes that bug according to ldc release notes
-    #"-DRT_ARCHIVE_WITH_LDC=OFF"
-      #"-DD_FLAGS=TZ_DATABASE_DIR=${tzdata}/share/zoneinfo/"
-      #"-DCMAKE_BUILD_TYPE=Release"
-      #"-DCMAKE_SKIP_RPATH=ON"
-
-      #-DINCLUDE_INSTALL_DIR=$out/include/dlang/ldc
-      #
-    cmakeFlagsString = stdenv.lib.optionalString (!bootstrapVersion) ''
-      "-DD_FLAGS=-d-version=TZDatabaseDir;-J$PWD"
-    '';
-
-    preConfigure = stdenv.lib.optionalString (!bootstrapVersion) ''
-      cmakeFlagsArray=(
-        ${cmakeFlagsString}
-      )
-    '';
-
-    postConfigure = ''
-      export DMD=$PWD/bin/ldmd2
-    '';
-
-    makeFlags = [ "DMD=$DMD" ];
-
-    doCheck = !bootstrapVersion;
-
-    checkPhase = ''
-      # 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"
-    '';
-
-    postInstall = ''
-      wrapProgram $out/bin/ldc2 \
-          --prefix PATH ":" "${targetPackages.stdenv.cc}/bin" \
-          --set-default CC "${targetPackages.stdenv.cc}/bin/cc"
-     '';
-
-    meta = with stdenv.lib; {
-      description = "The LLVM-based D compiler";
-      homepage = https://github.com/ldc-developers/ldc;
-      # from https://github.com/ldc-developers/ldc/blob/master/LICENSE
-      license = with licenses; [ bsd3 boost mit ncsa gpl2Plus ];
-      maintainers = with maintainers; [ ThomasMader ];
-      platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" ];
-    };
-  };
+  nativeBuildInputs = [ cmake makeWrapper llvm unzip ]
 
-  # Need to test Phobos in a fixed-output derivation, otherwise the
-  # network stuff in Phobos would fail if sandbox mode is enabled.
-  #
-  # Disable tests on Darwin for now because of
-  # https://github.com/NixOS/nixpkgs/issues/41099
-  # https://github.com/NixOS/nixpkgs/pull/36378#issuecomment-385034818
-  ldcUnittests = if (!bootstrapVersion && !stdenv.hostPlatform.isDarwin) then
-    stdenv.mkDerivation rec {
-      name = "ldcUnittests-${version}";
+  ++ stdenv.lib.optional (!bootstrapVersion) [
+    bootstrapLdc python lit
+  ]
 
-      enableParallelBuilding = ldcBuild.enableParallelBuilding;
-      preferLocalBuild = true;
-      inputString = ldcBuild.outPath;
-      outputHashAlgo = "sha256";
-      outputHash = builtins.hashString "sha256" inputString;
+  ++ stdenv.lib.optional (!bootstrapVersion && !stdenv.hostPlatform.isDarwin) [
+    # https://github.com/NixOS/nixpkgs/pull/36378#issuecomment-385034818
+    gdb
+  ]
 
-      src = ldcBuild.src;
+  ++ stdenv.lib.optional (bootstrapVersion) [
+    libconfig
+  ]
 
-      postUnpack = ldcBuild.postUnpack;
+  ++ stdenv.lib.optional stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [
+    Foundation
+  ]);
 
-      postPatch = ldcBuild.postPatch;
 
-      nativeBuildInputs = ldcBuild.nativeBuildInputs
+  buildInputs = [ curl tzdata ];
 
-      ++ [
-        ldcBuild
-      ];
+  cmakeFlagsString = stdenv.lib.optionalString (!bootstrapVersion) ''
+    "-DD_FLAGS=-d-version=TZDatabaseDir;-d-version=LibcurlPath;-J$PWD"
+    "-DCMAKE_BUILD_TYPE=Release"
+  '';
 
-      buildInputs = ldcBuild.buildInputs;
+  preConfigure = stdenv.lib.optionalString (!bootstrapVersion) ''
+    cmakeFlagsArray=(
+      ${cmakeFlagsString}
+    )
+  '';
 
-      preConfigure = ''
-        cmakeFlagsArray=(
-          ${ldcBuild.cmakeFlagsString}
-          "-DD_COMPILER=${ldcBuild.out}/bin/ldmd2"
-        )
-      '';
+  postConfigure = ''
+    export DMD=$PWD/bin/ldmd2
+  '';
 
-      postConfigure = ldcBuild.postConfigure;
+  makeFlags = [ "DMD=$DMD" ];
 
-      makeFlags = ldcBuild.makeFlags;
+  fixNames = if stdenv.hostPlatform.isDarwin then ''
+    fixDarwinDylibNames() {
+      local flags=()
 
-      buildCmd = if bootstrapVersion then
-        "ctest -V -R \"build-druntime-ldc-unittest|build-phobos2-ldc-unittest\""
-      else
-        "make -j$NIX_BUILD_CORES DMD=${ldcBuild.out}/bin/ldc2 phobos2-test-runner phobos2-test-runner-debug";
+      for fn in "$@"; do
+        flags+=(-change "$(basename "$fn")" "$fn")
+      done
 
-      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\"";
+      for fn in "$@"; do
+        if [ -L "$fn" ]; then continue; fi
+        echo "$fn: fixing dylib"
+        install_name_tool -id "$fn" "''${flags[@]}" "$fn"
+      done
+    }
 
-      buildPhase = ''
-          ${buildCmd}
-          ln -s ${ldcBuild.out}/bin/ldmd2 $PWD/bin/ldmd2
-          ${testCmd}
-      '';
+    fixDarwinDylibNames $(find "$(pwd)/lib" -name "*.dylib")
+  ''
+  else
+    "";
 
-      installPhase = ''
-          echo -n $inputString > $out
-      '';
-    }
+  # https://github.com/ldc-developers/ldc/issues/2497#issuecomment-459633746
+  additionalExceptions = if stdenv.hostPlatform.isDarwin then
+    "|druntime-test-shared"
   else
     "";
 
-in
+  doCheck = !bootstrapVersion;
 
-stdenv.mkDerivation rec {
-  inherit ldcUnittests;
-  name = "ldc-${version}";
-  phases = "installPhase";
-  buildInputs = ldcBuild.buildInputs;
+  checkPhase = stdenv.lib.optionalString doCheck ''
+    # Build default lib test runners
+    make -j$NIX_BUILD_CORES all-test-runners
+
+    ${fixNames}
+
+    # Run dmd testsuite
+    export DMD_TESTSUITE_MAKE_ARGS="-j$NIX_BUILD_CORES DMD=$DMD CC=$CXX"
+    ctest -V -R "dmd-testsuite"
 
-  installPhase = ''
-    mkdir $out
-    cp -r --symbolic-link ${ldcBuild}/* $out/
+    # Build and run LDC D unittests.
+    ctest --output-on-failure -R "ldc2-unittest"
+
+    # Run LIT testsuite.
+    ctest -V -R "lit-tests"
+
+    # Run default lib unittests
+    ctest -j$NIX_BUILD_CORES --output-on-failure -E "ldc2-unittest|lit-tests|dmd-testsuite${additionalExceptions}"
   '';
 
-  meta = ldcBuild.meta;
+  postInstall = ''
+    wrapProgram $out/bin/ldc2 \
+        --prefix PATH ":" "${targetPackages.stdenv.cc}/bin" \
+        --set-default CC "${targetPackages.stdenv.cc}/bin/cc"
+   '';
+
+  meta = with stdenv.lib; {
+    description = "The LLVM-based D compiler";
+    homepage = https://github.com/ldc-developers/ldc;
+    # from https://github.com/ldc-developers/ldc/blob/master/LICENSE
+    license = with licenses; [ bsd3 boost mit ncsa gpl2Plus ];
+    maintainers = with maintainers; [ ThomasMader ];
+    platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" ];
+  };
 }