From 29098a81b3720590cde0b0b92bfbf3e66fd9d31b Mon Sep 17 00:00:00 2001 From: Michael Roitzsch Date: Mon, 21 Oct 2019 10:39:03 +0200 Subject: [PATCH 1/3] 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 --- pkgs/development/compilers/swift/default.nix | 93 +++++++++---------- ...sets-linux-don-t-require-using-Ninja.patch | 14 +-- ...ts-linux-allow-custom-install-prefix.patch | 14 +-- ...presets-linux-don-t-build-extra-libs.patch | 2 + ...sets-linux-plumb-extra-cmake-options.patch | 14 +-- .../swift/patches/llvm-include-dirs.patch | 13 --- .../swift/patches/llvm-toolchain-dir.patch | 24 +++++ pkgs/development/compilers/swift/purity.patch | 14 +-- 8 files changed, 73 insertions(+), 115 deletions(-) delete mode 100644 pkgs/development/compilers/swift/patches/llvm-include-dirs.patch create mode 100644 pkgs/development/compilers/swift/patches/llvm-toolchain-dir.patch diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix index 817f81f9257..a3aa5f89c1c 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 79482ac10e6..70b7b0ff73b 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 -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 5c1927acb7f..9122cf01cc8 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 -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 5d766bc2590..d749a430a32 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 1d0a6a9577a..9710f6a1083 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 -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 789c0be7e7a..00000000000 --- 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 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 00000000000..c22b5c820c8 --- /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 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 832decdc41f..a358c2acb66 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 -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 - From b472f4a2de06d1ef8d4feeec30a72cce82bbc7e6 Mon Sep 17 00:00:00 2001 From: Michael Roitzsch Date: Mon, 21 Oct 2019 11:02:16 +0200 Subject: [PATCH 2/3] swift: 5.0.2 -> 5.1.1 --- pkgs/development/compilers/swift/default.nix | 62 +++++++++++++------ ...sets-linux-don-t-require-using-Ninja.patch | 2 +- ...ts-linux-allow-custom-install-prefix.patch | 6 +- ...presets-linux-don-t-build-extra-libs.patch | 8 +-- ...sets-linux-plumb-extra-cmake-options.patch | 2 +- .../swift/patches/glibc-arch-headers.patch | 2 +- .../patches/libdispatch-fortify-fix.patch | 13 ---- pkgs/development/compilers/swift/purity.patch | 2 +- 8 files changed, 53 insertions(+), 44 deletions(-) delete mode 100644 pkgs/development/compilers/swift/patches/libdispatch-fortify-fix.patch diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix index a3aa5f89c1c..5a61e775a9c 100644 --- a/pkgs/development/compilers/swift/default.nix +++ b/pkgs/development/compilers/swift/default.nix @@ -33,7 +33,7 @@ }: let - version = "5.0.2"; + version = "5.1.1"; fetch = { repo, sha256, fetchSubmodules ? false }: fetchFromGitHub { @@ -44,19 +44,29 @@ let }; 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 llvm = fetch { repo = "swift-llvm"; - sha256 = "1bnscqsiljiclij60f44h2fyx5c84pzry0lz1jbwknphwmqd6f84"; + sha256 = "00ldd9dby6fl6nk3z17148fvb7g9x4jkn1afx26y51v8rwgm1i7f"; }; compilerrt = fetch { repo = "swift-compiler-rt"; - sha256 = "0bba54xa7z0wj6k7a24q74gc4yajc6s64g1m894i3yd6swdk7f6r"; + sha256 = "1431f74l0n2dxn728qp65nc6hivx88fax1wzfrnrv19y77br05wj"; }; clang = fetch { repo = "swift-clang"; - sha256 = "046p7f4044ls8hhgklsz32md5jvxkaaim1d75n0fmnwap6di3n1q"; + sha256 = "0n7k6nvzgqp6h6bfqcmna484w90db3zv4sh5rdh89wxyhdz6rk4v"; + }; + clangtools = fetch { + repo = "swift-clang-tools-extra"; + sha256 = "0snp2rpd60z239pr7fxpkj332rkdjhg63adqvqdkjsbrxcqqcgqa"; + }; + indexstore = fetch { + repo = "indexstore-db"; + sha256 = "1gwkqkdmpd5hn7555dpdkys0z50yh00hjry2886h6rx7avh5p05n"; + }; + sourcekit = fetch { + repo = "sourcekit-lsp"; + sha256 = "0k84ssr1k7grbvpk81rr21ii8csnixn9dp0cga98h6i1gshn8ml4"; }; cmark = fetch { repo = "swift-cmark"; @@ -64,32 +74,32 @@ let }; lldb = fetch { repo = "swift-lldb"; - sha256 = "01yrhc1ggv89qii03fdjdvb2aq9v4hd1wk83n8ygrwwc75p44qmi"; + sha256 = "0j787475f0nlmvxqblkhn3yrvn9qhcb2jcijwijxwq95ar2jdygs"; }; llbuild = fetch { repo = "swift-llbuild"; - sha256 = "0ipwryzpqxpk3rzkxilfahlkz06k39j91q2lv7fprf0slqknrdms"; + sha256 = "1n2s5isxyl6b6ya617gdzjbw68shbvd52vsfqc1256rk4g448v8b"; }; pm = fetch { repo = "swift-package-manager"; - sha256 = "1mnywlm7i2mbp16q0rskskvnbx1ap8lchwr8q3gx0xs3b2fs6chh"; + sha256 = "1a49jmag5mpld9zr96g8a773334mrz1c4nyw38gf4p6sckf4jp29"; }; xctest = fetch { repo = "swift-corelibs-xctest"; - sha256 = "1vpljkxhfk3yd07ry0xsv3qwbn62pwd2mdn9cw22jhbhvqinc13z"; + sha256 = "0rxy9sq7i0s0kxfkz0hvdp8zyb40h31f7g4m0kry36qk82gzzh89"; }; foundation = fetch { repo = "swift-corelibs-foundation"; - sha256 = "1wys4xh7f6c7yjf210x41n2krmyi2qj1wpxbv0p48d230va1azj1"; + sha256 = "1iiiijsnys0r3hjcj1jlkn3yszzi7hwb2041cnm5z306nl9sybzp"; }; libdispatch = fetch { repo = "swift-corelibs-libdispatch"; - sha256 = "0chnb0d4xjyn9wnc8bgimd5ji5igfyq891flgnqpfwr4y26496c1"; + sha256 = "0laqsizsikyjhrzn0rghvxd8afg4yav7cbghvnf7ywk9wc6kpkmn"; fetchSubmodules = true; }; swift = fetch { repo = "swift"; - sha256 = "0fsq1y8dz4ssn90akvzj36cqyblalb09bjzy4ikqn67mb5x99wpb"; + sha256 = "0m4r1gzrnn0s1c7haqq9dlmvpqxbgbkbdfmq6qaph869wcmvdkvy"; }; }; @@ -155,6 +165,9 @@ stdenv.mkDerivation { cp -r ${sources.llvm} llvm cp -r ${sources.compilerrt} compiler-rt cp -r ${sources.clang} clang + cp -r ${sources.clangtools} clang-tools-extra + cp -r ${sources.indexstore} indexstore-db + cp -r ${sources.sourcekit} sourcekit-lsp cp -r ${sources.cmark} cmark cp -r ${sources.lldb} lldb cp -r ${sources.llbuild} llbuild @@ -199,9 +212,8 @@ stdenv.mkDerivation { \ -e 's/^swift-install-components=autolink.*$/\0;editor-integration/' - # https://bugs.swift.org/browse/SR-10559 - patch -p1 -d swift-corelibs-libdispatch -i ${./patches/libdispatch-fortify-fix.patch} - + substituteInPlace clang/lib/Driver/ToolChains/Linux.cpp \ + --replace 'SysRoot + "/lib' '"${glibc}/lib" "' substituteInPlace clang/lib/Driver/ToolChains/Linux.cpp \ --replace 'SysRoot + "/usr/lib' '"${glibc}/lib" "' patch -p1 -d clang -i ${./patches/llvm-toolchain-dir.patch} @@ -211,6 +223,10 @@ stdenv.mkDerivation { sed -i 's/curses/ncurses/' llbuild/*/*/CMakeLists.txt PREFIX=''${out/#\/} + substituteInPlace indexstore-db/Utilities/build-script-helper.py \ + --replace usr "$PREFIX" + substituteInPlace sourcekit-lsp/Utilities/build-script-helper.py \ + --replace usr "$PREFIX" substituteInPlace swift-corelibs-xctest/build_script.py \ --replace usr "$PREFIX" ''; @@ -222,9 +238,6 @@ stdenv.mkDerivation { 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= @@ -237,6 +250,12 @@ stdenv.mkDerivation { # 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" + # However, we want to use the wrapped compiler whenever possible. + export CC="${clang}/bin/clang" + + # fix for https://bugs.llvm.org/show_bug.cgi?id=39743 + # see also https://forums.swift.org/t/18138/15 + export CCC_OVERRIDE_OPTIONS="#x-fmodules s/-fmodules-cache-path.*//" $SWIFT_SOURCE_ROOT/swift/utils/build-script \ --preset=buildbot_linux \ @@ -265,6 +284,11 @@ stdenv.mkDerivation { tar xf $INSTALLABLE_PACKAGE -C $out --strip-components=3 ''${out/#\/} find $out -type d -empty -delete + # fix installation weirdness, also present in Apple’s official tarballs + mv $out/local/include/indexstore $out/include + rmdir $out/local/include $out/local + rm -r $out/bin/sdk-module-lists $out/bin/swift-api-checker.py + wrapProgram $out/bin/swift \ --suffix C_INCLUDE_PATH : $out/lib/swift/clang/include \ --suffix CPLUS_INCLUDE_PATH : $out/lib/swift/clang/include \ 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 70b7b0ff73b..60b2996b340 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 @@ -2,7 +2,7 @@ Don't build Ninja, we use our own. --- a/utils/build-presets.ini +++ b/utils/build-presets.ini -@@ -721,7 +721,7 @@ swiftpm +@@ -745,7 +745,7 @@ swiftpm dash-dash 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 9122cf01cc8..5ca6bf1354d 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 @@ -2,12 +2,12 @@ allow custom install prefix --- 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 @@ +@@ -752,7 +752,7 @@ install-swiftpm install-xctest install-libicu -install-prefix=/usr +install-prefix=%(install_prefix)s - 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 + install-sourcekit-lsp + build-swift-static-stdlib 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 d749a430a32..0a66af9e513 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 @@ -2,7 +2,7 @@ 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 @@ +@@ -740,8 +740,6 @@ llbuild swiftpm xctest @@ -11,15 +11,13 @@ Disable targets, where we use Nix packages. dash-dash -@@ -727,11 +725,9 @@ +@@ -751,9 +749,7 @@ install-llbuild install-swiftpm install-xctest -install-libicu install-prefix=%(install_prefix)s - 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 + install-sourcekit-lsp build-swift-static-stdlib build-swift-static-sdk-overlay - build-swift-stdlib-unittest-extra 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 9710f6a1083..304b53a1dbf 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 @@ -2,7 +2,7 @@ plumb extra-cmake-options --- a/utils/build-presets.ini +++ b/utils/build-presets.ini -@@ -743,6 +743,8 @@ install-destdir=%(install_destdir)s +@@ -766,6 +766,8 @@ install-destdir=%(install_destdir)s # Path to the .tar.gz package we would create. installable-package=%(installable_package)s diff --git a/pkgs/development/compilers/swift/patches/glibc-arch-headers.patch b/pkgs/development/compilers/swift/patches/glibc-arch-headers.patch index df906f9c84c..c05db520801 100644 --- a/pkgs/development/compilers/swift/patches/glibc-arch-headers.patch +++ b/pkgs/development/compilers/swift/patches/glibc-arch-headers.patch @@ -2,7 +2,7 @@ The Nix glibc headers do not use include/x86_64-linux-gnu subdirectories. --- swift/stdlib/public/Platform/CMakeLists.txt 2019-04-09 20:14:44.493801403 +0200 +++ swift/stdlib/public/Platform/CMakeLists.txt 2019-04-09 20:14:44.577800593 +0200 -@@ -68,7 +68,7 @@ +@@ -77,7 +77,7 @@ endif() set(GLIBC_INCLUDE_PATH "${GLIBC_SYSROOT_RELATIVE_INCLUDE_PATH}") diff --git a/pkgs/development/compilers/swift/patches/libdispatch-fortify-fix.patch b/pkgs/development/compilers/swift/patches/libdispatch-fortify-fix.patch deleted file mode 100644 index d23a308d68f..00000000000 --- a/pkgs/development/compilers/swift/patches/libdispatch-fortify-fix.patch +++ /dev/null @@ -1,13 +0,0 @@ -Nix compiles with _FORTIFY_SOURCE enabled. Fix error due to -Werror and an unused return value warning. - ---- swift-corelibs-libdispatch/src/internal.h 2019-04-26 09:33:38.287289099 +0200 -+++ swift-corelibs-libdispatch/src/internal.h 2019-04-26 15:31:10.485334128 +0200 -@@ -1053,7 +1053,7 @@ - #else - #define _dispatch_client_assert_fail(fmt, ...) do { \ - char *_msg = NULL; \ -- asprintf(&_msg, "%s" fmt, DISPATCH_ASSERTION_FAILED_MESSAGE, \ -+ (void)asprintf(&_msg, "%s" fmt, DISPATCH_ASSERTION_FAILED_MESSAGE, \ - ##__VA_ARGS__); \ - _dispatch_assert_crash(_msg); \ - free(_msg); \ diff --git a/pkgs/development/compilers/swift/purity.patch b/pkgs/development/compilers/swift/purity.patch index a358c2acb66..4133e89c283 100644 --- a/pkgs/development/compilers/swift/purity.patch +++ b/pkgs/development/compilers/swift/purity.patch @@ -2,7 +2,7 @@ --- 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, +@@ -402,13 +402,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"); From b82d44383687094ecaf0544006726b26c65a6268 Mon Sep 17 00:00:00 2001 From: Michael Roitzsch Date: Tue, 10 Dec 2019 15:14:42 +0100 Subject: [PATCH 3/3] swift: fix UUID module and enable tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix UUID compilation error This was pointed out by Swift’s test suite. * enable tests after build Two broken tests disabled for now. --- pkgs/development/compilers/swift/default.nix | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix index 5a61e775a9c..77bc3cc5b73 100644 --- a/pkgs/development/compilers/swift/default.nix +++ b/pkgs/development/compilers/swift/default.nix @@ -221,6 +221,8 @@ stdenv.mkDerivation { # Workaround hardcoded dep on "libcurses" (vs "libncurses"): sed -i 's/curses/ncurses/' llbuild/*/*/CMakeLists.txt + # uuid.h is not part of glibc, but of libuuid + sed -i 's|''${GLIBC_INCLUDE_PATH}/uuid/uuid.h|${libuuid.dev}/include/uuid/uuid.h|' swift/stdlib/public/Platform/glibc.modulemap.gyb PREFIX=''${out/#\/} substituteInPlace indexstore-db/Utilities/build-script-helper.py \ @@ -265,15 +267,20 @@ stdenv.mkDerivation { extra_cmake_options="${stdenv.lib.concatStringsSep "," cmakeFlags}" ''; - doCheck = false; + doCheck = true; checkInputs = [ file ]; - # TODO: investigate the non-working tests checkPhase = '' + # FIXME: disable non-working tests + rm $SWIFT_SOURCE_ROOT/swift/test/Driver/static-stdlib-linux.swift # static linkage of libatomic.a complains about missing PIC + rm $SWIFT_SOURCE_ROOT/swift/validation-test/Python/build_swift.swift # install_prefix not passed properly + + # match the swift wrapper in the install phase + export LIBRARY_PATH=${icu}/lib:${libuuid.out}/lib + checkTarget=check-swift-all ninjaFlags='-C buildbot_linux/swift-${stdenv.hostPlatform.parsed.kernel.name}-${stdenv.hostPlatform.parsed.cpu.name}' - ninjaCheckPhase ''; @@ -292,7 +299,7 @@ stdenv.mkDerivation { wrapProgram $out/bin/swift \ --suffix C_INCLUDE_PATH : $out/lib/swift/clang/include \ --suffix CPLUS_INCLUDE_PATH : $out/lib/swift/clang/include \ - --suffix LIBRARY_PATH : $icu/lib + --suffix LIBRARY_PATH : ${icu}/lib:${libuuid.out}/lib ''; # Hack to avoid build and install directories in RPATHs.