1# TODO: We already package the CoreFoundation component of Foundation in:
2# pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix
3# This is separate because the CF build is completely different and part of
4# stdenv. Merging the two was kept outside of the scope of Swift work.
5
6{ lib
7, stdenv
8, fetchpatch
9, callPackage
10, cmake
11, ninja
12, swift
13, Dispatch
14, icu
15, libxml2
16, curl
17}:
18
19let
20 sources = callPackage ../sources.nix { };
21in stdenv.mkDerivation {
22 pname = "swift-corelibs-foundation";
23
24 inherit (sources) version;
25 src = sources.swift-corelibs-foundation;
26
27 patches = [
28 # from https://github.com/apple/swift-corelibs-foundation/pull/4811
29 # fix build with glibc >=2.38
30 (fetchpatch {
31 url = "https://github.com/apple/swift-corelibs-foundation/commit/47260803a108c6e0d639adcebeed3ac6a76e8bcd.patch";
32 hash = "sha256-1JUSQW86IHKkBZqxvpk0P8zcSKntzOTNlMoGBfgeT4c=";
33 })
34 ];
35
36 outputs = [ "out" "dev" ];
37
38 nativeBuildInputs = [ cmake ninja swift ];
39 buildInputs = [ icu libxml2 curl ];
40 propagatedBuildInputs = [ Dispatch ];
41
42 preConfigure = ''
43 # Fails to build with -D_FORTIFY_SOURCE.
44 NIX_HARDENING_ENABLE=''${NIX_HARDENING_ENABLE/fortify/}
45 '';
46
47 postInstall = ''
48 # Split up the output.
49 mkdir $dev
50 mv $out/lib/swift/${swift.swiftOs} $out/swiftlibs
51 mv $out/lib/swift $dev/include
52 mkdir $out/lib/swift
53 mv $out/swiftlibs $out/lib/swift/${swift.swiftOs}
54
55 # Provide a CMake module. This is primarily used to glue together parts of
56 # the Swift toolchain. Modifying the CMake config to do this for us is
57 # otherwise more trouble.
58 mkdir -p $dev/lib/cmake/Foundation
59 export dylibExt="${stdenv.hostPlatform.extensions.sharedLibrary}"
60 export swiftOs="${swift.swiftOs}"
61 substituteAll ${./glue.cmake} $dev/lib/cmake/Foundation/FoundationConfig.cmake
62 '';
63
64 meta = {
65 description = "Core utilities, internationalization, and OS independence for Swift";
66 homepage = "https://github.com/apple/swift-corelibs-foundation";
67 platforms = lib.platforms.linux;
68 license = lib.licenses.asl20;
69 maintainers = with lib.maintainers; [ dtzWill trepetti dduan trundle stephank ];
70 };
71}