2023-02-02 18:25:31 +00:00
|
|
|
{ lib
|
|
|
|
, pkgs
|
|
|
|
, newScope
|
|
|
|
, darwin
|
2023-05-24 13:37:59 +00:00
|
|
|
, llvmPackages_15
|
2023-02-02 18:25:31 +00:00
|
|
|
, overrideCC
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2023-02-02 18:25:31 +00:00
|
|
|
self = rec {
|
2022-02-10 20:34:41 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
callPackage = newScope self;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
# Current versions of Swift on Darwin require macOS SDK 10.15 at least.
|
|
|
|
# Re-export this so we can rely on the minimum Swift SDK elsewhere.
|
|
|
|
apple_sdk = pkgs.darwin.apple_sdk_11_0;
|
2021-08-22 07:53:02 +00:00
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
# Swift builds its own Clang for internal use. We wrap that clang with a
|
|
|
|
# cc-wrapper derived from the clang configured below. Because cc-wrapper
|
|
|
|
# applies a specific resource-root, the two versions are best matched, or
|
|
|
|
# we'll often run into compilation errors.
|
2023-02-02 18:25:31 +00:00
|
|
|
#
|
2023-05-24 13:37:59 +00:00
|
|
|
# The following selects the correct Clang version, matching the version
|
|
|
|
# used in Swift, and applies the same libc overrides as `apple_sdk.stdenv`.
|
2023-02-02 18:25:31 +00:00
|
|
|
clang = if pkgs.stdenv.isDarwin
|
|
|
|
then
|
2023-05-24 13:37:59 +00:00
|
|
|
llvmPackages_15.clang.override rec {
|
2023-02-02 18:25:31 +00:00
|
|
|
libc = apple_sdk.Libsystem;
|
|
|
|
bintools = pkgs.bintools.override { inherit libc; };
|
|
|
|
}
|
|
|
|
else
|
2023-05-24 13:37:59 +00:00
|
|
|
llvmPackages_15.clang;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
# Overrides that create a useful environment for swift packages, allowing
|
|
|
|
# packaging with `swiftPackages.callPackage`. These are similar to
|
|
|
|
# `apple_sdk_11_0.callPackage`, with our clang on top.
|
|
|
|
inherit (clang) bintools;
|
|
|
|
stdenv = overrideCC pkgs.stdenv clang;
|
|
|
|
darwin = pkgs.darwin.overrideScope (_: prev: {
|
|
|
|
inherit apple_sdk;
|
|
|
|
inherit (apple_sdk) Libsystem LibsystemCross libcharset libunwind objc4 configd IOKit Security;
|
|
|
|
CF = apple_sdk.CoreFoundation;
|
|
|
|
});
|
|
|
|
xcodebuild = pkgs.xcbuild.override {
|
|
|
|
inherit (apple_sdk.frameworks) CoreServices CoreGraphics ImageIO;
|
|
|
|
inherit stdenv;
|
|
|
|
sdkVer = "10.15";
|
2022-09-09 14:08:57 +00:00
|
|
|
};
|
2023-02-02 18:25:31 +00:00
|
|
|
xcbuild = xcodebuild;
|
2022-09-09 14:08:57 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
swift-unwrapped = callPackage ./compiler {
|
|
|
|
inherit (darwin) DarwinTools cctools sigtool;
|
|
|
|
inherit (apple_sdk) MacOSX-SDK CLTools_Executables;
|
|
|
|
inherit (apple_sdk.frameworks) CoreServices Foundation Combine;
|
2022-02-10 20:34:41 +00:00
|
|
|
};
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
swiftNoSwiftDriver = callPackage ./wrapper {
|
|
|
|
swift = swift-unwrapped;
|
|
|
|
useSwiftDriver = false;
|
2022-09-09 14:08:57 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
Dispatch = if stdenv.isDarwin
|
|
|
|
then null # part of libsystem
|
|
|
|
else callPackage ./libdispatch { swift = swiftNoSwiftDriver; };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
Foundation = if stdenv.isDarwin
|
|
|
|
then apple_sdk.frameworks.Foundation
|
|
|
|
else callPackage ./foundation { swift = swiftNoSwiftDriver; };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
# TODO: Apple distributes a binary XCTest with Xcode, but it is not part of
|
|
|
|
# CLTools (or SUS), so would have to figure out how to fetch it. The binary
|
|
|
|
# version has several extra features, like a test runner and ObjC support.
|
|
|
|
XCTest = callPackage ./xctest {
|
|
|
|
inherit (darwin) DarwinTools;
|
|
|
|
swift = swiftNoSwiftDriver;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
swiftpm = callPackage ./swiftpm {
|
|
|
|
inherit (darwin) DarwinTools cctools;
|
|
|
|
inherit (apple_sdk.frameworks) CryptoKit LocalAuthentication;
|
|
|
|
swift = swiftNoSwiftDriver;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
swift-driver = callPackage ./swift-driver {
|
|
|
|
swift = swiftNoSwiftDriver;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
swift = callPackage ./wrapper {
|
|
|
|
swift = swift-unwrapped;
|
|
|
|
};
|
2021-08-22 07:53:02 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
sourcekit-lsp = callPackage ./sourcekit-lsp {
|
|
|
|
inherit (apple_sdk.frameworks) CryptoKit LocalAuthentication;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
swift-docc = callPackage ./swift-docc {
|
|
|
|
inherit (apple_sdk.frameworks) CryptoKit LocalAuthentication;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
swift-format = callPackage ./swift-format { };
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2023-02-02 18:25:31 +00:00
|
|
|
|
|
|
|
in self
|