about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStéphan Kochen <git@stephank.nl>2022-07-25 21:45:15 +0200
committerStéphan Kochen <git@stephank.nl>2022-10-10 21:26:50 +0200
commit0b877d85e53de20a64e79e868bdcfff1ddac442a (patch)
tree24f6a582cd70a2774da58ead2d269f488832e796
parent89f979085894124912f152dc8db11076518e66ac (diff)
swiftPackages.XCTest: init at 5.7
-rw-r--r--pkgs/development/compilers/swift/default.nix7
-rw-r--r--pkgs/development/compilers/swift/xctest/default.nix59
2 files changed, 66 insertions, 0 deletions
diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix
index e2c9207e6da72..ce20f3a0e8134 100644
--- a/pkgs/development/compilers/swift/default.nix
+++ b/pkgs/development/compilers/swift/default.nix
@@ -65,6 +65,13 @@ let
       then apple_sdk.frameworks.Foundation
       else callPackage ./foundation { };
 
+    # 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;
+    };
+
   };
 
 in self
diff --git a/pkgs/development/compilers/swift/xctest/default.nix b/pkgs/development/compilers/swift/xctest/default.nix
new file mode 100644
index 0000000000000..9fa8c02b4dc28
--- /dev/null
+++ b/pkgs/development/compilers/swift/xctest/default.nix
@@ -0,0 +1,59 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, cmake
+, ninja
+, swift
+, Foundation
+, DarwinTools
+}:
+
+stdenv.mkDerivation rec {
+  pname = "swift-corelibs-xctest";
+
+  # Releases are made as part of the Swift toolchain, so versions should match.
+  version = "5.7";
+  src = fetchFromGitHub {
+    owner = "apple";
+    repo = "swift-corelibs-xctest";
+    rev = "swift-${version}-RELEASE";
+    hash = "sha256-qLUO9/3tkJWorDMEHgHd8VC3ovLLq/UWXJWMtb6CMN0=";
+  };
+
+  outputs = [ "out" ];
+
+  nativeBuildInputs = [ cmake ninja swift ]
+    ++ lib.optional stdenv.isDarwin DarwinTools; # sw_vers
+  buildInputs = [ Foundation ];
+
+  postPatch = lib.optionalString stdenv.isDarwin ''
+    # On Darwin only, Swift uses arm64 as cpu arch.
+    substituteInPlace cmake/modules/SwiftSupport.cmake \
+      --replace '"aarch64" PARENT_SCOPE' '"arm64" PARENT_SCOPE'
+  '';
+
+  preConfigure = ''
+    # On aarch64-darwin, our minimum target is 11.0, but we can target lower,
+    # and some dependants require a lower target. Harmless on non-Darwin.
+    export MACOSX_DEPLOYMENT_TARGET=10.12
+  '';
+
+  cmakeFlags = lib.optional stdenv.isDarwin "-DUSE_FOUNDATION_FRAMEWORK=ON";
+
+  postInstall = lib.optionalString stdenv.isDarwin ''
+    # Darwin normally uses the Xcode version of XCTest. Installing
+    # swift-corelibs-xctest is probably not officially supported, but we have
+    # no alternative. Fix up the installation here.
+    mv $out/lib/swift/darwin/${swift.swiftArch}/* $out/lib/swift/darwin
+    rmdir $out/lib/swift/darwin/${swift.swiftArch}
+    mv $out/lib/swift/darwin $out/lib/swift/${swift.swiftOs}
+  '';
+
+  meta = {
+    description = "Framework for writing unit tests in Swift";
+    homepage = "https://github.com/apple/swift-corelibs-xctest";
+    platforms = lib.platforms.all;
+    license = lib.licenses.asl20;
+    maintainers = with lib.maintainers; [ dtzWill trepetti dduan trundle stephank ];
+  };
+}