2020-01-12 20:16:22 +00:00
{ stdenv , fetchFromGitHub , fetchurl , ninja , python3 , curl , libxml2 , objc4 , ICU }:
2016-08-24 12:35:30 +01:00
2018-09-07 07:18:36 +01:00
let
# 10.12 adds a new sysdir.h that our version of CF in the main derivation depends on, but
# isn't available publicly, so instead we grab an older version of the same file that did
# not use sysdir.h, but provided the same functionality. Luckily it's simple :) hack hack
sysdir-free-system-directories = fetchurl {
url = " h t t p s : / / r a w . g i t h u b u s e r c o n t e n t . c o m / a p p l e / s w i f t - c o r e l i b s - f o u n d a t i o n / 9 a 5 d 8 4 2 0 f 7 7 9 3 e 6 3 a 8 d 5 e c 1 e d e 5 1 6 c 4 e b e c 9 3 9 f 0 / C o r e F o u n d a t i o n / B a s e . s u b p r o j / C F S y s t e m D i r e c t o r i e s . c " ;
sha256 = " 0 k r f y g h j 4 f 0 9 6 a r v v p f 8 8 4 r a 5 c z q l m b r g f 8 y y c 0 b 3 a v q m b 6 1 3 p c c " ;
} ;
2019-02-11 23:29:28 +00:00
in
stdenv . mkDerivation {
2016-08-24 12:35:30 +01:00
name = " s w i f t - c o r e f o u n d a t i o n " ;
src = fetchFromGitHub {
owner = " a p p l e " ;
repo = " s w i f t - c o r e l i b s - f o u n d a t i o n " ;
2018-09-09 18:36:05 +01:00
rev = " 7 1 a a b a 2 0 e 1 4 5 0 a 8 2 c 5 1 6 a f 1 3 4 2 f e 2 3 2 6 8 e 1 5 d e 0 a " ;
sha256 = " 1 7 k p q l 0 f 2 7 x x z 4 j j w 8 4 v p a s 5 f 5 s n 4 v d q w v 1 0 g 1 5 1 r c 3 r s w b w l n 1 z " ;
2016-08-24 12:35:30 +01:00
} ;
2020-01-12 20:16:22 +00:00
nativeBuildInputs = [ ninja python3 ] ;
buildInputs = [ curl libxml2 objc4 ICU ] ;
2018-09-07 07:18:36 +01:00
sourceRoot = " s o u r c e / C o r e F o u n d a t i o n " ;
2016-08-24 12:35:30 +01:00
patchPhase = ''
2018-09-07 07:18:36 +01:00
cp $ { sysdir-free-system-directories } Base.subproj/CFSystemDirectories.c
# In order, since I can't comment individual lines:
# 1. Disable dispatch support for now
# 2. For the linker too
# 3. Use the legit CoreFoundation.h, not the one telling you not to use it because of Swift
substituteInPlace build . py \
- - replace " c f . C F L A G S + = ' - D D E P L O Y M E N T " ' #' \
2018-09-09 18:36:05 +01:00
- - replace " c f . L D F L A G S + = ' - l d i s p a t c h " ' #'
2018-09-07 07:18:36 +01:00
2019-02-11 23:29:28 +00:00
# Fix sandbox impurities.
substituteInPlace ../lib/script.py \
- - replace ' /bin/cp ' cp
2018-09-07 07:18:36 +01:00
# Includes xpc for some initialization routine that they don't define anyway, so no harm here
substituteInPlace PlugIn.subproj/CFBundlePriv.h \
- - replace ' #if (TARGET_OS_MAC' '#if (0'
# Why do we define __GNU__? Is that normal?
substituteInPlace Base.subproj/CFAsmMacros.h \
- - replace ' #if defined(__GNU__) ||' '#if 0 &&'
2016-08-24 12:35:30 +01:00
2018-09-07 07:18:36 +01:00
# The MIN macro doesn't seem to be defined sensibly for us. Not sure if our stdenv or their bug
substituteInPlace Base.subproj/CoreFoundation_Prefix.h \
- - replace ' #if DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX' '#if 1'
2016-08-24 12:35:30 +01:00
2018-09-07 07:18:36 +01:00
# Somehow our ICU doesn't have this, probably because it's too old (we'll update it soon when we update the rest of the SDK)
substituteInPlace Locale.subproj/CFLocale.c \
- - replace ' #if U_ICU_VERSION_MAJOR_NUM' '#if 0 //'
2016-08-24 12:35:30 +01:00
'' ;
2018-09-07 07:18:36 +01:00
BUILD_DIR = " . / B u i l d " ;
CFLAGS = " - D I N C L U D E _ O B J C - I ${ libxml2 . dev } / i n c l u d e / l i b x m l 2 " ; # They seem to assume we include objc in some places and not in others, make a PR; also not sure why but libxml2 include path isn't getting picked up from buildInputs
2019-02-11 23:29:28 +00:00
2018-09-09 18:36:05 +01:00
# I'm guessing at the version here. https://github.com/apple/swift-corelibs-foundation/commit/df3ec55fe6c162d590a7653d89ad669c2b9716b1 imported "high sierra"
# and this version is a version from there. No idea how accurate it is.
LDFLAGS = " - c u r r e n t _ v e r s i o n 1 4 5 4 . 9 0 . 0 - c o m p a t i b i l i t y _ v e r s i o n 1 5 0 . 0 . 0 - i n i t _ _ _ C F I n i t i a l i z e " ;
2019-11-17 13:55:00 +00:00
configurePhase = ''
../configure release - - sysroot UNUSED
'' ;
2018-09-07 07:18:36 +01:00
enableParallelBuilding = true ;
2019-11-17 13:55:00 +00:00
# FIXME: Workaround for intermittent build failures of CFRuntime.c.
# Based on testing this issue seems to only occur with clang_7, so
# please remove this when updating the default llvm versions to 8 or
# later.
buildPhase = stdenv . lib . optionalString true ''
for i in { 1 . .512 } ; do
2019-12-11 20:49:21 +00:00
if ninja - j $ NIX_BUILD_CORES ; then
break
2019-11-17 13:55:00 +00:00
fi
echo > & 2
echo " [ $ i / 5 1 2 ] r e t r y i n g b u i l d , w o r k a r o u n d f o r # 6 6 8 1 1 " > & 2
echo " W i t h c l a n g _ 7 t h e b u i l d o f C F R u n t i m e . c f a i l s i n t e r m i t t e n t l y . " > & 2
echo " S e e h t t p s : / / g i t h u b . c o m / N i x O S / n i x p k g s / i s s u e s / 6 6 8 1 1 f o r m o r e d e t a i l s . " > & 2
echo > & 2
continue
done
'' ;
2018-09-07 07:18:36 +01:00
# TODO: their build system sorta kinda can do this, but it doesn't seem to work right now
# Also, this includes a bunch of private headers in the framework, which is not what we want
2016-08-24 12:35:30 +01:00
installPhase = ''
2018-09-07 07:18:36 +01:00
base = " $ o u t / L i b r a r y / F r a m e w o r k s / C o r e F o u n d a t i o n . f r a m e w o r k "
mkdir - p $ base/Versions/A / { Headers , PrivateHeaders , Modules }
cp ./Build/CoreFoundation/libCoreFoundation.dylib $ base/Versions/A/CoreFoundation
2018-09-09 18:36:05 +01:00
# Note that this could easily live in the ldflags above as `-install_name @rpath/...` but
# https://github.com/NixOS/nixpkgs/issues/46434 thwarts that, so for now I'm hacking it up
# after the fact.
install_name_tool - id ' @ rpath/CoreFoundation.framework/Versions/A/CoreFoundation ' $ base/Versions/A/CoreFoundation
2018-09-07 07:18:36 +01:00
cp ./Build/CoreFoundation/usr/include/CoreFoundation /* . h $ b a s e / V e r s i o n s / A / H e a d e r s
cp ./Build/CoreFoundation/usr/include/CoreFoundation/module.modulemap $ base/Versions/A/Modules
ln - s A $ base/Versions/Current
for i in CoreFoundation Headers Modules ; do
ln - s Versions/Current / $ i $ base / $ i
done
2016-08-24 12:35:30 +01:00
'' ;
}