swift-driver: init at 5.7

+1
pkgs/development/compilers/swift/compiler/default.nix
···
gnugrep_bin = gnugrep;
suffixSalt = lib.replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
use_response_file_by_default = 1;
+
swiftDriver = "";
# NOTE: @prog@ needs to be filled elsewhere.
};
swiftWrapper = runCommand "swift-wrapper.sh" wrapperParams ''
+14 -3
pkgs/development/compilers/swift/default.nix
···
inherit (apple_sdk.frameworks) CoreServices Foundation Combine;
};
-
swift = callPackage ./wrapper {
+
swiftNoSwiftDriver = callPackage ./wrapper {
swift = swift-unwrapped;
+
useSwiftDriver = false;
};
Dispatch = if stdenv.isDarwin
then null # part of libsystem
-
else callPackage ./libdispatch { };
+
else callPackage ./libdispatch { swift = swiftNoSwiftDriver; };
Foundation = if stdenv.isDarwin
then apple_sdk.frameworks.Foundation
-
else callPackage ./foundation { };
+
else callPackage ./foundation { swift = swiftNoSwiftDriver; };
# 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;
};
swiftpm = callPackage ./swiftpm {
inherit (darwin) DarwinTools cctools;
inherit (apple_sdk.frameworks) CryptoKit LocalAuthentication;
+
swift = swiftNoSwiftDriver;
+
};
+
+
swift-driver = callPackage ./swift-driver {
+
swift = swiftNoSwiftDriver;
+
};
+
+
swift = callPackage ./wrapper {
+
swift = swift-unwrapped;
};
};
+83
pkgs/development/compilers/swift/swift-driver/default.nix
···
+
{ lib
+
, stdenv
+
, callPackage
+
, fetchFromGitHub
+
, fetchpatch
+
, swift
+
, swiftpm
+
, Foundation
+
, XCTest
+
, sqlite
+
, ncurses
+
, substituteAll
+
}:
+
let
+
# Generated by swiftpm2nix.
+
generated = callPackage ./generated { };
+
+
# On Darwin, we only want ncurses in the linker search path, because headers
+
# are part of libsystem. Adding its headers to the search path causes strange
+
# mixing and errors.
+
# TODO: Find a better way to prevent this conflict.
+
ncursesInput = if stdenv.isDarwin then ncurses.out else ncurses;
+
in
+
stdenv.mkDerivation rec {
+
pname = "swift-driver";
+
+
# Releases are made as part of the Swift toolchain, so versions should match.
+
version = "5.7";
+
src = fetchFromGitHub {
+
owner = "apple";
+
repo = "swift-driver";
+
rev = "swift-${version}-RELEASE";
+
hash = "sha256-sk7XWXYR1MGPEeVxA6eA/vxhN6Gq16iD1RHpVstL3zE=";
+
};
+
+
nativeBuildInputs = [ swift swiftpm ];
+
buildInputs = [
+
Foundation
+
XCTest
+
sqlite
+
ncursesInput
+
];
+
+
patches = [
+
./patches/nix-resource-root.patch
+
./patches/disable-catalyst.patch
+
./patches/linux-fix-linking.patch
+
# TODO: Replace with branch patch once merged:
+
# https://github.com/apple/swift-driver/pull/1197
+
(fetchpatch {
+
url = "https://github.com/apple/swift-driver/commit/d3ef9cdf4871a58eddec7ff0e28fe611130da3f9.patch";
+
hash = "sha256-eVBaKN6uzj48ZnHtwGV0k5ChKjak1tDCyE+wTdyGq2c=";
+
})
+
# Prevent a warning about SDK directories we don't have.
+
(substituteAll {
+
src = ./patches/prevent-sdk-dirs-warnings.patch;
+
inherit (builtins) storeDir;
+
})
+
];
+
+
configurePhase = generated.configure;
+
+
# TODO: Tests depend on indexstore-db being provided by an existing Swift
+
# toolchain. (ie. looks for `../lib/libIndexStore.so` relative to swiftc.
+
#doCheck = true;
+
+
# TODO: Darwin-specific installation includes more, but not sure why.
+
installPhase = ''
+
binPath="$(swiftpmBinPath)"
+
mkdir -p $out/bin
+
for executable in swift-driver swift-help swift-build-sdk-interfaces; do
+
cp $binPath/$executable $out/bin/
+
done
+
'';
+
+
meta = {
+
description = "Swift compiler driver";
+
homepage = "https://github.com/apple/swift-driver";
+
platforms = with lib.platforms; linux ++ darwin;
+
license = lib.licenses.asl20;
+
maintainers = with lib.maintainers; [ dtzWill trepetti dduan trundle stephank ];
+
};
+
}
+52
pkgs/development/compilers/swift/swift-driver/generated/Package.resolved
···
+
{
+
"object": {
+
"pins": [
+
{
+
"package": "swift-argument-parser",
+
"repositoryURL": "https://github.com/apple/swift-argument-parser.git",
+
"state": {
+
"branch": null,
+
"revision": "e1465042f195f374b94f915ba8ca49de24300a0d",
+
"version": "1.0.2"
+
}
+
},
+
{
+
"package": "llbuild",
+
"repositoryURL": "https://github.com/apple/swift-llbuild.git",
+
"state": {
+
"branch": "release/5.7",
+
"revision": "564424db5fdb62dcb5d863bdf7212500ef03a87b",
+
"version": null
+
}
+
},
+
{
+
"package": "swift-system",
+
"repositoryURL": "https://github.com/apple/swift-system.git",
+
"state": {
+
"branch": null,
+
"revision": "836bc4557b74fe6d2660218d56e3ce96aff76574",
+
"version": "1.1.1"
+
}
+
},
+
{
+
"package": "swift-tools-support-core",
+
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
+
"state": {
+
"branch": "release/5.7",
+
"revision": "184eba382f6abbb362ffc02942d790ff35019ad4",
+
"version": null
+
}
+
},
+
{
+
"package": "Yams",
+
"repositoryURL": "https://github.com/jpsim/Yams.git",
+
"state": {
+
"branch": null,
+
"revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa",
+
"version": "4.0.6"
+
}
+
}
+
]
+
},
+
"version": 1
+
}
+47
pkgs/development/compilers/swift/swift-driver/generated/default.nix
···
+
# This file was generated by swiftpm2nix.
+
{ lib, fetchgit }: rec {
+
sources = {
+
"swift-argument-parser" = fetchgit {
+
url = "https://github.com/apple/swift-argument-parser.git";
+
rev = "e1465042f195f374b94f915ba8ca49de24300a0d";
+
sha256 = "11did5snqj8chcbdbiyx84mpif940ls2pr1iikwivvfp63i248hm";
+
};
+
"swift-llbuild" = fetchgit {
+
url = "https://github.com/apple/swift-llbuild.git";
+
rev = "564424db5fdb62dcb5d863bdf7212500ef03a87b";
+
sha256 = "07zbp2dyfqd1bnyg7snpr9brn40jf22ivly5v10mql3hrg76a18h";
+
};
+
"swift-system" = fetchgit {
+
url = "https://github.com/apple/swift-system.git";
+
rev = "836bc4557b74fe6d2660218d56e3ce96aff76574";
+
sha256 = "0402hkx2q2dv27gccnn8ma79ngvwiwzkhcv4zlcdldmy6cgi0px7";
+
};
+
"swift-tools-support-core" = fetchgit {
+
url = "https://github.com/apple/swift-tools-support-core.git";
+
rev = "184eba382f6abbb362ffc02942d790ff35019ad4";
+
sha256 = "005akmisnkcg6zjwm545183c12xm8z504yxxqmnqf0rakfcab1mi";
+
};
+
"Yams" = fetchgit {
+
url = "https://github.com/jpsim/Yams.git";
+
rev = "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa";
+
sha256 = "1893y13sis2aimi1a5kgkczbf06z4yig054xb565yg2xm13srb45";
+
};
+
};
+
configure = ''
+
mkdir -p .build/checkouts
+
ln -sf ${./Package.resolved} ./Package.resolved
+
install -m 0600 ${./workspace-state.json} ./.build/workspace-state.json
+
''
+
+ lib.concatStrings (lib.mapAttrsToList (name: src: ''
+
ln -s '${src}' '.build/checkouts/${name}'
+
'') sources)
+
+ ''
+
# Helper that makes a swiftpm dependency mutable by copying the source.
+
swiftpmMakeMutable() {
+
local orig="$(readlink .build/checkouts/$1)"
+
rm .build/checkouts/$1
+
cp -r "$orig" .build/checkouts/$1
+
chmod -R u+w .build/checkouts/$1
+
}
+
'';
+
}
+93
pkgs/development/compilers/swift/swift-driver/generated/workspace-state.json
···
+
{
+
"object": {
+
"artifacts": [],
+
"dependencies": [
+
{
+
"basedOn": null,
+
"packageRef": {
+
"identity": "swift-argument-parser",
+
"kind": "remoteSourceControl",
+
"location": "https://github.com/apple/swift-argument-parser.git",
+
"name": "swift-argument-parser"
+
},
+
"state": {
+
"checkoutState": {
+
"revision": "e1465042f195f374b94f915ba8ca49de24300a0d",
+
"version": "1.0.2"
+
},
+
"name": "sourceControlCheckout"
+
},
+
"subpath": "swift-argument-parser"
+
},
+
{
+
"basedOn": null,
+
"packageRef": {
+
"identity": "swift-llbuild",
+
"kind": "remoteSourceControl",
+
"location": "https://github.com/apple/swift-llbuild.git",
+
"name": "llbuild"
+
},
+
"state": {
+
"checkoutState": {
+
"branch": "release/5.7",
+
"revision": "564424db5fdb62dcb5d863bdf7212500ef03a87b"
+
},
+
"name": "sourceControlCheckout"
+
},
+
"subpath": "swift-llbuild"
+
},
+
{
+
"basedOn": null,
+
"packageRef": {
+
"identity": "swift-system",
+
"kind": "remoteSourceControl",
+
"location": "https://github.com/apple/swift-system.git",
+
"name": "swift-system"
+
},
+
"state": {
+
"checkoutState": {
+
"revision": "836bc4557b74fe6d2660218d56e3ce96aff76574",
+
"version": "1.1.1"
+
},
+
"name": "sourceControlCheckout"
+
},
+
"subpath": "swift-system"
+
},
+
{
+
"basedOn": null,
+
"packageRef": {
+
"identity": "swift-tools-support-core",
+
"kind": "remoteSourceControl",
+
"location": "https://github.com/apple/swift-tools-support-core.git",
+
"name": "swift-tools-support-core"
+
},
+
"state": {
+
"checkoutState": {
+
"branch": "release/5.7",
+
"revision": "184eba382f6abbb362ffc02942d790ff35019ad4"
+
},
+
"name": "sourceControlCheckout"
+
},
+
"subpath": "swift-tools-support-core"
+
},
+
{
+
"basedOn": null,
+
"packageRef": {
+
"identity": "yams",
+
"kind": "remoteSourceControl",
+
"location": "https://github.com/jpsim/Yams.git",
+
"name": "Yams"
+
},
+
"state": {
+
"checkoutState": {
+
"revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa",
+
"version": "4.0.6"
+
},
+
"name": "sourceControlCheckout"
+
},
+
"subpath": "Yams"
+
}
+
]
+
},
+
"version": 5
+
}
+17
pkgs/development/compilers/swift/swift-driver/patches/disable-catalyst.patch
···
+
Tries to parse SDKSettings.plist looking for a Catalyst version map, but we
+
don't currently support this.
+
+
--- a/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift
+
+++ b/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift
+
@@ -297,11 +297,7 @@ public final class DarwinToolchain: Toolchain {
+
debugDescription: "Malformed version string")
+
}
+
self.version = version
+
- if self.canonicalName.hasPrefix("macosx") {
+
- self.versionMap = try keyedContainer.decode(VersionMap.self, forKey: .versionMap)
+
- } else {
+
self.versionMap = VersionMap()
+
- }
+
}
+
+
+40
pkgs/development/compilers/swift/swift-driver/patches/linux-fix-linking.patch
···
+
--- a/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
+
+++ b/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
+
@@ -9,6 +9,7 @@
+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+
//
+
//===----------------------------------------------------------------------===//
+
+import Foundation
+
import TSCBasic
+
import SwiftOptions
+
+
@@ -116,7 +117,20 @@ extension GenericUnixToolchain {
+
// just using `clang` and avoid a dependency on the C++ runtime.
+
let clangTool: Tool =
+
parsedOptions.hasArgument(.enableExperimentalCxxInterop) ? .clangxx : .clang
+
- var clangPath = try getToolPath(clangTool)
+
+
+
+ // For Nix, prefer linking using the wrapped system 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).
+
+ var clangPath: AbsolutePath
+
+ let env = ProcessInfo.processInfo.environment
+
+ if let nixCC = env["NIX_CC"],
+
+ let binPath = try? AbsolutePath(validating: "\(nixCC)/bin"),
+
+ let tool = lookupExecutablePath(filename: parsedOptions.hasArgument(.enableExperimentalCxxInterop)
+
+ ? "clang++" : "clang",
+
+ searchPaths: [binPath]) {
+
+ clangPath = tool
+
+ } else {
+
+ clangPath = try getToolPath(clangTool)
+
if let toolsDirPath = parsedOptions.getLastArgument(.toolsDirectory) {
+
// FIXME: What if this isn't an absolute path?
+
let toolsDir = try AbsolutePath(validating: toolsDirPath.asSingle)
+
@@ -132,6 +146,7 @@ extension GenericUnixToolchain {
+
commandLine.appendFlag("-B")
+
commandLine.appendPath(toolsDir)
+
}
+
+ } // nixCC
+
+
// Executables on Linux get -pie
+
if targetTriple.os == .linux && linkerOutputType == .executable {
+28
pkgs/development/compilers/swift/swift-driver/patches/nix-resource-root.patch
···
+
Swift normally looks for the Clang resource dir in a subdir/symlink of its own
+
resource dir. We provide a symlink to the Swift build-time Clang as a default
+
there, but we also here patch a check to try locate it via NIX_CC.
+
+
--- a/Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift
+
+++ b/Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift
+
@@ -9,6 +9,7 @@
+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+
//
+
//===----------------------------------------------------------------------===//
+
+import Foundation
+
import TSCBasic
+
import SwiftOptions
+
+
@@ -24,6 +25,13 @@ extension Toolchain {
+
for targetInfo: FrontendTargetInfo,
+
parsedOptions: inout ParsedOptions
+
) throws -> VirtualPath {
+
+ let env = ProcessInfo.processInfo.environment
+
+ if let nixCC = env["NIX_CC"] {
+
+ return try VirtualPath(path: nixCC)
+
+ .appending(components: "resource-root", "lib",
+
+ targetInfo.target.triple.platformName(conflatingDarwin: true)!)
+
+ }
+
+
+
return VirtualPath.lookup(targetInfo.runtimeResourcePath.path)
+
.appending(components: "clang", "lib",
+
targetInfo.target.triple.platformName(conflatingDarwin: true)!)
+16
pkgs/development/compilers/swift/swift-driver/patches/prevent-sdk-dirs-warnings.patch
···
+
Prevents a user-visible warning on every compilation:
+
+
ld: warning: directory not found for option '-L.../MacOSX11.0.sdk/usr/lib/swift'
+
+
--- a/Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift
+
+++ b/Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift
+
@@ -50,7 +50,9 @@ extension Toolchain {
+
result.append(sdkPath.appending(components: "System", "iOSSupport", "usr", "lib", "swift"))
+
}
+
+
+ if sdkPath.absolutePath?.pathString.starts(with: "@storeDir@") == false {
+
result.append(sdkPath.appending(components: "usr", "lib", "swift"))
+
+ }
+
}
+
+
return result
+7
pkgs/development/compilers/swift/swiftpm/default.nix
···
swiftpmMakeMutable swift-tools-support-core
substituteInPlace .build/checkouts/swift-tools-support-core/Sources/TSCTestSupport/XCTestCasePerf.swift \
--replace 'canImport(Darwin)' 'false'
+
+
# Prevent a warning about SDK directories we don't have.
+
swiftpmMakeMutable swift-driver
+
patch -p1 -d .build/checkouts/swift-driver -i ${substituteAll {
+
src = ../swift-driver/patches/prevent-sdk-dirs-warnings.patch;
+
inherit (builtins) storeDir;
+
}}
'';
buildPhase = ''
+11 -2
pkgs/development/compilers/swift/wrapper/default.nix
···
-
{ stdenv
+
{ lib
+
, stdenv
, swift
, wrapperParams ? swift._wrapperParams
+
, useSwiftDriver ? true, swift-driver
}:
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 = ''
···
substituteAll '${./wrapper.sh}' $out/bin/$executable
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
+25
pkgs/development/compilers/swift/wrapper/wrapper.sh
···
;;
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