diff options
author | Stéphan Kochen <git@stephank.nl> | 2022-11-15 13:05:58 +0100 |
---|---|---|
committer | Stéphan Kochen <git@stephank.nl> | 2022-11-15 14:24:25 +0100 |
commit | 449e2f1b017b232118ceb85606fec294bae5b983 (patch) | |
tree | eb19dba7b773c7eca4eb308313818d240e684904 /pkgs | |
parent | 0e08b082b894e987e89acb32b38f68f32f65c3d0 (diff) |
swift: track version in a central sources.nix
Diffstat (limited to 'pkgs')
9 files changed, 87 insertions, 129 deletions
diff --git a/pkgs/development/compilers/swift/compiler/default.nix b/pkgs/development/compilers/swift/compiler/default.nix index 8d6d04a0a5478..55721fa65eb1c 100644 --- a/pkgs/development/compilers/swift/compiler/default.nix +++ b/pkgs/development/compilers/swift/compiler/default.nix @@ -1,5 +1,6 @@ { lib , stdenv +, callPackage , cmake , coreutils , gnugrep @@ -10,7 +11,6 @@ , bintools , python3 , git -, fetchFromGitHub , fetchpatch , makeWrapper , gnumake @@ -43,43 +43,7 @@ let inherit (stdenv) hostPlatform targetPlatform; - # The Swift toolchain script builds projects with separate repos. By convention, some of them share - # the same version with the main Swift compiler project per release. - version = "5.7"; - - fetchSwiftRelease = { repo, hash }: - fetchFromGitHub { - owner = "apple"; - inherit repo hash; - rev = "swift-${version}-RELEASE"; - name = "${repo}-${version}-src"; - }; - - # Names in this set match the directory the source is unpacked to. - sources = { - cmark = fetchSwiftRelease { - repo = "swift-cmark"; - hash = "sha256-f0BoTs4HYdx/aJ9HIGCWMalhl8PvClWD6R4QK3qSgAw="; - }; - llvm-project = fetchSwiftRelease { - repo = "llvm-project"; - hash = "sha256-uW6dEAFaDOlHXnq8lFYxrKNLRPEukauZJxX4UCpWpIY="; - }; - swift = fetchSwiftRelease { - repo = "swift"; - hash = "sha256-n8WVQYinAyIj4wmQnDhvPsH+t8ydANkGbjFJ6blfHOY="; - }; - swift-experimental-string-processing = fetchSwiftRelease { - repo = "swift-experimental-string-processing"; - hash = "sha256-Ar9fQWi8bYSvGErrS0SWrxIxwEwCjsYIZcWweZ8bV28="; - }; - } - // lib.optionalAttrs (!stdenv.isDarwin) { - swift-corelibs-libdispatch = fetchSwiftRelease { - repo = "swift-corelibs-libdispatch"; - hash = "sha256-1qbXiC1k9+T+L6liqXKg6EZXqem6KEEx8OctuL4Kb2o="; - }; - }; + sources = callPackage ../sources.nix { }; # Tools invoked by swift at run-time. runtimeDeps = lib.optionals stdenv.isDarwin [ @@ -207,7 +171,7 @@ let in stdenv.mkDerivation { pname = "swift"; - inherit version; + inherit (sources) version; outputs = [ "out" "lib" "dev" "doc" "man" ]; @@ -267,13 +231,19 @@ in stdenv.mkDerivation { # We setup custom build directories. dontUseCmakeBuildDir = true; - unpackPhase = '' + unpackPhase = let + copySource = repo: "cp -r ${sources.${repo}} ${repo}"; + in '' mkdir src cd src - ${lib.concatStrings (lib.mapAttrsToList (dir: src: '' - cp -r ${src} ${dir} - '') sources)} + ${copySource "swift-cmark"} + ${copySource "llvm-project"} + ${copySource "swift"} + ${copySource "swift-experimental-string-processing"} + ${lib.optionalString + (!stdenv.isDarwin) + (copySource "swift-corelibs-libdispatch")} chmod -R u+w . ''; @@ -410,7 +380,7 @@ in stdenv.mkDerivation { } cmakeFlags="-GNinja" - buildProject cmark + buildProject swift-cmark # Some notes: # - The Swift build just needs Clang. @@ -439,8 +409,8 @@ in stdenv.mkDerivation { -DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=ON -DLLVM_DIR=$SWIFT_BUILD_ROOT/llvm/lib/cmake/llvm -DClang_DIR=$SWIFT_BUILD_ROOT/llvm/lib/cmake/clang - -DSWIFT_PATH_TO_CMARK_SOURCE=$SWIFT_SOURCE_ROOT/cmark - -DSWIFT_PATH_TO_CMARK_BUILD=$SWIFT_BUILD_ROOT/cmark + -DSWIFT_PATH_TO_CMARK_SOURCE=$SWIFT_SOURCE_ROOT/swift-cmark + -DSWIFT_PATH_TO_CMARK_BUILD=$SWIFT_BUILD_ROOT/swift-cmark -DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=$SWIFT_SOURCE_ROOT/swift-corelibs-libdispatch -DEXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR=$SWIFT_SOURCE_ROOT/swift-experimental-string-processing -DSWIFT_INSTALL_COMPONENTS=${lib.concatStringsSep ";" swiftInstallComponents} diff --git a/pkgs/development/compilers/swift/foundation/default.nix b/pkgs/development/compilers/swift/foundation/default.nix index 860e8556e0d44..409067db2ef74 100644 --- a/pkgs/development/compilers/swift/foundation/default.nix +++ b/pkgs/development/compilers/swift/foundation/default.nix @@ -1,6 +1,6 @@ { lib , stdenv -, fetchFromGitHub +, callPackage , cmake , ninja , swift @@ -10,17 +10,13 @@ , curl }: -stdenv.mkDerivation rec { +let + sources = callPackage ../sources.nix { }; +in stdenv.mkDerivation { pname = "swift-corelibs-foundation"; - # Releases are made as part of the Swift toolchain, so versions should match. - version = "5.7"; - src = fetchFromGitHub { - owner = "apple"; - repo = "swift-corelibs-foundation"; - rev = "swift-${version}-RELEASE"; - hash = "sha256-6XUSC6759dcG24YapWicjRzUnmVVe0QPSsLEw4sQNjI="; - }; + inherit (sources) version; + src = sources.swift-corelibs-foundation; outputs = [ "out" "dev" ]; diff --git a/pkgs/development/compilers/swift/libdispatch/default.nix b/pkgs/development/compilers/swift/libdispatch/default.nix index 57a0633ef76af..3fe536c1889f5 100644 --- a/pkgs/development/compilers/swift/libdispatch/default.nix +++ b/pkgs/development/compilers/swift/libdispatch/default.nix @@ -1,22 +1,16 @@ { lib , stdenv -, fetchFromGitHub +, callPackage , cmake , ninja , useSwift ? true, swift }: -stdenv.mkDerivation rec { +stdenv.mkDerivation { pname = "swift-corelibs-libdispatch"; - # Releases are made as part of the Swift toolchain, so versions should match. - version = "5.7"; - src = fetchFromGitHub { - owner = "apple"; - repo = "swift-corelibs-libdispatch"; - rev = "swift-${version}-RELEASE"; - hash = "sha256-1qbXiC1k9+T+L6liqXKg6EZXqem6KEEx8OctuL4Kb2o="; - }; + inherit (sources) version; + src = sources.swift-corelibs-libdispatch; outputs = [ "out" "dev" "man" ]; diff --git a/pkgs/development/compilers/swift/sourcekit-lsp/default.nix b/pkgs/development/compilers/swift/sourcekit-lsp/default.nix index bf013a8f6e8e8..542bd7cef027a 100644 --- a/pkgs/development/compilers/swift/sourcekit-lsp/default.nix +++ b/pkgs/development/compilers/swift/sourcekit-lsp/default.nix @@ -1,7 +1,6 @@ { lib , stdenv , callPackage -, fetchFromGitHub , swift , swiftpm , Foundation @@ -12,8 +11,8 @@ , LocalAuthentication }: let - # Generated by swiftpm2nix. - generated = callPackage ./generated { }; + sources = callPackage ../sources.nix { }; + generated = callPackage ./generated { }; # Generated by swiftpm2nix. # 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 @@ -21,17 +20,11 @@ let # TODO: Find a better way to prevent this conflict. ncursesInput = if stdenv.isDarwin then ncurses.out else ncurses; in -stdenv.mkDerivation rec { +stdenv.mkDerivation { pname = "sourcekit-lsp"; - # Releases are made as part of the Swift toolchain, so versions should match. - version = "5.7"; - src = fetchFromGitHub { - owner = "apple"; - repo = "sourcekit-lsp"; - rev = "swift-${version}-RELEASE"; - hash = "sha256-uA3a+kAqI+XFzkDFEJ8XuRTgfYqacEuTsOU289Im+0Y="; - }; + inherit (sources) version; + src = sources.sourcekit-lsp; nativeBuildInputs = [ swift swiftpm ]; buildInputs = [ diff --git a/pkgs/development/compilers/swift/sources.nix b/pkgs/development/compilers/swift/sources.nix new file mode 100644 index 0000000000000..9c28c683406e7 --- /dev/null +++ b/pkgs/development/compilers/swift/sources.nix @@ -0,0 +1,33 @@ +{ lib, fetchFromGitHub }: + +let + + # These packages are all part of the Swift toolchain, and have a single + # upstream version that should match. We also list the hashes here so a basic + # version upgrade touches only this file. + version = "5.7"; + hashes = { + llvm-project = "sha256-uW6dEAFaDOlHXnq8lFYxrKNLRPEukauZJxX4UCpWpIY="; + sourcekit-lsp = "sha256-uA3a+kAqI+XFzkDFEJ8XuRTgfYqacEuTsOU289Im+0Y="; + swift = "sha256-n8WVQYinAyIj4wmQnDhvPsH+t8ydANkGbjFJ6blfHOY="; + swift-cmark = "sha256-f0BoTs4HYdx/aJ9HIGCWMalhl8PvClWD6R4QK3qSgAw="; + swift-corelibs-foundation = "sha256-6XUSC6759dcG24YapWicjRzUnmVVe0QPSsLEw4sQNjI="; + swift-corelibs-libdispatch = "sha256-1qbXiC1k9+T+L6liqXKg6EZXqem6KEEx8OctuL4Kb2o="; + swift-corelibs-xctest = "sha256-qLUO9/3tkJWorDMEHgHd8VC3ovLLq/UWXJWMtb6CMN0="; + swift-docc = "sha256-WlXJMAnrlVPCM+iCIhG0Gyho76BsC2yVBEpX3m/WiIQ="; + swift-docc-render-artifact = "sha256-ttdurN/K7OX+I4577jG3YGeRs+GLUTc7BiiEZGmFD+s="; + swift-driver = "sha256-sk7XWXYR1MGPEeVxA6eA/vxhN6Gq16iD1RHpVstL3zE="; + swift-experimental-string-processing = "sha256-Ar9fQWi8bYSvGErrS0SWrxIxwEwCjsYIZcWweZ8bV28="; + swift-package-manager = "sha256-MZah+/XfeK46YamxwuE3Kiv+u5bj7VmjEh6ztDF+0j4="; + }; + + # Create fetch derivations. + sources = lib.mapAttrs (repo: hash: fetchFromGitHub { + owner = "apple"; + inherit repo; + rev = "swift-${version}-RELEASE"; + name = "${repo}-${version}-src"; + hash = hashes.${repo}; + }) hashes; + +in sources // { inherit version; } diff --git a/pkgs/development/compilers/swift/swift-docc/default.nix b/pkgs/development/compilers/swift/swift-docc/default.nix index c3bb8f7fb9d51..ebdaefdaf8635 100644 --- a/pkgs/development/compilers/swift/swift-docc/default.nix +++ b/pkgs/development/compilers/swift/swift-docc/default.nix @@ -1,7 +1,6 @@ { lib , stdenv , callPackage -, fetchFromGitHub , swift , swiftpm , Foundation @@ -10,28 +9,17 @@ , LocalAuthentication }: let - # Generated by swiftpm2nix. - generated = callPackage ./generated { }; + sources = callPackage ../sources.nix { }; + generated = callPackage ./generated { }; # Generated by swiftpm2nix. in -stdenv.mkDerivation rec { +stdenv.mkDerivation { pname = "swift-docc"; - # Releases are made as part of the Swift toolchain, so versions should match. - version = "5.7"; - src = fetchFromGitHub { - owner = "apple"; - repo = "swift-docc"; - rev = "swift-${version}-RELEASE"; - hash = "sha256-WlXJMAnrlVPCM+iCIhG0Gyho76BsC2yVBEpX3m/WiIQ="; - }; + inherit (sources) version; + src = sources.swift-docc; # TODO: We could build this from `apple/swift-docc-render` source, but that # repository is not tagged. - render-artifact = fetchFromGitHub { - owner = "apple"; - repo = "swift-docc-render-artifact"; - rev = "swift-${version}-RELEASE"; - hash = "sha256-ttdurN/K7OX+I4577jG3YGeRs+GLUTc7BiiEZGmFD+s="; - }; + renderArtifact = sources.swift-docc-render-artifact; nativeBuildInputs = [ swift swiftpm ]; buildInputs = [ Foundation XCTest ] @@ -47,7 +35,7 @@ stdenv.mkDerivation rec { binPath="$(swiftpmBinPath)" mkdir -p $out/bin $out/share/docc cp $binPath/docc $out/bin/ - ln -s ${render-artifact}/dist $out/share/docc/render + ln -s $renderArtifact/dist $out/share/docc/render ''; meta = { diff --git a/pkgs/development/compilers/swift/swift-driver/default.nix b/pkgs/development/compilers/swift/swift-driver/default.nix index b09cc7d8fbda1..33f2c045983c7 100644 --- a/pkgs/development/compilers/swift/swift-driver/default.nix +++ b/pkgs/development/compilers/swift/swift-driver/default.nix @@ -1,7 +1,6 @@ { lib , stdenv , callPackage -, fetchFromGitHub , fetchpatch , swift , swiftpm @@ -12,8 +11,8 @@ , substituteAll }: let - # Generated by swiftpm2nix. - generated = callPackage ./generated { }; + sources = callPackage ../sources.nix { }; + generated = callPackage ./generated { }; # Generated by swiftpm2nix. # 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 @@ -21,17 +20,11 @@ let # TODO: Find a better way to prevent this conflict. ncursesInput = if stdenv.isDarwin then ncurses.out else ncurses; in -stdenv.mkDerivation rec { +stdenv.mkDerivation { 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="; - }; + inherit (sources) version; + src = sources.swift-driver; nativeBuildInputs = [ swift swiftpm ]; buildInputs = [ diff --git a/pkgs/development/compilers/swift/swiftpm/default.nix b/pkgs/development/compilers/swift/swiftpm/default.nix index 15090e1e2685a..5a89ff17935e3 100644 --- a/pkgs/development/compilers/swift/swiftpm/default.nix +++ b/pkgs/development/compilers/swift/swiftpm/default.nix @@ -1,7 +1,6 @@ { lib , callPackage , stdenv -, fetchFromGitHub , cmake , ninja , git @@ -25,16 +24,12 @@ let inherit (swift) swiftOs swiftModuleSubdir swiftStaticModuleSubdir; sharedLibraryExt = stdenv.hostPlatform.extensions.sharedLibrary; + sources = callPackage ../sources.nix { }; + # Common attributes for the bootstrap swiftpm and the final swiftpm. - commonAttrs = rec { - # Releases are made as part of the Swift toolchain, so versions should match. - version = "5.7"; - src = fetchFromGitHub { - owner = "apple"; - repo = "swift-package-manager"; - rev = "swift-${version}-RELEASE"; - hash = "sha256-MZah+/XfeK46YamxwuE3Kiv+u5bj7VmjEh6ztDF+0j4="; - }; + commonAttrs = { + inherit (sources) version; + src = sources.swift-package-manager; nativeBuildInputs = [ makeWrapper ]; # Required at run-time for the host platform to build package manifests. propagatedBuildInputs = [ Foundation ]; diff --git a/pkgs/development/compilers/swift/xctest/default.nix b/pkgs/development/compilers/swift/xctest/default.nix index 9fa8c02b4dc28..c8003d8486f10 100644 --- a/pkgs/development/compilers/swift/xctest/default.nix +++ b/pkgs/development/compilers/swift/xctest/default.nix @@ -1,6 +1,6 @@ { lib , stdenv -, fetchFromGitHub +, callPackage , cmake , ninja , swift @@ -8,17 +8,13 @@ , DarwinTools }: -stdenv.mkDerivation rec { +let + sources = callPackage ../sources.nix { }; +in stdenv.mkDerivation { 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="; - }; + inherit (sources) version; + src = sources.swift-corelibs-xctest; outputs = [ "out" ]; |