Skip to content

Commit

Permalink
swift: WIP darwin support
Browse files Browse the repository at this point in the history
- Needs cleanup

- Need to check if swift-nix-toolchain.patch is still necessary.

- Should enable verbose-build, IMHO

- Can we build less? Tweak buildbot_linux preset?

- Currently fails at:

  [3400/3403][ 99%][2567.938s] Performing build step for 'compiler-rt'
  [104/806][ 12%][0.798s] Building C object lib/builtins/CMakeFiles/clang_rt.cc_kext_x86_64_osx.dir/os_version_check.c.o
  FAILED: lib/builtins/CMakeFiles/clang_rt.cc_kext_x86_64_osx.dir/os_version_check.c.o
  /tmp/nix-build-swift-5.1.1.drv-0/build/buildbot_linux/llvm-macosx-x86_64/./bin/clang -DKERNEL_USE  -O3 -DNDEBUG -arch x86_64 -isysroot /nix/store/afpv8r50svbrmdmk56wcwpzyp5zac3l5-SDKs/MacOSX10.12.sdk  -isysroot /nix/store/afpv8r50svbrmdmk56wcwpzyp5zac3l5-SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.5 -fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer -arch x86_64 -mkernel -MD -MT lib/builtins/CMakeFiles/clang_rt.cc_kext_x86_64_osx.dir/os_version_check.c.o -MF lib/builtins/CMakeFiles/clang_rt.cc_kext_x86_64_osx.dir/os_version_check.c.o.d -o lib/builtins/CMakeFiles/clang_rt.cc_kext_x86_64_osx.dir/os_version_check.c.o -c /tmp/nix-build-swift-5.1.1.drv-0/src/llvm/projects/compiler-rt/lib/builtins/os_version_check.c
  /tmp/nix-build-swift-5.1.1.drv-0/src/llvm/projects/compiler-rt/lib/builtins/os_version_check.c:18:10: fatal error: 'TargetConditionals.h' file not found
  #include <TargetConditionals.h>
           ^~~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  [113/806][ 14%][0.848s] Building C object lib/builtins/CMakeFiles/clang_rt.cc_kext_x86_64_osx.dir/popcountti2.c.o
  ninja: build stopped: subcommand failed.
  FAILED: tools/clang/runtime/compiler-rt-stamps/compiler-rt-build
  cd /tmp/nix-build-swift-5.1.1.drv-0/build/buildbot_linux/llvm-macosx-x86_64/tools/clang/runtime/compiler-rt-bins && /nix/store/mrz74myz60ig4asl3ldrch86mhwlfsai-cmake-3.18.4/bin/cmake --build . && /nix/store/mrz74myz60ig4asl3ldrch86mhwlfsai-cmake-3.18.4/bin/cmake -E touch /tmp/nix-build-swift-5.1.1.drv-0/build/buildbot_linux/llvm-macosx-x86_64/tools/clang/runtime/compiler-rt-stamps//compiler-rt-build
  ninja: build stopped: subcommand failed.
  • Loading branch information
stephank committed Nov 28, 2020
1 parent 97dcc00 commit 2b035ef
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 14 deletions.
56 changes: 42 additions & 14 deletions pkgs/development/compilers/swift/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
, makeWrapper
, gnumake
, file
, darwin
, xcbuild
}:

let
Expand Down Expand Up @@ -107,23 +109,27 @@ let

devInputs = [
curl
glibc
icu
libblocksruntime
libbsd
libedit
libuuid
libxml2
ncurses
sqlite
swig
];
]
++ stdenv.lib.optionals stdenv.isLinux [
glibc
libuuid
];

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=${gccForLibs}"
];
]
++ stdenv.lib.optionals stdenv.isLinux [
"-DGLIBC_INCLUDE_PATH=${stdenv.cc.libc.dev}/include"
];

in
stdenv.mkDerivation {
Expand All @@ -137,18 +143,25 @@ stdenv.mkDerivation {
coreutils
findutils
gnumake
libtool
makeWrapper
ninja
perl
pkgconfig
python
rsync
which
];
buildInputs = devInputs ++ [
clang
];
]
++ (stdenv.lib.optionals stdenv.isLinux [
libtool
])
++ (stdenv.lib.optionals stdenv.isDarwin [
xcbuild clang darwin.cctools darwin.PowerManagement
]);

buildInputs = devInputs
++ (stdenv.lib.optionals stdenv.isLinux [
clang
]);

