diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix index 845b91158495..83627130d405 100644 --- a/pkgs/development/compilers/swift/default.nix +++ b/pkgs/development/compilers/swift/default.nix @@ -88,6 +88,10 @@ let swift = swift-unwrapped; }; + sourcekit-lsp = callPackage ./sourcekit-lsp { + inherit (apple_sdk.frameworks) CryptoKit LocalAuthentication; + }; + }; in self diff --git a/pkgs/development/compilers/swift/sourcekit-lsp/default.nix b/pkgs/development/compilers/swift/sourcekit-lsp/default.nix new file mode 100644 index 000000000000..bf013a8f6e8e --- /dev/null +++ b/pkgs/development/compilers/swift/sourcekit-lsp/default.nix @@ -0,0 +1,74 @@ +{ lib +, stdenv +, callPackage +, fetchFromGitHub +, swift +, swiftpm +, Foundation +, XCTest +, sqlite +, ncurses +, CryptoKit +, LocalAuthentication +}: +let + # Generated by swiftpm2nix. + generated = callPackage ./generated { }; + + # On Darwin, we only want ncurses in the linker search path, because headers + # are part of libsystem. Adding its headers to the search path causes strange + # mixing and errors. + # TODO: Find a better way to prevent this conflict. + ncursesInput = if stdenv.isDarwin then ncurses.out else ncurses; +in +stdenv.mkDerivation rec { + pname = "sourcekit-lsp"; + + # Releases are made as part of the Swift toolchain, so versions should match. + version = "5.7"; + src = fetchFromGitHub { + owner = "apple"; + repo = "sourcekit-lsp"; + rev = "swift-${version}-RELEASE"; + hash = "sha256-uA3a+kAqI+XFzkDFEJ8XuRTgfYqacEuTsOU289Im+0Y="; + }; + + nativeBuildInputs = [ swift swiftpm ]; + buildInputs = [ + Foundation + XCTest + sqlite + ncursesInput + ] + ++ lib.optionals stdenv.isDarwin [ CryptoKit LocalAuthentication ]; + + configurePhase = generated.configure + '' + swiftpmMakeMutable indexstore-db + patch -p1 -d .build/checkouts/indexstore-db -i ${./patches/indexstore-db-macos-target.patch} + + # This toggles a section specific to Xcode XCTest, which doesn't work on + # Darwin, where we also use swift-corelibs-xctest. + substituteInPlace Sources/LSPTestSupport/PerfTestCase.swift \ + --replace '#if os(macOS)' '#if false' + + # Required to link with swift-corelibs-xctest on Darwin. + export SWIFTTSC_MACOS_DEPLOYMENT_TARGET=10.12 + ''; + + # TODO: BuildServerBuildSystemTests fails + #doCheck = true; + + installPhase = '' + binPath="$(swiftpmBinPath)" + mkdir -p $out/bin + cp $binPath/sourcekit-lsp $out/bin/ + ''; + + meta = { + description = "Language Server Protocol implementation for Swift and C-based languages"; + homepage = "https://github.com/apple/sourcekit-lsp"; + platforms = with lib.platforms; linux ++ darwin; + license = lib.licenses.asl20; + maintainers = with lib.maintainers; [ dtzWill trepetti dduan trundle stephank ]; + }; +} diff --git a/pkgs/development/compilers/swift/sourcekit-lsp/generated/Package.resolved b/pkgs/development/compilers/swift/sourcekit-lsp/generated/Package.resolved new file mode 100644 index 000000000000..00f079308773 --- /dev/null +++ b/pkgs/development/compilers/swift/sourcekit-lsp/generated/Package.resolved @@ -0,0 +1,97 @@ +{ + "object": { + "pins": [ + { + "package": "IndexStoreDB", + "repositoryURL": "https://github.com/apple/indexstore-db.git", + "state": { + "branch": "main", + "revision": "2ff1c0491248cd958a2ac05da9aa613eb27a8eeb", + "version": null + } + }, + { + "package": "swift-argument-parser", + "repositoryURL": "https://github.com/apple/swift-argument-parser.git", + "state": { + "branch": null, + "revision": "e394bf350e38cb100b6bc4172834770ede1b7232", + "version": "1.0.3" + } + }, + { + "package": "swift-collections", + "repositoryURL": "https://github.com/apple/swift-collections.git", + "state": { + "branch": null, + "revision": "f504716c27d2e5d4144fa4794b12129301d17729", + "version": "1.0.3" + } + }, + { + "package": "swift-crypto", + "repositoryURL": "https://github.com/apple/swift-crypto.git", + "state": { + "branch": null, + "revision": "ddb07e896a2a8af79512543b1c7eb9797f8898a5", + "version": "1.1.7" + } + }, + { + "package": "swift-driver", + "repositoryURL": "https://github.com/apple/swift-driver.git", + "state": { + "branch": "main", + "revision": "6c71f58f89d65eb79f1f6b32a707ddc39cec5ad6", + "version": null + } + }, + { + "package": "llbuild", + "repositoryURL": "https://github.com/apple/swift-llbuild.git", + "state": { + "branch": "main", + "revision": "d99c31577c60a247b065d29289a44fbdd141e2be", + "version": null + } + }, + { + "package": "SwiftPM", + "repositoryURL": "https://github.com/apple/swift-package-manager.git", + "state": { + "branch": "main", + "revision": "f04ad469a6053d713c2fb854fbeb27ee3e6c9dee", + "version": null + } + }, + { + "package": "swift-system", + "repositoryURL": "https://github.com/apple/swift-system.git", + "state": { + "branch": null, + "revision": "836bc4557b74fe6d2660218d56e3ce96aff76574", + "version": "1.1.1" + } + }, + { + "package": "swift-tools-support-core", + "repositoryURL": "https://github.com/apple/swift-tools-support-core.git", + "state": { + "branch": "main", + "revision": "0220fc394f2ae820eeacd754fb2c7ce211e9979e", + "version": null + } + }, + { + "package": "Yams", + "repositoryURL": "https://github.com/jpsim/Yams.git", + "state": { + "branch": null, + "revision": "01835dc202670b5bb90d07f3eae41867e9ed29f6", + "version": "5.0.1" + } + } + ] + }, + "version": 1 +} diff --git a/pkgs/development/compilers/swift/sourcekit-lsp/generated/default.nix b/pkgs/development/compilers/swift/sourcekit-lsp/generated/default.nix new file mode 100644 index 000000000000..c7ce2361b8bf --- /dev/null +++ b/pkgs/development/compilers/swift/sourcekit-lsp/generated/default.nix @@ -0,0 +1,72 @@ +# This file was generated by swiftpm2nix. +{ lib, fetchgit }: rec { + sources = { + "indexstore-db" = fetchgit { + url = "https://github.com/apple/indexstore-db.git"; + rev = "2ff1c0491248cd958a2ac05da9aa613eb27a8eeb"; + sha256 = "005vvkrncgpryzrn0hzgsapflpyga0n7152b2b565wislpx90cwl"; + }; + "swift-argument-parser" = fetchgit { + url = "https://github.com/apple/swift-argument-parser.git"; + rev = "e394bf350e38cb100b6bc4172834770ede1b7232"; + sha256 = "1jph9w7lk9nr20fsv2c8p4hisx3dda817fh7pybd0r0j1jwa9nmw"; + }; + "swift-collections" = fetchgit { + url = "https://github.com/apple/swift-collections.git"; + rev = "f504716c27d2e5d4144fa4794b12129301d17729"; + sha256 = "0l0pv16zil3n7fac7mdf5qxklxr5rwiig5bixgca1ybq7arlnv7i"; + }; + "swift-crypto" = fetchgit { + url = "https://github.com/apple/swift-crypto.git"; + rev = "ddb07e896a2a8af79512543b1c7eb9797f8898a5"; + sha256 = "020b8q4ss2k7a65r5dgh59z40i6sn7ij1allxkh8c8a9d0jzn313"; + }; + "swift-driver" = fetchgit { + url = "https://github.com/apple/swift-driver.git"; + rev = "6c71f58f89d65eb79f1f6b32a707ddc39cec5ad6"; + sha256 = "0nblvs47kh2hl1l70rmrbablx4m5i27w8l3dfrv2h7zccqr8jl0a"; + }; + "swift-llbuild" = fetchgit { + url = "https://github.com/apple/swift-llbuild.git"; + rev = "d99c31577c60a247b065d29289a44fbdd141e2be"; + sha256 = "1bvqbj8ji72ilh3ah2mw411jwzbbjxjyasa6sg4b8da0kqia4021"; + }; + "swift-package-manager" = fetchgit { + url = "https://github.com/apple/swift-package-manager.git"; + rev = "f04ad469a6053d713c2fb854fbeb27ee3e6c9dee"; + sha256 = "16qvk14f1l0hf5bphx6qk51nn9d36a2iw5v3sgkvmqi8h7l4kqg5"; + }; + "swift-system" = fetchgit { + url = "https://github.com/apple/swift-system.git"; + rev = "836bc4557b74fe6d2660218d56e3ce96aff76574"; + sha256 = "0402hkx2q2dv27gccnn8ma79ngvwiwzkhcv4zlcdldmy6cgi0px7"; + }; + "swift-tools-support-core" = fetchgit { + url = "https://github.com/apple/swift-tools-support-core.git"; + rev = "0220fc394f2ae820eeacd754fb2c7ce211e9979e"; + sha256 = "1ryd5iyx5mfv8bhyq3bf08z7nv886chzzqnmwaj16r2cry9yml7c"; + }; + "Yams" = fetchgit { + url = "https://github.com/jpsim/Yams.git"; + rev = "01835dc202670b5bb90d07f3eae41867e9ed29f6"; + sha256 = "11abhcfkmqm3cmh7vp7rqzvxd1zj02j2866a2pp6v9m89456xb76"; + }; + }; + configure = '' + mkdir -p .build/checkouts + ln -sf ${./Package.resolved} ./Package.resolved + install -m 0600 ${./workspace-state.json} ./.build/workspace-state.json + '' + + lib.concatStrings (lib.mapAttrsToList (name: src: '' + ln -s '${src}' '.build/checkouts/${name}' + '') sources) + + '' + # Helper that makes a swiftpm dependency mutable by copying the source. + swiftpmMakeMutable() { + local orig="$(readlink .build/checkouts/$1)" + rm .build/checkouts/$1 + cp -r "$orig" .build/checkouts/$1 + chmod -R u+w .build/checkouts/$1 + } + ''; +} diff --git a/pkgs/development/compilers/swift/sourcekit-lsp/generated/workspace-state.json b/pkgs/development/compilers/swift/sourcekit-lsp/generated/workspace-state.json new file mode 100644 index 000000000000..4e8625ed0d6a --- /dev/null +++ b/pkgs/development/compilers/swift/sourcekit-lsp/generated/workspace-state.json @@ -0,0 +1,178 @@ +{ + "object": { + "artifacts": [], + "dependencies": [ + { + "basedOn": null, + "packageRef": { + "identity": "indexstore-db", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/indexstore-db.git", + "name": "IndexStoreDB" + }, + "state": { + "checkoutState": { + "branch": "main", + "revision": "2ff1c0491248cd958a2ac05da9aa613eb27a8eeb" + }, + "name": "sourceControlCheckout" + }, + "subpath": "indexstore-db" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-argument-parser", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-argument-parser.git", + "name": "swift-argument-parser" + }, + "state": { + "checkoutState": { + "revision": "e394bf350e38cb100b6bc4172834770ede1b7232", + "version": "1.0.3" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-argument-parser" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-collections", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-collections.git", + "name": "swift-collections" + }, + "state": { + "checkoutState": { + "revision": "f504716c27d2e5d4144fa4794b12129301d17729", + "version": "1.0.3" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-collections" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-crypto", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-crypto.git", + "name": "swift-crypto" + }, + "state": { + "checkoutState": { + "revision": "ddb07e896a2a8af79512543b1c7eb9797f8898a5", + "version": "1.1.7" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-crypto" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-driver", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-driver.git", + "name": "swift-driver" + }, + "state": { + "checkoutState": { + "branch": "main", + "revision": "6c71f58f89d65eb79f1f6b32a707ddc39cec5ad6" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-driver" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-llbuild", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-llbuild.git", + "name": "llbuild" + }, + "state": { + "checkoutState": { + "branch": "main", + "revision": "d99c31577c60a247b065d29289a44fbdd141e2be" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-llbuild" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-package-manager", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-package-manager.git", + "name": "SwiftPM" + }, + "state": { + "checkoutState": { + "branch": "main", + "revision": "f04ad469a6053d713c2fb854fbeb27ee3e6c9dee" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-package-manager" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-system", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-system.git", + "name": "swift-system" + }, + "state": { + "checkoutState": { + "revision": "836bc4557b74fe6d2660218d56e3ce96aff76574", + "version": "1.1.1" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-system" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-tools-support-core", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-tools-support-core.git", + "name": "swift-tools-support-core" + }, + "state": { + "checkoutState": { + "branch": "main", + "revision": "0220fc394f2ae820eeacd754fb2c7ce211e9979e" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-tools-support-core" + }, + { + "basedOn": null, + "packageRef": { + "identity": "yams", + "kind": "remoteSourceControl", + "location": "https://github.com/jpsim/Yams.git", + "name": "Yams" + }, + "state": { + "checkoutState": { + "revision": "01835dc202670b5bb90d07f3eae41867e9ed29f6", + "version": "5.0.1" + }, + "name": "sourceControlCheckout" + }, + "subpath": "Yams" + } + ] + }, + "version": 5 +} diff --git a/pkgs/development/compilers/swift/sourcekit-lsp/patches/indexstore-db-macos-target.patch b/pkgs/development/compilers/swift/sourcekit-lsp/patches/indexstore-db-macos-target.patch new file mode 100644 index 000000000000..53e790874d5d --- /dev/null +++ b/pkgs/development/compilers/swift/sourcekit-lsp/patches/indexstore-db-macos-target.patch @@ -0,0 +1,12 @@ +Raise the deployment target of IndexStoreDB so it can link against our XCTest. + +--- a/Package.swift ++++ b/Package.swift +@@ -4,6 +4,7 @@ import PackageDescription + + let package = Package( + name: "IndexStoreDB", ++ platforms: [.macOS("10.12")], + products: [ + .library( + name: "IndexStoreDB", diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 21c57e3e5480..069dd19ffec0 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15042,7 +15042,7 @@ with pkgs; svdtools = callPackage ../development/embedded/svdtools { }; swiftPackages = recurseIntoAttrs (callPackage ../development/compilers/swift { }); - inherit (swiftPackages) swift swiftpm; + inherit (swiftPackages) swift swiftpm sourcekit-lsp; swiftpm2nix = callPackage ../development/tools/swiftpm2nix { };