Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swift: init at 3.1 #22098

Merged
merged 1 commit into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
264 changes: 264 additions & 0 deletions pkgs/development/compilers/swift/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
{ stdenv
, cmake
, coreutils
, glibc
, which
, perl
, libedit
, ninja
, pkgconfig
, sqlite
, swig
, bash
, libxml2
, llvm
, clang
, python
, ncurses
, libuuid
, libbsd
, icu
, autoconf
, libtool
, automake
, libblocksruntime
, curl
, rsync
, git
, libgit2
, binutils
, fetchFromGitHub
, paxctl
, findutils
#, systemtap
}:

let
v_major = "3.1";
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";
};

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 = "0820mx1ghfnk4p5595r1f313y1699jwi61zghfbwak5wgwgy7n4x";
};
llvm = fetch {
repo = "swift-llvm";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if it really needs its own custom llvm or if it can use our pre-existing packages? I fear that we'll be missing patches and it'll reach out to all sorts of impure locations as a result.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unable to convince their build scripts to use an external LLVM. I believe their versions of these components are very similar but haven't tried sorting out differences (especially since I don't think they're based on a particular fixed release). Without more insight into the differences I'd be reluctant to use anything other than their vendor'd LLVM due to concerns about possible subtle behavioral differences from other "Swift 3.1" implementations.

That said, even breaking this huge build into pieces would be awfully nice :).

sha256 = "0zb1zi77b2xdz5szlz2m3j3d92dc0q00dv8py2s6iaq3k435i3sq";
};
compilerrt = fetch {
repo = "swift-compiler-rt";
sha256 = "1gjcr6g3ffs3nhf4a84iwg4flbd7rqcf9rvvclwyq96msa3mj950";
};
cmark = fetch {
repo = "swift-cmark";
sha256 = "0qf2f3zd8lndkfbxbz6vkznzz8rvq5gigijh7pgmfx9fi4zcssqx";
};
lldb = fetch {
repo = "swift-lldb";
sha256 = "17n4whpf3wxw9zaayiq21gk9q3547qxi4rvxld2hybh0k7a1bj5c";
};
llbuild = fetch {
repo = "swift-llbuild";
sha256 = "1l3hnb2s01jby91k1ipbc3bhszq14vyx5pzdhf2chld1yhpg420d";
};
pm = fetch {
repo = "swift-package-manager";
sha256 = "05zijald08z4jbppjawlc0h9n0i4dvn6jnhq0i5b9qq55l7a1lrk";
};
xctest = fetch {
repo = "swift-corelibs-xctest";
sha256 = "0cj5y7wanllfldag08ci567x12aw793c79afckpbsiaxmwy4xhnm";
};
foundation = fetch {
repo = "swift-corelibs-foundation";
sha256 = "0d34clr7n0kfy0l94hmgg1cailg3bml0qzlhy8wh75hrrv3n4g1v";
};
libdispatch = fetch {
repo = "swift-corelibs-libdispatch";
sha256 = "1rka7ijkdk4ybdvyk3map5mc1fm79v848v9nhpfq75m5i63r61bh";
fetchSubmodules = true;
};
swift = fetch {
repo = "swift";
sha256 = "172q84z70z9gpwahmlcifihldrvc3cafy9ajbz4wi5f6ncw7wbmb";
};
};

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 = ''
$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
] ++ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the build automatically build all this stuff? I'm surprised to see these going in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! What's built is described by the preset we're using, which is a modified version of what they use on the linux buildbots:
https://github.com/NixOS/nixpkgs/pull/22098/files#diff-207758b47bdae6fde307317858e26f47R715
(which references the mixin_linux_installation preset: https://github.com/NixOS/nixpkgs/pull/22098/files#diff-207758b47bdae6fde307317858e26f47R681).

It's possible we can break these apart eventually but I don't think it would be easy or even worth it--AFAICT the components are all very much meant to be built/tested together.

Also this does take a while to build... :).

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

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}

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
substituteInPlace llbuild/tests/BuildSystem/Build/basic.llbuild \
--replace /usr/bin/env $(type -p env)

# This test fails on one of my machines, not sure why.
# Disabling for now.
rm llbuild/tests/Examples/buildsystem-capi.llbuild

substituteInPlace swift-corelibs-foundation/lib/script.py \
--replace /bin/cp $(type -p cp)

PREFIX=''${out/#\/}
substituteInPlace swift-corelibs-xctest/build_script.py \
--replace usr "$PREFIX"
substituteInPlace swiftpm/Utilities/bootstrap \
--replace "usr" "$PREFIX"
'';

doCheck = false;

buildPhase = builder;

installPhase = ''
mkdir -p $out

# Extract the generated tarball into the store
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the build process have to generate a tarball? Feels kind of convoluted, but I guess such is life sometimes 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't go so far as to say it /has/ to generate a tarball, but it's the best I could find for installing all the bits neatly. Unfortunately given the very long build time this is a bit tainted by being satisfied with what works vs trying other things. I agree it's unfortunate, for sure.

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/
ln -s ${binutils}/bin/ar $out/bin/ar
'';

meta = with stdenv.lib; {
description = "The Swift Programming Language";
homepage = "https://github.com/apple/swift";
maintainers = with maintainers; [ jb55 dtzWill ];
license = licenses.asl20;
platforms = platforms.linux;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried it on macOS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! But since, for example, the current buildPhase explicitly refers to the linux build configuration I'm pretty sure it won't work :(. Hopefully it's not too much trouble to make it work on Darwin, but I really don't know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I can look into it but this PR is definitely good to merge even without macOS

};
}

Original file line number Diff line number Diff line change
@@ -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
@@ -686,7 +686,7 @@ swiftpm
xctest
dash-dash

-build-ninja
+# build-ninja
install-swift
install-lldb
install-llbuild
--
2.12.2

Original file line number Diff line number Diff line change
@@ -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
@@ -692,7 +692,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
build-swift-static-stdlib
build-swift-static-sdk-overlay
--
2.12.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
From fcc7c216da6cd255f884b7aa39f361786e3afa6a Mon Sep 17 00:00:00 2001
From: Will Dietz <w@wdtz.org>
Date: Tue, 28 Mar 2017 15:02:18 -0500
Subject: [PATCH 3/4] build-presets: (linux) disable tests.

---
utils/build-presets.ini | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/utils/build-presets.ini b/utils/build-presets.ini
index 1095cbaab7..1739e91dc2 100644
--- a/utils/build-presets.ini
+++ b/utils/build-presets.ini
@@ -700,7 +700,7 @@ build-swift-stdlib-unittest-extra

# Executes the lit tests for the installable package that is created
# Assumes the swift-integration-tests repo is checked out
-test-installable-package
+# test-installable-package

# Path to the root of the installation filesystem.
install-destdir=%(install_destdir)s
@@ -713,9 +713,9 @@ mixin-preset=mixin_linux_installation
build-subdir=buildbot_linux
lldb
release
-test
-validation-test
-long-test
+#test
+#validation-test
+#long-test
foundation
libdispatch
lit-args=-v
--
2.12.2

Original file line number Diff line number Diff line change
@@ -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
@@ -708,6 +708,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