2017-01-24 14:23:15 +00:00
|
|
|
{ stdenv
|
2017-10-18 19:05:39 +01:00
|
|
|
, targetPackages
|
2017-01-24 14:23:15 +00:00
|
|
|
, 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
|
2018-02-04 05:38:20 +00:00
|
|
|
, fetchpatch
|
2017-01-24 14:23:15 +00:00
|
|
|
, paxctl
|
|
|
|
, findutils
|
2018-02-04 05:38:20 +00:00
|
|
|
, makeWrapper
|
2018-02-12 06:31:47 +00:00
|
|
|
, gnumake
|
|
|
|
, file
|
2017-01-24 14:23:15 +00:00
|
|
|
#, systemtap
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2018-02-12 06:31:47 +00:00
|
|
|
v_major = "4.0.3";
|
2017-01-24 14:23:15 +00:00
|
|
|
version = "${v_major}-RELEASE";
|
|
|
|
version_friendly = "${v_major}";
|
|
|
|
|
|
|
|
tag = "refs/tags/swift-${version}";
|
|
|
|
fetch = { repo, sha256, fetchSubmodules ? false }:
|
|
|
|
fetchFromGitHub {
|
|
|
|
owner = "apple";
|
|
|
|
inherit repo sha256 fetchSubmodules;
|
|
|
|
rev = tag;
|
|
|
|
name = "${repo}-${version}-src";
|
|
|
|
};
|
|
|
|
|
2018-02-04 05:38:20 +00:00
|
|
|
sources = {
|
2017-01-24 14:23:15 +00:00
|
|
|
# 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";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "0zm624iwiprk3c3nzqf4p1fd9zqic4yi3jv51cw3249ax4x6vy10";
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
llvm = fetch {
|
|
|
|
repo = "swift-llvm";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "11vw6461c0cdvwm1wna1a5709fjj14hzp6br6jg94p4f6jp3yv4d";
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
compilerrt = fetch {
|
|
|
|
repo = "swift-compiler-rt";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "1hj4qaj4c9n2wzg2cvarbyl0n708zd1dlw4zkzq07fjxxqs36nfa";
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
cmark = fetch {
|
|
|
|
repo = "swift-cmark";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "1nmxp0fj749sgar682c5nsj7zxxigqwg973baxj2r656a7ybh325";
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
lldb = fetch {
|
|
|
|
repo = "swift-lldb";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "0yk5qg85008vcn63vn2jpn5ls9pdhda222p2w1cfkrj27k5k8vqr";
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
llbuild = fetch {
|
|
|
|
repo = "swift-llbuild";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "0jffw6z1s6ck1i05brw59x6vsg7zrxbz5n2wz72fj29rh3nppc7a";
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
pm = fetch {
|
|
|
|
repo = "swift-package-manager";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "0xj070b8fii7ijfsnyq4fxgv6569vdrg0yippi85h2p1l7s9aagh";
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
xctest = fetch {
|
|
|
|
repo = "swift-corelibs-xctest";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "0l355wq8zfwrpv044xf4smjwbm0bmib360748n8cwls3vkr9l2yv";
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
foundation = fetch {
|
|
|
|
repo = "swift-corelibs-foundation";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "0s7yc5gsbd96a4bs8c6q24dyfjm4xhcr2nzhl2ics8dmi60j15s4";
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
libdispatch = fetch {
|
|
|
|
repo = "swift-corelibs-libdispatch";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "0x8zzq3shhvmhq4sbhaaa0ddiv3nw347pz6ayym6jyzq7j9n15ia";
|
2017-01-24 14:23:15 +00:00
|
|
|
fetchSubmodules = true;
|
|
|
|
};
|
|
|
|
swift = fetch {
|
|
|
|
repo = "swift";
|
2018-02-12 06:31:47 +00:00
|
|
|
sha256 = "0a1gq0k5701i418f0qi7kywv16q7vh4a4wp0f6fpyv4sjkq27msx";
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
devInputs = [
|
|
|
|
curl
|
|
|
|
glibc
|
|
|
|
icu
|
|
|
|
libblocksruntime
|
|
|
|
libbsd
|
|
|
|
libedit
|
|
|
|
libuuid
|
|
|
|
libxml2
|
|
|
|
ncurses
|
|
|
|
sqlite
|
|
|
|
swig
|
|
|
|
# systemtap?
|
|
|
|
];
|
|
|
|
|
|
|
|
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 = ''
|
2018-02-12 06:31:47 +00:00
|
|
|
# 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"
|
2018-02-04 05:38:20 +00:00
|
|
|
|
2017-01-24 14:23:15 +00:00
|
|
|
$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}"'';
|
|
|
|
|
2018-02-04 05:38:20 +00:00
|
|
|
# from llvm/4/llvm.nix
|
|
|
|
sigaltstackPatch = fetchpatch {
|
|
|
|
name = "sigaltstack.patch"; # for glibc-2.26
|
|
|
|
url = https://github.com/llvm-mirror/compiler-rt/commit/8a5e425a68d.diff;
|
|
|
|
sha256 = "0h4y5vl74qaa7dl54b1fcyqalvlpd8zban2d1jxfkxpzyi7m8ifi";
|
|
|
|
};
|
|
|
|
|
|
|
|
# https://bugs.swift.org/browse/SR-6409
|
|
|
|
sigunusedPatch = fetchpatch {
|
|
|
|
name = "sigunused.patch";
|
|
|
|
url = "https://github.com/apple/swift-llbuild/commit/303a89bc6da606c115560921a452686aa0655f5e.diff";
|
|
|
|
sha256 = "04sw7ym1grzggj1v3xrzr2ljxz8rf9rnn9n5fg1xjbwlrdagkc7m";
|
|
|
|
};
|
2017-01-24 14:23:15 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
name = "swift-${version_friendly}";
|
|
|
|
|
|
|
|
buildInputs = devInputs ++ [
|
|
|
|
autoconf
|
|
|
|
automake
|
|
|
|
bash
|
|
|
|
clang
|
|
|
|
cmake
|
|
|
|
coreutils
|
|
|
|
libtool
|
|
|
|
ninja
|
|
|
|
perl
|
|
|
|
pkgconfig
|
|
|
|
python
|
|
|
|
rsync
|
|
|
|
which
|
|
|
|
findutils
|
2018-02-04 05:38:20 +00:00
|
|
|
makeWrapper
|
2018-02-12 06:31:47 +00:00
|
|
|
gnumake
|
2017-01-24 14:23:15 +00:00
|
|
|
] ++ 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
|
|
|
|
|
2018-02-12 06:31:47 +00:00
|
|
|
# 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'
|
|
|
|
|
2017-01-24 14:23:15 +00:00
|
|
|
substituteInPlace swift/stdlib/public/Platform/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++"
|
|
|
|
'' + 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/0003-build-presets-linux-disable-tests.patch}
|
|
|
|
patch -p1 -d swift -i ${./patches/0004-build-presets-linux-plumb-extra-cmake-options.patch}
|
2018-02-04 05:38:20 +00:00
|
|
|
# https://sourceware.org/glibc/wiki/Release/2.26#Removal_of_.27xlocale.h.27
|
|
|
|
patch -p1 -i ${./patches/remove_xlocale.patch}
|
|
|
|
# https://bugs.swift.org/browse/SR-4633
|
|
|
|
patch -p1 -d swift -i ${./patches/icu59.patch}
|
2017-01-24 14:23:15 +00:00
|
|
|
|
2018-02-12 06:31:47 +00:00
|
|
|
# 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
|
|
|
|
|
2018-02-27 01:49:51 +00:00
|
|
|
# https://bugs.swift.org/browse/SR-4838
|
|
|
|
sed -i -e '30i#include <functional>' lldb/include/lldb/Utility/TaskPool.h
|
|
|
|
|
2017-01-24 14:23:15 +00:00
|
|
|
substituteInPlace clang/lib/Driver/ToolChains.cpp \
|
|
|
|
--replace ' addPathIfExists(D, SysRoot + "/usr/lib", Paths);' \
|
|
|
|
' addPathIfExists(D, SysRoot + "/usr/lib", Paths); addPathIfExists(D, "${glibc}/lib", Paths);'
|
|
|
|
patch -p1 -d clang -i ${./purity.patch}
|
|
|
|
|
|
|
|
# Workaround hardcoded dep on "libcurses" (vs "libncurses"):
|
|
|
|
sed -i 's,curses,ncurses,' llbuild/*/*/CMakeLists.txt
|
|
|
|
|
|
|
|
# This test fails on one of my machines, not sure why.
|
|
|
|
# Disabling for now.
|
|
|
|
rm llbuild/tests/Examples/buildsystem-capi.llbuild
|
|
|
|
|
|
|
|
PREFIX=''${out/#\/}
|
|
|
|
substituteInPlace swift-corelibs-xctest/build_script.py \
|
|
|
|
--replace usr "$PREFIX"
|
|
|
|
substituteInPlace swiftpm/Utilities/bootstrap \
|
|
|
|
--replace "usr" "$PREFIX"
|
2018-02-04 05:38:20 +00:00
|
|
|
'' + stdenv.lib.optionalString (stdenv ? glibc) ''
|
|
|
|
patch -p1 -d compiler-rt -i ${sigaltstackPatch}
|
|
|
|
patch -p1 -d compiler-rt -i ${./patches/sigaltstack.patch}
|
|
|
|
patch -p1 -d llbuild -i ${sigunusedPatch}
|
|
|
|
patch -p1 -i ${./patches/sigunused.patch}
|
2017-01-24 14:23:15 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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/
|
2018-02-27 03:01:29 +00:00
|
|
|
ln -s ${targetPackages.stdenv.cc.bintools.bintools_bin}/bin/ar $out/bin/ar
|
2018-02-04 05:38:20 +00:00
|
|
|
|
|
|
|
wrapProgram $out/bin/swift \
|
|
|
|
--suffix C_INCLUDE_PATH : $out/lib/swift/clang/include \
|
|
|
|
--suffix CPLUS_INCLUDE_PATH : $out/lib/swift/clang/include
|
2017-01-24 14:23:15 +00:00
|
|
|
'';
|
|
|
|
|
2017-05-16 15:35:52 +01:00
|
|
|
# Hack to avoid TMPDIR in RPATHs.
|
|
|
|
preFixup = ''rm -rf "$(pwd)" '';
|
|
|
|
|
2017-01-24 14:23:15 +00:00
|
|
|
meta = with stdenv.lib; {
|
|
|
|
description = "The Swift Programming Language";
|
2017-08-01 21:03:30 +01:00
|
|
|
homepage = https://github.com/apple/swift;
|
2017-09-24 20:10:20 +01:00
|
|
|
maintainers = with maintainers; [ dtzWill ];
|
2017-01-24 14:23:15 +00:00
|
|
|
license = licenses.asl20;
|
2017-03-29 13:42:16 +01:00
|
|
|
# Swift doesn't support 32bit Linux, unknown on other platforms.
|
|
|
|
platforms = [ "x86_64-linux" ];
|
2017-01-24 14:23:15 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|