about summary refs log tree commit diff
path: root/pkgs/development/compilers/swift/swiftpm
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/compilers/swift/swiftpm')
-rw-r--r--pkgs/development/compilers/swift/swiftpm/default.nix15
-rw-r--r--pkgs/development/compilers/swift/swiftpm/patches/force-unwrap-file-handles.patch33
2 files changed, 13 insertions, 35 deletions
diff --git a/pkgs/development/compilers/swift/swiftpm/default.nix b/pkgs/development/compilers/swift/swiftpm/default.nix
index 4a7a4ab63cced..2f3cb9530cfe5 100644
--- a/pkgs/development/compilers/swift/swiftpm/default.nix
+++ b/pkgs/development/compilers/swift/swiftpm/default.nix
@@ -1,6 +1,7 @@
 { lib
 , stdenv
 , callPackage
+, fetchpatch
 , cmake
 , ninja
 , git
@@ -195,12 +196,22 @@ let
       '';
   };
 
+  # Part of this patch fixes for glibc 2.39: glibc patch 64b1a44183a3094672ed304532bedb9acc707554
+  # marks the `FILE*` argument to a few functions including `ferror` & `fread` as non-null. However
+  # the code passes an `Optional<T>` to these functions.
+  # This patch uses a `guard` which effectively unwraps the type (or throws an exception).
+  swift-tools-support-core-glibc-fix = fetchpatch {
+    url = "https://github.com/apple/swift-tools-support-core/commit/990afca47e75cce136d2f59e464577e68a164035.patch";
+    hash = "sha256-PLzWsp+syiUBHhEFS8+WyUcSae5p0Lhk7SSRdNvfouE=";
+    includes = [ "Sources/TSCBasic/FileSystem.swift" ];
+  };
+
   swift-tools-support-core = mkBootstrapDerivation {
     name = "swift-tools-support-core";
     src = generated.sources.swift-tools-support-core;
 
     patches = [
-      ./patches/force-unwrap-file-handles.patch
+      swift-tools-support-core-glibc-fix
     ];
 
     buildInputs = [
@@ -389,7 +400,7 @@ in stdenv.mkDerivation (commonAttrs // {
     swiftpmMakeMutable swift-tools-support-core
     substituteInPlace .build/checkouts/swift-tools-support-core/Sources/TSCTestSupport/XCTestCasePerf.swift \
       --replace 'canImport(Darwin)' 'false'
-    patch -p1 -d .build/checkouts/swift-tools-support-core -i ${./patches/force-unwrap-file-handles.patch}
+    patch -p1 -d .build/checkouts/swift-tools-support-core -i ${swift-tools-support-core-glibc-fix}
 
     # Prevent a warning about SDK directories we don't have.
     swiftpmMakeMutable swift-driver
diff --git a/pkgs/development/compilers/swift/swiftpm/patches/force-unwrap-file-handles.patch b/pkgs/development/compilers/swift/swiftpm/patches/force-unwrap-file-handles.patch
deleted file mode 100644
index a2f2d38c37c81..0000000000000
--- a/pkgs/development/compilers/swift/swiftpm/patches/force-unwrap-file-handles.patch
+++ /dev/null
@@ -1,33 +0,0 @@
-From 8d9ab4b6ed24a97e8af0cc338a52aacdcf438b8c Mon Sep 17 00:00:00 2001
-From: Pavel Sobolev <paveloom@riseup.net>
-Date: Tue, 21 Nov 2023 20:53:33 +0300
-Subject: [PATCH] Force-unwrap file handles.
-
----
- Sources/TSCBasic/FileSystem.swift | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/Sources/TSCBasic/FileSystem.swift b/Sources/TSCBasic/FileSystem.swift
-index 3a63bdf..a1f3d9d 100644
---- a/Sources/TSCBasic/FileSystem.swift
-+++ b/Sources/TSCBasic/FileSystem.swift
-@@ -425,7 +425,7 @@ private class LocalFileSystem: FileSystem {
-         if fp == nil {
-             throw FileSystemError(errno: errno, path)
-         }
--        defer { fclose(fp) }
-+        defer { fclose(fp!) }
-
-         // Read the data one block at a time.
-         let data = BufferedOutputByteStream()
-@@ -455,7 +455,7 @@ private class LocalFileSystem: FileSystem {
-         if fp == nil {
-             throw FileSystemError(errno: errno, path)
-         }
--        defer { fclose(fp) }
-+        defer { fclose(fp!) }
-
-         // Write the data in one chunk.
-         var contents = bytes.contents
---
-2.42.0