summary refs log tree commit diff
path: root/pkgs/development/compilers/swift
diff options
context:
space:
mode:
authorMichael Roitzsch <reactorcontrol@icloud.com>2019-10-21 10:39:03 +0200
committerMichael Roitzsch <reactorcontrol@icloud.com>2020-01-15 13:19:35 +0100
commit29098a81b3720590cde0b0b92bfbf3e66fd9d31b (patch)
tree178eefa2e04f8e2f1c07eec4ffa5f68f03721371 /pkgs/development/compilers/swift
parente4bc7a1c1da34de677b26dc2b39f971a749f182c (diff)
swift: refactor phases and patch documentation
* simplify versioning
* uniform patch documentation
* reorder phases so they read in order
* reorder scripts for readability
* GNU toolchain dir:
  handle sysroot for GNU toolchain like for C headers, so that
  GCC_INSTALL_PREFIX is actually used correctly
Diffstat (limited to 'pkgs/development/compilers/swift')
-rw-r--r--pkgs/development/compilers/swift/default.nix93
-rw-r--r--pkgs/development/compilers/swift/patches/0001-build-presets-linux-don-t-require-using-Ninja.patch14
-rw-r--r--pkgs/development/compilers/swift/patches/0002-build-presets-linux-allow-custom-install-prefix.patch14
-rw-r--r--pkgs/development/compilers/swift/patches/0003-build-presets-linux-don-t-build-extra-libs.patch2
-rw-r--r--pkgs/development/compilers/swift/patches/0004-build-presets-linux-plumb-extra-cmake-options.patch14
-rw-r--r--pkgs/development/compilers/swift/patches/llvm-include-dirs.patch13
-rw-r--r--pkgs/development/compilers/swift/patches/llvm-toolchain-dir.patch24
-rw-r--r--pkgs/development/compilers/swift/purity.patch14
8 files changed, 73 insertions, 115 deletions
diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix
index 817f81f9257b7..a3aa5f89c1c58 100644
--- a/pkgs/development/compilers/swift/default.nix
+++ b/pkgs/development/compilers/swift/default.nix
@@ -33,26 +33,19 @@
 }:
 
 let
-  v_base = "5.0.2";
-  version = "${v_base}-RELEASE";
-  version_friendly = v_base;
+  version = "5.0.2";
 
