2018-09-07 08:18:36 +02:00
{ stdenv , fetchFromGitHub , fetchurl , python , ninja , libxml2 , objc4 , ICU , curl }:
2016-08-24 13:35:30 +02:00
2018-09-07 08:18:36 +02: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 13:35:30 +02: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 19:36:05 +02: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 13:35:30 +02:00
} ;
2018-09-09 19:36:05 +02:00
nativeBuildInputs = [ ninja python ] ;
buildInputs = [ libxml2 objc4 ICU curl ] ;
2018-09-07 08:18:36 +02: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 13:35:30 +02:00
patchPhase = ''
2018-09-07 08:18:36 +02: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 19:36:05 +02:00
- - replace " c f . L D F L A G S + = ' - l d i s p a t c h " ' #'
2018-09-07 08:18:36 +02: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 13:35:30 +02:00
2018-09-07 08:18:36 +02: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 13:35:30 +02:00
2018-09-07 08:18:36 +02: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 13:35:30 +02:00
'' ;
2018-09-07 08:18:36 +02: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
2018-09-09 19:36:05 +02: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 " ;
configurePhase = " . . / c o n f i g u r e r e l e a s e - - s y s r o o t U N U S E D " ;
2018-09-07 08:18:36 +02:00
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 13:35:30 +02:00
installPhase = ''
2018-09-07 08:18:36 +02: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 19:36:05 +02: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 08:18:36 +02: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 13:35:30 +02:00
'' ;
}