1{
2 lib,
3 stdenv,
4 callPackage,
5 fetchpatch,
6 pkg-config,
7 swift,
8 swiftpm,
9 swiftpm2nix,
10 Foundation,
11 XCTest,
12 sqlite,
13 ncurses,
14}:
15let
16 sources = callPackage ../sources.nix { };
17 generated = swiftpm2nix.helpers ./generated;
18
19 # On Darwin, we only want ncurses in the linker search path, because headers
20 # are part of libsystem. Adding its headers to the search path causes strange
21 # mixing and errors.
22 # TODO: Find a better way to prevent this conflict.
23 ncursesInput = if stdenv.hostPlatform.isDarwin then ncurses.out else ncurses;
24in
25stdenv.mkDerivation {
26 pname = "sourcekit-lsp";
27
28 inherit (sources) version;
29 src = sources.sourcekit-lsp;
30
31 nativeBuildInputs = [
32 pkg-config
33 swift
34 swiftpm
35 ];
36 buildInputs = [
37 Foundation
38 XCTest
39 sqlite
40 ncursesInput
41 ];
42
43 configurePhase = generated.configure + ''
44 swiftpmMakeMutable indexstore-db
45 patch -p1 -d .build/checkouts/indexstore-db -i ${./patches/indexstore-db-macos-target.patch}
46 patch -p1 -d .build/checkouts/indexstore-db -i ${
47 # Fix the build with modern Clang.
48 fetchpatch {
49 url = "https://github.com/swiftlang/indexstore-db/commit/6120b53b1e8774ef4e2ad83438d4d94961331e72.patch";
50 hash = "sha256-tMAfTIa3RKiA/jDtP02mHcpPaF2s9a+3q/PLJxqn30M=";
51 }
52 }
53
54 swiftpmMakeMutable swift-tools-support-core
55 patch -p1 -d .build/checkouts/swift-tools-support-core -i ${
56 fetchpatch {
57 url = "https://github.com/apple/swift-tools-support-core/commit/990afca47e75cce136d2f59e464577e68a164035.patch";
58 hash = "sha256-PLzWsp+syiUBHhEFS8+WyUcSae5p0Lhk7SSRdNvfouE=";
59 includes = [ "Sources/TSCBasic/FileSystem.swift" ];
60 }
61 }
62
63 # This toggles a section specific to Xcode XCTest, which doesn't work on
64 # Darwin, where we also use swift-corelibs-xctest.
65 substituteInPlace Sources/LSPTestSupport/PerfTestCase.swift \
66 --replace '#if os(macOS)' '#if false'
67
68 # Required to link with swift-corelibs-xctest on Darwin.
69 export SWIFTTSC_MACOS_DEPLOYMENT_TARGET=10.12
70 '';
71
72 # TODO: BuildServerBuildSystemTests fails
73 #doCheck = true;
74
75 installPhase = ''
76 binPath="$(swiftpmBinPath)"
77 mkdir -p $out/bin
78 cp $binPath/sourcekit-lsp $out/bin/
79 '';
80
81 # Canary to verify output of our Swift toolchain does not depend on the Swift
82 # compiler itself. (Only its 'lib' output.)
83 disallowedRequisites = [ swift.swift ];
84
85 meta = {
86 description = "Language Server Protocol implementation for Swift and C-based languages";
87 mainProgram = "sourcekit-lsp";
88 homepage = "https://github.com/apple/sourcekit-lsp";
89 platforms = with lib.platforms; linux ++ darwin;
90 license = lib.licenses.asl20;
91 teams = [ lib.teams.swift ];
92 };
93}