Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to build a Swift toolchain on Linux with full Dispatch and NSURLSession support

Follow the instructions to checkout a full Swift build for Linux:

git clone https://github.com/apple/swift.git
cd swift
./utils/update-checkout --clone

Update the libdispatch component to use the 'experimental/foundation' branch:

cd swift-corelibs-libdispatch
git pull origin experimental/foundation
git submodule init
git submodule update
cd ..

Replace the foundation component with the seabaylea/swift-corelibs-foundation#nsurlsession fork/branch:

rm -rf swift-corelibs-foundation
git clone -b nsurlsession http://github.com/seabaylea/swift-corelibs-foundation

Build a full toolchain, with the addition of the --dispatch and --install-dispatch flags. This can be done by updating the swift/utils/build-presets.ini file to add the flags to the buildbot_linux:

[preset: buildbot_linux]
mixin-preset=mixin_linux_installation
build-subdir=buildbot_linux
lldb
release
test
validation-test
long-test
libdispatch
foundation

dash-dash

install-libdispatch
install-foundation
reconfigure

and then running the buildbot_linux preset:

./swift/utils/build-script --preset=buildbot_linux install_destdir=/tmp/install installable_package=/tmp/swift-with-nsurlsession.tar.gz
@romainmenke
Copy link

romainmenke commented Jun 13, 2016

I had some trouble with :

cd swift-corelibs-libdispatch
git pull origin experimental/foundation

So I ended up removing swift-corelibs-libdispatch and cloning from your branch.
I first cloned all the files locally and then COPY them into a docker container.

My current Dockerfile (docker did not like adding all the files at once, so I split it into multiple phases) :
NSURLSessionDockerfile

Had an error while building Swift but I have since changed my Dockerfile and I am now waiting for it to complete. Will update when it is done.

@romainmenke
Copy link

romainmenke commented Jun 13, 2016

I now get the following :

FAILED: /usr/bin/clang++   -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-stack-protector -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -std=c++11 -fcolor-diagnostics -ffunction-sections -fdata-sections -O3  -Ilib/CodeGen -I/src/llvm/lib/CodeGen -Iinclude -I/src/llvm/include    -UNDEBUG  -fno-exceptions -fno-rtti -MMD -MT lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/MachineVerifier.cpp.o -MF lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/MachineVerifier.cpp.o.d -o lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/MachineVerifier.cpp.o -c /src/llvm/lib/CodeGen/MachineVerifier.cpp
In file included from /src/llvm/lib/CodeGen/MachineVerifier.cpp:26:
....
....
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.2.1/../../../../include/c++/5.2.1/random:42:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.2.1/../../../../include/c++/5.2.1/limits:1755:7: error: no return statement in constexpr function
      lowest() noexcept { return -__LDBL_MAX__; }
      ^
1 error generated.
ninja: build stopped: subcommand failed.

@seabaylea
Copy link
Author

seabaylea commented Jun 14, 2016

Picking up the libdispatch branch could be replaced with:

git clone -b experimental/foundation http://github.com/apple/swift-corelibs-libdispatch
cd swift-corelibs-libdispatch
git submodule init
git submodule update

but you'd most likely have to delete the existing swift-corelibs-libdispatch directory first.

@seabaylea
Copy link
Author

seabaylea commented Jun 14, 2016

That build failure is unrelated to the Foundation and libdispatch changes - it looks like a failure in the LLVM build. It might be worth updating that component:

cd llvm
git pull origin stable

@romainmenke
Copy link

romainmenke commented Jun 19, 2016

Updated my scripts with you suggestions, It builds fine, but then the tests fail. I'm just going to wait a couple of days/weeks :) I can't thank you enough for your time and help. I really love what you guys are doing with Swift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment