2018-09-06 23:18:36 -07:00
{ stdenv , fetchFromGitHub , fetchurl , python , ninja , libxml2 , objc4 , ICU , curl }:
2016-08-24 04:35:30 -07:00
2018-09-06 23:18:36 -07: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 " ;
} ;
in stdenv . mkDerivation {
2016-08-24 04:35:30 -07: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-06 23:18:36 -07:00
rev = " 8 5 c 6 4 0 e 7 c e 5 0 e 6 c a 6 1 a 1 3 4 c 7 2 2 7 0 e 2 1 4 b c 6 3 f d b a " ; # https://github.com/apple/swift-corelibs-foundation/pull/1686
sha256 = " 0 z 2 v 2 7 8 w y 7 j h 0 c 9 2 g 1 d s z d 8 h j 8 n a x a r i 6 6 0 s q x 6 y a b 5 d w a p d 4 6 q c " ;
2016-08-24 04:35:30 -07:00
} ;
2018-09-06 23:18:36 -07:00
buildInputs = [ ninja python libxml2 objc4 ICU curl ] ;
sourceRoot = " s o u r c e / C o r e F o u n d a t i o n " ;
2016-08-24 04:35:30 -07:00
patchPhase = ''
2018-09-06 23:18:36 -07: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 " ' #' \
- - replace " c f . L D F L A G S + = ' - l d i s p a t c h " ' #' \
- - replace " B a s e . s u b p r o j / S w i f t R u n t i m e / C o r e F o u n d a t i o n . h " ' Base.subproj/CoreFoundation.h '
# 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 04:35:30 -07:00
2018-09-06 23:18:36 -07: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 04:35:30 -07:00
2018-09-06 23:18:36 -07: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 04:35:30 -07:00
'' ;
2018-09-06 23:18:36 -07: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
LDFLAGS = " - i n s t a l l _ n a m e ${ placeholder " o u t " } / 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 / C o r e F o u n d a t i o n - c u r r e n t _ v e r s i o n 1 2 3 4 . 5 6 . 7 - 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 " ;
configurePhase = " . . / c o n f i g u r e - - s y s r o o t u n u s e d " ;
enableParallelBuilding = true ;
buildPhase = " n i n j a - j $ N I X _ B U I L D _ C O R E S " ;
# 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 04:35:30 -07:00
installPhase = ''
2018-09-06 23:18:36 -07: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
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 04:35:30 -07:00
'' ;
}