Files
nixpkgs/pkgs/development/compilers/swift/compiler/patches/swift-linux-fix-linking.patch
Emily 809f7d037c swiftPackages.swift{,-unwrapped,-driver}: ignore $NIX_CC
Swift needs Clang to link with. The linker patch breaks linking
when using Swift with a GCC‐based standard environment.

Similarly, the internal Clang headers in the resource directory are
coupled to the corresponding version of Clang. The resource root patch
caused Swift’s Clang to use the resource directory from the version
of Clang used in the build environment, which is only compatible if
the versions match.

Instead, hard‐code the Clang path in the patches and wrappers.
2025-09-02 04:09:46 +01:00

18 lines
634 B
Diff

diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index c0ee9217e8..bf7737d6fa 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -1489,6 +1489,12 @@
LinkerDriver = Args.MakeArgString(tool.get());
}
+ // For Nix, prefer linking using the wrapped Nixpkgs clang, instead of using
+ // the unwrapped clang packaged with swift. The latter is unable to link, but
+ // we still want to use it for other purposes (clang importer).
+ if (auto tool = llvm::sys::findProgramByName(LinkerDriver, {"@clang@/bin"}))
+ return Args.MakeArgString(tool.get());
+
return LinkerDriver;
}