-  tag = "refs/tags/swift-${version}";
   fetch = { repo, sha256, fetchSubmodules ? false }:
     fetchFromGitHub {
       owner = "apple";
       inherit repo sha256 fetchSubmodules;
-      rev = tag;
+      rev = "swift-${version}-RELEASE";
       name = "${repo}-${version}-src";
     };
 
   sources = {
     # FYI: SourceKit probably would work but currently requires building everything twice
     # For more inforation, see: https://github.com/apple/swift/pull/3594#issuecomment-234169759
-    clang = fetch {
-      repo = "swift-clang";
-      sha256 = "046p7f4044ls8hhgklsz32md5jvxkaaim1d75n0fmnwap6di3n1q";
-    };
     llvm = fetch {
       repo = "swift-llvm";
       sha256 = "1bnscqsiljiclij60f44h2fyx5c84pzry0lz1jbwknphwmqd6f84";
@@ -61,6 +54,10 @@ let
       repo = "swift-compiler-rt";
       sha256 = "0bba54xa7z0wj6k7a24q74gc4yajc6s64g1m894i3yd6swdk7f6r";
     };
+    clang = fetch {
+      repo = "swift-clang";
+      sha256 = "046p7f4044ls8hhgklsz32md5jvxkaaim1d75n0fmnwap6di3n1q";
+    };
     cmark = fetch {
       repo = "swift-cmark";
       sha256 = "079smm79hbwr06bvghd2sb86b8gpkprnzlyj9kh95jy38xhlhdnj";
@@ -116,23 +113,9 @@ let
     "-DGCC_INSTALL_PREFIX=${clang.cc.gcc}"
   ];
 
-  builder = ''
-    # gcc-6.4.0/include/c++/6.4.0/cstdlib:75:15: fatal error: 'stdlib.h' file not found
-    NIX_CFLAGS_COMPILE="$( echo ${clang.default_cxx_stdlib_compile} ) $NIX_CFLAGS_COMPILE"
-    # During the Swift build, a full local LLVM build is performed and the resulting clang is invoked.
-    # This compiler is not using the Nix wrappers, so it needs some help to find things.
-    export NIX_LDFLAGS_BEFORE="-rpath ${clang.cc.gcc.lib}/lib -L${clang.cc.gcc.lib}/lib $NIX_LDFLAGS_BEFORE"
-
-    $SWIFT_SOURCE_ROOT/swift/utils/build-script \
-      --preset=buildbot_linux \
-      installable_package=$INSTALLABLE_PACKAGE \
-      install_prefix=$out \
-      install_destdir=$SWIFT_INSTALL_DIR \
-      extra_cmake_options="${stdenv.lib.concatStringsSep "," cmakeFlags}"'';
-
 in
 stdenv.mkDerivation {
-  name = "swift-${version_friendly}";
+  name = "swift-${version}";
 
   nativeBuildInputs = [
     autoconf
@@ -164,32 +147,14 @@ stdenv.mkDerivation {
 
   hardeningDisable = [ "format" ]; # for LLDB
 
-  configurePhase = ''
-    cd ..
-
-    export INSTALLABLE_PACKAGE=$PWD/swift.tar.gz
-
-    mkdir build install
-    export SWIFT_BUILD_ROOT=$PWD/build
-    export SWIFT_INSTALL_DIR=$PWD/install
-
-    cd $SWIFT_BUILD_ROOT
-
-    unset CC
-    unset CXX
-
-    export NIX_ENFORCE_PURITY=
-  '';
-
   unpackPhase = ''
     mkdir src
     cd src
-    export sourceRoot=$PWD
     export SWIFT_SOURCE_ROOT=$PWD
 
-    cp -r ${sources.clang} clang
     cp -r ${sources.llvm} llvm
     cp -r ${sources.compilerrt} compiler-rt
+    cp -r ${sources.clang} clang
     cp -r ${sources.cmark} cmark
     cp -r ${sources.lldb} lldb
     cp -r ${sources.llbuild} llbuild
@@ -239,18 +204,47 @@ stdenv.mkDerivation {
 
     substituteInPlace clang/lib/Driver/ToolChains/Linux.cpp \
       --replace 'SysRoot + "/usr/lib' '"${glibc}/lib" "'
-    patch -p1 -d clang -i ${./patches/llvm-include-dirs.patch}
+    patch -p1 -d clang -i ${./patches/llvm-toolchain-dir.patch}
     patch -p1 -d clang -i ${./purity.patch}
 
     # Workaround hardcoded dep on "libcurses" (vs "libncurses"):
-    sed -i 's,curses,ncurses,' llbuild/*/*/CMakeLists.txt
+    sed -i 's/curses/ncurses/' llbuild/*/*/CMakeLists.txt
 
     PREFIX=''${out/#\/}
     substituteInPlace swift-corelibs-xctest/build_script.py \
       --replace usr "$PREFIX"
   '';
 
-  buildPhase = builder;
+  configurePhase = ''
+    cd ..
+
+    mkdir build install
+    export SWIFT_BUILD_ROOT=$PWD/build
+    export SWIFT_INSTALL_DIR=$PWD/install
+
+    unset CC
+    unset CXX
+
+    export INSTALLABLE_PACKAGE=$PWD/swift.tar.gz
+    export NIX_ENFORCE_PURITY=
+
+    cd $SWIFT_BUILD_ROOT
+  '';
+
+  buildPhase = ''
+    # gcc-6.4.0/include/c++/6.4.0/cstdlib:75:15: fatal error: 'stdlib.h' file not found
+    export NIX_CFLAGS_COMPILE="$( echo ${clang.default_cxx_stdlib_compile} ) $NIX_CFLAGS_COMPILE"
+    # During the Swift build, a full local LLVM build is performed and the resulting clang is invoked.
+    # This compiler is not using the Nix wrappers, so it needs some help to find things.
+    export NIX_LDFLAGS_BEFORE="-rpath ${clang.cc.gcc.lib}/lib -L${clang.cc.gcc.lib}/lib $NIX_LDFLAGS_BEFORE"
+
+    $SWIFT_SOURCE_ROOT/swift/utils/build-script \
+      --preset=buildbot_linux \
+      installable_package=$INSTALLABLE_PACKAGE \
+      install_prefix=$out \
+      install_destdir=$SWIFT_INSTALL_DIR \
+      extra_cmake_options="${stdenv.lib.concatStringsSep "," cmakeFlags}"
+  '';
 
   doCheck = false;
 
@@ -268,8 +262,7 @@ stdenv.mkDerivation {
     mkdir -p $out
 
     # Extract the generated tarball into the store
-    PREFIX=''${out/#\/}
-    tar xf $INSTALLABLE_PACKAGE -C $out --strip-components=3 $PREFIX
+    tar xf $INSTALLABLE_PACKAGE -C $out --strip-components=3 ''${out/#\/}
     find $out -type d -empty -delete
 
     wrapProgram $out/bin/swift \
@@ -278,8 +271,8 @@ stdenv.mkDerivation {
       --suffix LIBRARY_PATH : $icu/lib
   '';
 
-  # Hack to avoid TMPDIR in RPATHs.
-  preFixup = ''rm -rf "$(pwd)" '';
+  # Hack to avoid build and install directories in RPATHs.
+  preFixup = ''rm -rf $SWIFT_BUILD_ROOT $SWIFT_INSTALL_DIR'';
 
   meta = with stdenv.lib; {
     description = "The Swift Programming Language";
diff --git a/pkgs/development/compilers/swift/patches/0001-build-presets-linux-don-t-require-using-Ninja.patch b/pkgs/development/compilers/swift/patches/0001-build-presets-linux-don-t-require-using-Ninja.patch
index 79482ac10e693..70b7b0ff73be2 100644
--- a/pkgs/development/compilers/swift/patches/0001-build-presets-linux-don-t-require-using-Ninja.patch
+++ b/pkgs/development/compilers/swift/patches/0001-build-presets-linux-don-t-require-using-Ninja.patch
@@ -1,14 +1,5 @@
-From 1fc49285c7a198de14005803dfde64bda17f4120 Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Tue, 28 Mar 2017 15:01:16 -0500
-Subject: [PATCH 1/4] build-presets: (linux) don't require using Ninja
+Don't build Ninja, we use our own.
 
----
- utils/build-presets.ini | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/utils/build-presets.ini b/utils/build-presets.ini
-index 7ee57ad2df..e6b0af3581 100644
 --- a/utils/build-presets.ini
 +++ b/utils/build-presets.ini
 @@ -721,7 +721,7 @@ swiftpm
@@ -20,6 +11,3 @@ index 7ee57ad2df..e6b0af3581 100644
  install-swift
  install-lldb
  install-llbuild
--- 
-2.12.2
-
diff --git a/pkgs/development/compilers/swift/patches/0002-build-presets-linux-allow-custom-install-prefix.patch b/pkgs/development/compilers/swift/patches/0002-build-presets-linux-allow-custom-install-prefix.patch
index 5c1927acb7f1e..9122cf01cc8fb 100644
--- a/pkgs/development/compilers/swift/patches/0002-build-presets-linux-allow-custom-install-prefix.patch
+++ b/pkgs/development/compilers/swift/patches/0002-build-presets-linux-allow-custom-install-prefix.patch
@@ -1,14 +1,5 @@
-From fca6624b7a0ad670157105336a737cc95f9ce9fb Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Tue, 28 Mar 2017 15:01:40 -0500
-Subject: [PATCH 2/4] build-presets: (linux) allow custom install prefix
+allow custom install prefix
 
----
- utils/build-presets.ini | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/utils/build-presets.ini b/utils/build-presets.ini
-index e6b0af3581..1095cbaab7 100644
 --- a/utils/build-presets.ini	2019-04-11 14:51:40.060259462 +0200
 +++ b/utils/build-presets.ini	2019-04-11 15:16:17.471137969 +0200
 @@ -728,7 +728,7 @@
@@ -20,6 +11,3 @@ index e6b0af3581..1095cbaab7 100644
  swift-install-components=autolink-driver;compiler;clang-resource-dir-symlink;stdlib;swift-remote-mirror;sdk-overlay;license;sourcekit-inproc
  llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-headers;compiler-rt
  install-libcxx
--- 
-2.12.2
-
diff --git a/pkgs/development/compilers/swift/patches/0003-build-presets-linux-don-t-build-extra-libs.patch b/pkgs/development/compilers/swift/patches/0003-build-presets-linux-don-t-build-extra-libs.patch
index 5d766bc25901d..d749a430a32dd 100644
--- a/pkgs/development/compilers/swift/patches/0003-build-presets-linux-don-t-build-extra-libs.patch
+++ b/pkgs/development/compilers/swift/patches/0003-build-presets-linux-don-t-build-extra-libs.patch
@@ -1,3 +1,5 @@
+Disable targets, where we use Nix packages.
+
 --- a/utils/build-presets.ini	2019-04-11 15:19:57.845178834 +0200
 +++ b/utils/build-presets.ini	2019-04-11 15:27:42.041297057 +0200
 @@ -716,8 +716,6 @@
diff --git a/pkgs/development/compilers/swift/patches/0004-build-presets-linux-plumb-extra-cmake-options.patch b/pkgs/development/compilers/swift/patches/0004-build-presets-linux-plumb-extra-cmake-options.patch
index 1d0a6a9577aad..9710f6a108371 100644
--- a/pkgs/development/compilers/swift/patches/0004-build-presets-linux-plumb-extra-cmake-options.patch
+++ b/pkgs/development/compilers/swift/patches/0004-build-presets-linux-plumb-extra-cmake-options.patch
@@ -1,14 +1,5 @@
-From 4a46b12f580d0a9779937d07c4f1fd347570c4ef Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Tue, 28 Mar 2017 15:02:37 -0500
-Subject: [PATCH 4/4] build-presets: (linux) plumb extra-cmake-options
+plumb extra-cmake-options
 
----
- utils/build-presets.ini | 2 ++
- 1 file changed, 2 insertions(+)
-
-diff --git a/utils/build-presets.ini b/utils/build-presets.ini
-index 1739e91dc2..0608fed9c1 100644
 --- a/utils/build-presets.ini
 +++ b/utils/build-presets.ini
 @@ -743,6 +743,8 @@ install-destdir=%(install_destdir)s
@@ -20,6 +11,3 @@ index 1739e91dc2..0608fed9c1 100644
  [preset: buildbot_linux]
  mixin-preset=mixin_linux_installation
  build-subdir=buildbot_linux
--- 
-2.12.2
-
diff --git a/pkgs/development/compilers/swift/patches/llvm-include-dirs.patch b/pkgs/development/compilers/swift/patches/llvm-include-dirs.patch
deleted file mode 100644
index 789c0be7e7a8b..0000000000000
--- a/pkgs/development/compilers/swift/patches/llvm-include-dirs.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-Only use the Nix include dirs when no sysroot is configured.
-
---- clang/lib/Driver/ToolChains/Linux.cpp	2018-10-05 18:01:15.731109551 +0200
-+++ clang/lib/Driver/ToolChains/Linux.cpp	2018-10-05 18:00:27.959509924 +0200
-@@ -641,7 +641,7 @@
- 
-   // Check for configure-time C include directories.
-   StringRef CIncludeDirs(C_INCLUDE_DIRS);
--  if (CIncludeDirs != "") {
-+  if (CIncludeDirs != "" && (SysRoot.empty() || SysRoot == "/")) {
-     SmallVector<StringRef, 5> dirs;
-     CIncludeDirs.split(dirs, ":");
-     for (StringRef dir : dirs) {
diff --git a/pkgs/development/compilers/swift/patches/llvm-toolchain-dir.patch b/pkgs/development/compilers/swift/patches/llvm-toolchain-dir.patch
new file mode 100644
index 0000000000000..c22b5c820c852
--- /dev/null
+++ b/pkgs/development/compilers/swift/patches/llvm-toolchain-dir.patch
@@ -0,0 +1,24 @@
+Use the Nix include dirs and gcc runtime dir, when no sysroot is configured.
+
+--- clang/lib/Driver/ToolChains/Linux.cpp	2018-10-05 18:01:15.731109551 +0200
++++ clang/lib/Driver/ToolChains/Linux.cpp	2018-10-05 18:00:27.959509924 +0200
+@@ -665,7 +665,7 @@
+ 
+   // Check for configure-time C include directories.
+   StringRef CIncludeDirs(C_INCLUDE_DIRS);
+-  if (CIncludeDirs != "") {
++  if (CIncludeDirs != "" && (SysRoot.empty() || SysRoot == "/")) {
+     SmallVector<StringRef, 5> dirs;
+     CIncludeDirs.split(dirs, ":");
+     for (StringRef dir : dirs) {
+--- clang/lib/Driver/ToolChains/Gnu.cpp	2019-10-26 09:49:27.003752743 +0200
++++ clang/lib/Driver/ToolChains/Gnu.cpp	2019-10-26 09:50:49.067236497 +0200
+@@ -1743,7 +1743,7 @@
+   // If we have a SysRoot, ignore GCC_INSTALL_PREFIX.
+   // GCC_INSTALL_PREFIX specifies the gcc installation for the default
+   // sysroot and is likely not valid with a different sysroot.
+-  if (!SysRoot.empty())
++  if (!(SysRoot.empty() || SysRoot == "/"))
+     return "";
+ 
+   return GCC_INSTALL_PREFIX;
diff --git a/pkgs/development/compilers/swift/purity.patch b/pkgs/development/compilers/swift/purity.patch
index 832decdc41f57..a358c2acb6617 100644
--- a/pkgs/development/compilers/swift/purity.patch
+++ b/pkgs/development/compilers/swift/purity.patch
@@ -1,14 +1,5 @@
-From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Thu, 18 May 2017 11:56:12 -0500
-Subject: [PATCH] "purity" patch for 5.0
+"purity" patch for 5.0
 
----
- lib/Driver/ToolChains/Gnu.cpp | 7 -------
- 1 file changed, 7 deletions(-)
-
-diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
-index fe3c0191bb..c6a482bece 100644
 --- a/lib/Driver/ToolChains/Gnu.cpp
 +++ b/lib/Driver/ToolChains/Gnu.cpp
 @@ -380,13 +380,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
@@ -25,6 +16,3 @@ index fe3c0191bb..c6a482bece 100644
    }
  
    CmdArgs.push_back("-o");
--- 
-2.11.0
-