about summary refs log tree commit diff
path: root/pkgs/development/compilers/swift/wrapper
diff options
context:
space:
mode:
authorStéphan Kochen <git@stephank.nl>2022-08-26 08:09:17 +0200
committerStéphan Kochen <git@stephank.nl>2022-10-10 21:26:50 +0200
commitdcb0eaf66d3ad5f1826a8c6b629b6cb3afb42603 (patch)
tree934118aea445fd87e244d1576685f52d2667c9e4 /pkgs/development/compilers/swift/wrapper
parentece9224c8a6e9099306e8a0afc85d917e0f14066 (diff)
swift-driver: init at 5.7
Diffstat (limited to 'pkgs/development/compilers/swift/wrapper')
-rw-r--r--pkgs/development/compilers/swift/wrapper/default.nix13
-rw-r--r--pkgs/development/compilers/swift/wrapper/wrapper.sh25
2 files changed, 36 insertions, 2 deletions
diff --git a/pkgs/development/compilers/swift/wrapper/default.nix b/pkgs/development/compilers/swift/wrapper/default.nix
index f244af13fcba2..f1c7198e0f3d5 100644
--- a/pkgs/development/compilers/swift/wrapper/default.nix
+++ b/pkgs/development/compilers/swift/wrapper/default.nix
@@ -1,6 +1,8 @@
-{ stdenv
+{ lib
+, stdenv
 , swift
 , wrapperParams ? swift._wrapperParams
+, useSwiftDriver ? true, swift-driver
 }:
 
 stdenv.mkDerivation (wrapperParams // {
@@ -9,12 +11,14 @@ stdenv.mkDerivation (wrapperParams // {
 
   outputs = [ "out" "man" ];
 
-  # Setup hook variables.
+  # Wrapper and setup hook variables.
   inherit swift;
   inherit (swift)
     swiftOs swiftArch
     swiftModuleSubdir swiftLibSubdir
     swiftStaticModuleSubdir swiftStaticLibSubdir;
+  swiftDriver = if useSwiftDriver
+    then "${swift-driver}/bin/swift-driver" else "";
 
   passAsFile = [ "buildCommand" ];
   buildCommand = ''
@@ -33,6 +37,11 @@ stdenv.mkDerivation (wrapperParams // {
       chmod a+x $out/bin/$executable
     done
 
+    ${lib.optionalString useSwiftDriver ''
+    # Symlink swift-driver executables.
+    ln -s -t $out/bin/ ${swift-driver}/bin/*
+    ''}
+
     ln -s ${swift.man} $man
 
     # This link is here because various tools (swiftpm) check for stdlib
diff --git a/pkgs/development/compilers/swift/wrapper/wrapper.sh b/pkgs/development/compilers/swift/wrapper/wrapper.sh
index dd08355903963..0c56e63b6f29e 100644
--- a/pkgs/development/compilers/swift/wrapper/wrapper.sh
+++ b/pkgs/development/compilers/swift/wrapper/wrapper.sh
@@ -63,6 +63,31 @@ case "$firstArg" in
         ;;
 esac
 
+# For many tasks, Swift reinvokes swift-driver, the new driver implementation
+# written in Swift. It needs some help finding the executable, though, and
+# reimplementing the logic here is little effort. These checks follow
+# `shouldDisallowNewDriver`.
+if [[
+    $isFrontend = 0 &&
+    -n "@swiftDriver@" &&
+    -z "${SWIFT_USE_OLD_DRIVER:-}" &&
+    ( "$progName" == "swift" || "$progName" == "swiftc" )
+]]; then
+    prog=@swiftDriver@
+    # Driver mode must be the very first argument.
+    extraBefore+=( "--driver-mode=$progName" )
+    if [[ $isRepl = 1 ]]; then
+        extraBefore+=( "-repl" )
+    fi
+
+    # Ensure swift-driver invokes the unwrapped frontend (instead of finding
+    # the wrapped one via PATH), because we don't have to wrap a second time.
+    export SWIFT_DRIVER_SWIFT_FRONTEND_EXEC="@swift@/bin/swift-frontend"
+
+    # Ensure swift-driver can find the LLDB with Swift support for the REPL.
+    export SWIFT_DRIVER_LLDB_EXEC="@swift@/bin/lldb"
+fi
+
 path_backup="$PATH"
 
 # That @-vars are substituted separately from bash evaluation makes