# TODO: Revisit what's propagated and how
propagatedBuildInputs = [
Expand Down Expand Up @@ -198,14 +211,16 @@ stdenv.mkDerivation {
-e 's|/usr/bin/file|${file}/bin/file|g'
substituteInPlace swift/stdlib/public/Platform/CMakeLists.txt \
--replace '/usr/include' "${stdenv.cc.libc.dev}/include"
--replace '/usr/include' "${stdenv.cc.libc_dev}/include"
substituteInPlace swift/utils/build-script-impl \
--replace '/usr/include/c++' "${gccForLibs}/include/c++"
patch -p1 -d swift -i ${./patches/glibc-arch-headers.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-don-t-build-extra-libs.patch}
patch -p1 -d swift -i ${./patches/0004-build-presets-linux-plumb-extra-cmake-options.patch}
patch -p1 -d swift -i ${./patches/swift-darwin-sandbox.patch}
patch -p1 -d swift -i ${./patches/swift-nix-toolchain.patch}
sed -i swift/utils/build-presets.ini \
-e 's/^test-installable-package$/# \0/' \
Expand All @@ -217,17 +232,22 @@ stdenv.mkDerivation {
\
-e 's/^swift-install-components=autolink.*$/\0;editor-integration/'
${stdenv.lib.optionalString stdenv.isLinux ''
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}
patch -p1 -d clang -i ${./purity.patch}
# 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
${stdenv.lib.optionalString (libuuid != null) ''
sed -i 's|''${GLIBC_INCLUDE_PATH}/uuid/uuid.h|${libuuid.dev}/include/uuid/uuid.h|' swift/stdlib/public/Platform/glibc.modulemap.gyb
''}
# Compatibility with glibc 2.30
# Adapted from https://github.com/apple/swift-package-manager/pull/2408
Expand Down Expand Up @@ -295,7 +315,10 @@ stdenv.mkDerivation {
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
export LIBRARY_PATH=${icu}/lib
${stdenv.lib.optionalString (libuuid != null) ''
export LIBRARY_PATH=${libuuid.out}/lib:$LIBRARY_PATH
''}
checkTarget=check-swift-all
ninjaFlags='-C buildbot_linux/swift-${stdenv.hostPlatform.parsed.kernel.name}-${stdenv.hostPlatform.parsed.cpu.name}'
Expand All @@ -314,10 +337,15 @@ stdenv.mkDerivation {
rmdir $out/local/include $out/local
rm -r $out/bin/sdk-module-lists $out/bin/swift-api-checker.py
export LIBRARY_PATH=${icu}/lib
${stdenv.lib.optionalString (libuuid != null) ''
export LIBRARY_PATH=${libuuid.out}/lib:$LIBRARY_PATH
''}
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:${libuuid.out}/lib
--suffix LIBRARY_PATH : $LIBRARY_PATH
'';

# Hack to avoid build and install directories in RPATHs.
Expand All @@ -329,7 +357,7 @@ stdenv.mkDerivation {
maintainers = with maintainers; [ dtzWill ];
license = licenses.asl20;
# Swift doesn't support 32bit Linux, unknown on other platforms.
platforms = platforms.linux;
platforms = platforms.linux ++ platforms.darwin;
badPlatforms = platforms.i686;
broken = stdenv.isAarch64; # 2018-09-04, never built on Hydra
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Disable Darwin build-time checks broken within the sandbox

--- a/utils/swift_build_support/swift_build_support/host.py
+++ b/utils/swift_build_support/swift_build_support/host.py
@@ -44,7 +44,6 @@ def _darwin_system_memory():


_PER_PLATFORM_SYSTEM_MEMORY = {
- ('Darwin', 'x86_64'): _darwin_system_memory
}


@@ -79,8 +78,6 @@ def _darwin_max_num_swift_parallel_lto_link_jobs():


_PER_PLATFORM_MAX_PARALLEL_LTO_JOBS = {
- ('Darwin', 'x86_64'): (_darwin_max_num_llvm_parallel_lto_link_jobs,
- _darwin_max_num_swift_parallel_lto_link_jobs)
}


30 changes: 30 additions & 0 deletions pkgs/development/compilers/swift/patches/swift-nix-toolchain.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Force PATH lookup of toolchain on all platforms

--- a/utils/swift_build_support/swift_build_support/toolchain.py
+++ b/utils/swift_build_support/swift_build_support/toolchain.py
@@ -16,6 +16,7 @@ Represent toolchain - the versioned executables.

from __future__ import absolute_import

+import os
import platform

from . import cache_util
@@ -192,9 +193,16 @@ class Haiku(GenericUnix):
super(Haiku, self)


+class Nix(GenericUnix):
+ def __init__(self):
+ super(Nix, self).__init__([''])
+
+
def host_toolchain(**kwargs):
sys = platform.system()
- if sys == 'Darwin':
+ if 'NIX_BUILD_TOP' in os.environ:
+ return Nix()
+ elif sys == 'Darwin':
return MacOSX(kwargs.pop('xcrun_toolchain', 'default'))
elif sys == 'Linux':
return Linux()

0 comments on commit 2b035ef

Please sign in to comment.