about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/swift
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/swift')
-rw-r--r--nixpkgs/pkgs/development/compilers/swift/default.nix294
-rw-r--r--nixpkgs/pkgs/development/compilers/swift/patches/0001-build-presets-linux-don-t-require-using-Ninja.patch25
-rw-r--r--nixpkgs/pkgs/development/compilers/swift/patches/0002-build-presets-linux-allow-custom-install-prefix.patch25
-rw-r--r--nixpkgs/pkgs/development/compilers/swift/patches/0004-build-presets-linux-plumb-extra-cmake-options.patch25
-rw-r--r--nixpkgs/pkgs/development/compilers/swift/patches/build-script-pax.patch33
-rw-r--r--nixpkgs/pkgs/development/compilers/swift/patches/glibc-arch-headers.patch13
-rw-r--r--nixpkgs/pkgs/development/compilers/swift/patches/llvm-include-dirs.patch13
-rw-r--r--nixpkgs/pkgs/development/compilers/swift/purity.patch30
8 files changed, 458 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/compilers/swift/default.nix b/nixpkgs/pkgs/development/compilers/swift/default.nix
new file mode 100644
index 000000000000..bbfa1be8f921
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/swift/default.nix
@@ -0,0 +1,294 @@
+{ stdenv
+, targetPackages
+, cmake
+, coreutils
+, glibc
+, which
+, perl
+, libedit
+, ninja
+, pkgconfig
+, sqlite
+, swig
+, bash
+, libxml2
+, clang
+, python
+, ncurses
+, libuuid
+, libbsd
+, icu
+, autoconf
+, libtool
+, automake
+, libblocksruntime
+, curl
+, rsync
+, git
+, libgit2
+, fetchFromGitHub
+, paxctl
+, findutils
+, makeWrapper
+, gnumake
+, file
+}:
+
+let
+  v_base = "4.2.1";
+  version = "${v_base}-RELEASE";
+  version_friendly = "${v_base}";
+
+  tag = "refs/tags/swift-${version}";
+  fetch = { repo, sha256, fetchSubmodules ? false }:
+    fetchFromGitHub {
+      owner = "apple";
+      inherit repo sha256 fetchSubmodules;
+      rev = tag;
+      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 = "0l6w4xzpl3w2nax9a0b885nfzhfj38p2g99158nb5bzfd4s0man7";
+    };
+    llvm = fetch {
+      repo = "swift-llvm";
+      sha256 = "1664zwxbq0a1cmxr9n5a0vw6vdk6ygr7rpglpdsfc7ki857vpsyv";
+    };
+    compilerrt = fetch {
+      repo = "swift-compiler-rt";
+      sha256 = "19s6qxn4i0kxpf39xjp2i7zg427iinbmaxqkbb1p91g616y367sf";
+    };
+    cmark = fetch {
+      repo = "swift-cmark";
+      sha256 = "1nmxp0fj749sgar682c5nsj7zxxigqwg973baxj2r656a7ybh325";
+    };
+    lldb = fetch {
+      repo = "swift-lldb";
+      sha256 = "00kz0xhj1p6ckyandj2gs1yfl29kxv84x9pfph00r8crbkd2jz7b";
+    };
+    llbuild = fetch {
+      repo = "swift-llbuild";
+      sha256 = "1mkkhydshhxr28igbldzr0hhqvb6ql43cpf3ba5vglfkbcz6wh6q";
+    };
+    pm = fetch {
+      repo = "swift-package-manager";
+      sha256 = "1aqvmgq9g5zs4k2qnkvw3h3mar66d690hqq6g2dmrapsyb321j9l";
+    };
+    xctest = fetch {
+      repo = "swift-corelibs-xctest";
+      sha256 = "1n4w7bfgy73vjzbvbphlwayy0dw73bbrayrpkqq8lbidg0x9lam8";
+    };
+    foundation = fetch {
+      repo = "swift-corelibs-foundation";
+      sha256 = "1bfnkj8s3v327cy0czkngz0ryzmz7amjzkkxbsg2zyrhf9a9f0f7";
+    };
+    libdispatch = fetch {
+      repo = "swift-corelibs-libdispatch";
+      sha256 = "0fibrx54nbaawhsgd7cbr356ji9qvf8y8ahd5bdx28fpj6q0cnwc";
+      fetchSubmodules = true;
+    };
+    swift = fetch {
+      repo = "swift";
+      sha256 = "0y277wi0m6zp1yph9s14mmc65m21q5fm6lgzkn2rkrbaz25fdzak";
+    };
+  };
+
+  devInputs = [
+    curl
+    glibc
+    icu
+    libblocksruntime
+    libbsd
+    libedit
+    libuuid
+    libxml2
+    ncurses
+    sqlite
+    swig
+  ];
+
+  cmakeFlags = [
+    "-DGLIBC_INCLUDE_PATH=${stdenv.cc.libc.dev}/include"
+    "-DC_INCLUDE_DIRS=${stdenv.lib.makeSearchPathOutput "dev" "include" devInputs}:${libxml2.dev}/include/libxml2"
+    "-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"
+
+    $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 rec {
+  name = "swift-${version_friendly}";
+
+  buildInputs = devInputs ++ [
+    autoconf
+    automake
+    bash
+    clang
+    cmake
+    coreutils
+    libtool
+    ninja
+    perl
+    pkgconfig
+    python
+    rsync
+    which
+    findutils
+    makeWrapper
+    gnumake
+  ] ++ stdenv.lib.optional stdenv.needsPax paxctl;
+
+  # TODO: Revisit what's propagated and how
+  propagatedBuildInputs = [
+    libgit2
+    python
+  ];
+  propagatedUserEnvPkgs = [ git pkgconfig ];
+
+  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.cmark} cmark
+    cp -r ${sources.lldb} lldb
+    cp -r ${sources.llbuild} llbuild
+    cp -r ${sources.pm} swiftpm
+    cp -r ${sources.xctest} swift-corelibs-xctest
+    cp -r ${sources.foundation} swift-corelibs-foundation
+    cp -r ${sources.libdispatch} swift-corelibs-libdispatch
+    cp -r ${sources.swift} swift
+
+    chmod -R u+w .
+  '';
+
+  patchPhase = ''
+    # Just patch all the things for now, we can focus this later
+    patchShebangs $SWIFT_SOURCE_ROOT
+
+    # TODO eliminate use of env.
+    find -type f -print0 | xargs -0 sed -i \
+      -e 's|/usr/bin/env|${coreutils}/bin/env|g' \
+      -e 's|/usr/bin/make|${gnumake}/bin/make|g' \
+      -e 's|/bin/mkdir|${coreutils}/bin/mkdir|g' \
+      -e 's|/bin/cp|${coreutils}/bin/cp|g' \
+      -e 's|/usr/bin/file|${file}/bin/file|g'
+
+    substituteInPlace swift/stdlib/public/Platform/CMakeLists.txt \
+      --replace '/usr/include' "${stdenv.cc.libc.dev}/include"
+    substituteInPlace swift-corelibs-libdispatch/src/CMakeLists.txt \
+      --replace '/usr/include' "${stdenv.cc.libc.dev}/include"
+    substituteInPlace swift/utils/build-script-impl \
+      --replace '/usr/include/c++' "${clang.cc.gcc}/include/c++"
+    patch -p1 -d swift -i ${./patches/glibc-arch-headers.patch}
+  '' + stdenv.lib.optionalString stdenv.needsPax ''
+    patch -p1 -d swift -i ${./patches/build-script-pax.patch}
+  '' + ''
+    patch -p1 -d swift -i ${./patches/0001-build-presets-linux-don-t-require-using-Ninja.patch}
+    patch -p1 -d swift -i ${./patches/0002-build-presets-linux-allow-custom-install-prefix.patch}
+    patch -p1 -d swift -i ${./patches/0004-build-presets-linux-plumb-extra-cmake-options.patch}
+
+    sed -i swift/utils/build-presets.ini \
+      -e 's/^test-installable-package$/# \0/' \
+      -e 's/^test$/# \0/' \
+      -e 's/^validation-test$/# \0/' \
+      -e 's/^long-test$/# \0/' \
+      -e 's/^stress-test$/# \0/' \
+      -e 's/^test-optimized$/# \0/'
+
+    # https://bugs.swift.org/browse/SR-5779
+    sed -i -e 's|"-latomic"|"-Wl,-rpath,${clang.cc.gcc.lib}/lib" "-L${clang.cc.gcc.lib}/lib" "-latomic"|' swift/cmake/modules/AddSwift.cmake
+
+    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 ${./purity.patch}
+
+    # Workaround hardcoded dep on "libcurses" (vs "libncurses"):
+    sed -i 's,curses,ncurses,' llbuild/*/*/CMakeLists.txt
+
+    PREFIX=''${out/#\/}
+    substituteInPlace swift-corelibs-foundation/build.py \
+      --replace usr/lib "$PREFIX/lib"
+    substituteInPlace swift-corelibs-xctest/build_script.py \
+      --replace usr "$PREFIX"
+    substituteInPlace swiftpm/Utilities/bootstrap \
+      --replace \"usr\" \"$PREFIX\" \
+      --replace usr/lib "$PREFIX/lib"
+  '';
+
+  doCheck = false;
+
+  buildPhase = builder;
+
+  installPhase = ''
+    mkdir -p $out
+
+    # Extract the generated tarball into the store
+    PREFIX=''${out/#\/}
+    tar xf $INSTALLABLE_PACKAGE -C $out --strip-components=3 $PREFIX
+    find $out -type d -empty -delete
+
+    paxmark pmr $out/bin/swift
+    paxmark pmr $out/bin/*
+
+    # TODO: Use wrappers to get these on the PATH for swift tools, instead
+    ln -s ${clang}/bin/* $out/bin/
+    ln -s ${targetPackages.stdenv.cc.bintools.bintools_bin}/bin/ar $out/bin/ar
+
+    wrapProgram $out/bin/swift \
+      --suffix C_INCLUDE_PATH : $out/lib/swift/clang/include \
+      --suffix CPLUS_INCLUDE_PATH : $out/lib/swift/clang/include
+  '';
+
+  # Hack to avoid TMPDIR in RPATHs.
+  preFixup = ''rm -rf "$(pwd)" '';
+
+  meta = with stdenv.lib; {
+    description = "The Swift Programming Language";
+    homepage = https://github.com/apple/swift;
+    maintainers = with maintainers; [ dtzWill ];
+    license = licenses.asl20;
+    # Swift doesn't support 32bit Linux, unknown on other platforms.
+    platforms = platforms.linux;
+    badPlatforms = platforms.i686;
+    broken = stdenv.isAarch64; # 2018-09-04, never built on Hydra
+  };
+}
diff --git a/nixpkgs/pkgs/development/compilers/swift/patches/0001-build-presets-linux-don-t-require-using-Ninja.patch b/nixpkgs/pkgs/development/compilers/swift/patches/0001-build-presets-linux-don-t-require-using-Ninja.patch
new file mode 100644
index 000000000000..f2b30e5dcdb6
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/swift/patches/0001-build-presets-linux-don-t-require-using-Ninja.patch
@@ -0,0 +1,25 @@
+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
+
+---
+ 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
+@@ -717,7 +717,7 @@ swiftpm
+ xctest
+ dash-dash
+ 
+-build-ninja
++# build-ninja
+ install-swift
+ install-lldb
+ install-llbuild
+-- 
+2.12.2
+
diff --git a/nixpkgs/pkgs/development/compilers/swift/patches/0002-build-presets-linux-allow-custom-install-prefix.patch b/nixpkgs/pkgs/development/compilers/swift/patches/0002-build-presets-linux-allow-custom-install-prefix.patch
new file mode 100644
index 000000000000..612b33cdb483
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/swift/patches/0002-build-presets-linux-allow-custom-install-prefix.patch
@@ -0,0 +1,25 @@
+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
+
+---
+ 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
++++ b/utils/build-presets.ini
+@@ -723,7 +723,7 @@ install-lldb
+ install-llbuild
+ install-swiftpm
+ install-xctest
+-install-prefix=/usr
++install-prefix=%(install_prefix)s
+ swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;license;sourcekit-inproc
+ build-swift-static-stdlib
+ build-swift-static-sdk-overlay
+-- 
+2.12.2
+
diff --git a/nixpkgs/pkgs/development/compilers/swift/patches/0004-build-presets-linux-plumb-extra-cmake-options.patch b/nixpkgs/pkgs/development/compilers/swift/patches/0004-build-presets-linux-plumb-extra-cmake-options.patch
new file mode 100644
index 000000000000..e84c7eb2a08a
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/swift/patches/0004-build-presets-linux-plumb-extra-cmake-options.patch
@@ -0,0 +1,25 @@
+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
+
+---
+ 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
+@@ -740,6 +740,8 @@ install-destdir=%(install_destdir)s
+ # Path to the .tar.gz package we would create.
+ installable-package=%(installable_package)s
+ 
++extra-cmake-options=%(extra_cmake_options)s
++
+ [preset: buildbot_linux]
+ mixin-preset=mixin_linux_installation
+ build-subdir=buildbot_linux
+-- 
+2.12.2
+
diff --git a/nixpkgs/pkgs/development/compilers/swift/patches/build-script-pax.patch b/nixpkgs/pkgs/development/compilers/swift/patches/build-script-pax.patch
new file mode 100644
index 000000000000..1f47bf8ee045
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/swift/patches/build-script-pax.patch
@@ -0,0 +1,33 @@
+--- swift/utils/build-script-impl	2017-01-23 12:47:20.401326309 -0600
++++ swift-pax/utils/build-script-impl	2017-01-23 13:24:10.339366996 -0600
+@@ -1837,6 +1837,17 @@ function set_lldb_xcodebuild_options() {
+     fi
+ }
+ 
++## XXX: Taken from nixpkgs /pkgs/stdenv/generic/setup.sh
++isELF() {
++    local fn="$1"
++    local fd
++    local magic
++    exec {fd}< "$fn"
++    read -n 4 -u $fd magic
++    exec {fd}<&-
++    if [[ "$magic" =~ ELF ]]; then return 0; else return 1; fi
++}
++
+ #
+ # Configure and build each product
+ #
+@@ -2735,6 +2746,12 @@ for host in "${ALL_HOSTS[@]}"; do
+             fi
+ 
+             call "${CMAKE_BUILD[@]}" "${build_dir}" $(cmake_config_opt ${product}) -- "${BUILD_ARGS[@]}" ${build_targets[@]}
++            
++						while IFS= read -r -d $'\0' i; do
++								if ! isELF "$i"; then continue; fi
++								echo "setting pax flags on $i"
++								paxctl -czexm "$i" || true
++						done < <(find "${build_dir}" -executable -type f -wholename "*/bin/*" -print0)
+         fi
+     done
+ done
diff --git a/nixpkgs/pkgs/development/compilers/swift/patches/glibc-arch-headers.patch b/nixpkgs/pkgs/development/compilers/swift/patches/glibc-arch-headers.patch
new file mode 100644
index 000000000000..650e1a2429d4
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/swift/patches/glibc-arch-headers.patch
@@ -0,0 +1,13 @@
+The Nix glibc headers do not use include/x86_64-linux-gnu subdirectories.
+
+--- swift/stdlib/public/Platform/CMakeLists.txt	2018-09-30 17:51:51.581766303 +0200
++++ swift/stdlib/public/Platform/CMakeLists.txt	2018-09-30 18:40:04.118956708 +0200
+@@ -65,7 +65,7 @@
+     endif()
+ 
+     set(GLIBC_INCLUDE_PATH "${GLIBC_SYSROOT_RELATIVE_INCLUDE_PATH}")
+-    set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_SYSROOT_RELATIVE_ARCH_INCLUDE_PATH}")
++    set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_SYSROOT_RELATIVE_INCLUDE_PATH}")
+ 
+     if(NOT "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}" STREQUAL "/")
+       set(GLIBC_INCLUDE_PATH "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}${GLIBC_INCLUDE_PATH}")
diff --git a/nixpkgs/pkgs/development/compilers/swift/patches/llvm-include-dirs.patch b/nixpkgs/pkgs/development/compilers/swift/patches/llvm-include-dirs.patch
new file mode 100644
index 000000000000..9523943c4801
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/swift/patches/llvm-include-dirs.patch
@@ -0,0 +1,13 @@
+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
+@@ -565,7 +565,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/nixpkgs/pkgs/development/compilers/swift/purity.patch b/nixpkgs/pkgs/development/compilers/swift/purity.patch
new file mode 100644
index 000000000000..d10e407260a5
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/swift/purity.patch
@@ -0,0 +1,30 @@
+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
+
+---
+ 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
+@@ -398,13 +398,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+   if (!Args.hasArg(options::OPT_static)) {
+     if (Args.hasArg(options::OPT_rdynamic))
+       CmdArgs.push_back("-export-dynamic");
+-
+-    if (!Args.hasArg(options::OPT_shared)) {
+-      const std::string Loader =
+-          D.DyldPrefix + ToolChain.getDynamicLinker(Args);
+-      CmdArgs.push_back("-dynamic-linker");
+-      CmdArgs.push_back(Args.MakeArgString(Loader));
+-    }
+   }
+ 
+   CmdArgs.push_back("-o");
+-- 
+2.11.0
+