summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2023-11-11 20:51:48 -0800
committerAdam Joseph <adam@westernsemico.com>2023-11-11 22:12:40 -0800
commitb6a3fabcc1691a769e0cbe130f08dd5f2a285e02 (patch)
tree85f034a2e8597b93439c96544ecf07c934211740
parentb07a29c8fc41bed7e24c3092eb5c55b0e594f03c (diff)
downloadnixpkgs-b6a3fabcc1691a769e0cbe130f08dd5f2a285e02.tar
nixpkgs-b6a3fabcc1691a769e0cbe130f08dd5f2a285e02.tar.gz
nixpkgs-b6a3fabcc1691a769e0cbe130f08dd5f2a285e02.tar.bz2
nixpkgs-b6a3fabcc1691a769e0cbe130f08dd5f2a285e02.tar.lz
nixpkgs-b6a3fabcc1691a769e0cbe130f08dd5f2a285e02.tar.xz
nixpkgs-b6a3fabcc1691a769e0cbe130f08dd5f2a285e02.tar.zst
nixpkgs-b6a3fabcc1691a769e0cbe130f08dd5f2a285e02.zip
rust: allow building/git-bisecting without tarballs
This commit adds the machinery required to get our `rustc.nix` to
work using upstream's git repository, directly, without them waving
dead chickens over it and performing whatever other occult rituals
are involved in creating a release tarball.

No chickens, live or dead, were harmed in the creation of this
commit.
-rw-r--r--pkgs/development/compilers/rust/default.nix2
-rw-r--r--pkgs/development/compilers/rust/rustc.nix22
2 files changed, 20 insertions, 4 deletions
diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix
index 0a0af783236..efd7042c230 100644
--- a/pkgs/development/compilers/rust/default.nix
+++ b/pkgs/development/compilers/rust/default.nix
@@ -73,7 +73,7 @@ in
         patches = rustcPatches;
 
         # Use boot package set to break cycle
-        inherit (bootstrapRustPackages) cargo rustc;
+        inherit (bootstrapRustPackages) cargo rustc rustfmt;
       });
       rustfmt = self.callPackage ./rustfmt.nix {
         inherit Security;
diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix
index 3a649bde95d..1550887c356 100644
--- a/pkgs/development/compilers/rust/rustc.nix
+++ b/pkgs/development/compilers/rust/rustc.nix
@@ -1,7 +1,7 @@
 { lib, stdenv, removeReferencesTo, pkgsBuildBuild, pkgsBuildHost, pkgsBuildTarget, targetPackages
 , llvmShared, llvmSharedForBuild, llvmSharedForHost, llvmSharedForTarget, llvmPackages
 , fetchurl, file, python3
-, darwin, cargo, cmake, rust, rustc
+, darwin, cargo, cmake, rust, rustc, rustfmt
 , pkg-config, openssl, xz
 , libiconv
 , which, libffi
@@ -24,13 +24,15 @@
 let
   inherit (lib) optionals optional optionalString concatStringsSep;
   inherit (darwin.apple_sdk.frameworks) Security;
-in stdenv.mkDerivation rec {
+in stdenv.mkDerivation (finalAttrs: {
   pname = "${targetPackages.stdenv.cc.targetPrefix}rustc";
   inherit version;
 
   src = fetchurl {
     url = "https://static.rust-lang.org/dist/rustc-${version}-src.tar.gz";
     inherit sha256;
+    # See https://nixos.org/manual/nixpkgs/stable/#using-git-bisect-on-the-rust-compiler
+    passthru.isReleaseTarball = true;
   };
 
   __darwinAllowLocalNetworking = true;
@@ -79,6 +81,12 @@ in stdenv.mkDerivation rec {
     "--release-channel=stable"
     "--set=build.rustc=${rustc}/bin/rustc"
     "--set=build.cargo=${cargo}/bin/cargo"
+  ] ++ lib.optionals (!(finalAttrs.src.passthru.isReleaseTarball or false)) [
+    # release tarballs vendor the rustfmt source; when
+    # git-bisect'ing from upstream's git repo we must prevent
+    # attempts to download the missing source tarball
+    "--set=build.rustfmt=${rustfmt}/bin/rustfmt"
+  ] ++ [
     "--tools=rustc,rust-analyzer-proc-macro-srv"
     "--enable-rpath"
     "--enable-vendor"
@@ -203,6 +211,14 @@ in stdenv.mkDerivation rec {
     # See https://github.com/jemalloc/jemalloc/issues/1997
     # Using a value of 48 should work on both emulated and native x86_64-darwin.
     export JEMALLOC_SYS_WITH_LG_VADDR=48
+  '' + lib.optionalString (!(finalAttrs.src.passthru.isReleaseTarball or false)) ''
+    mkdir .cargo
+    cat > .cargo/config <<\EOF
+    [source.crates-io]
+    replace-with = "vendored-sources"
+    [source.vendored-sources]
+    directory = "vendor"
+    EOF
   '';
 
   # rustc unfortunately needs cmake to compile llvm-rt but doesn't
@@ -281,4 +297,4 @@ in stdenv.mkDerivation rec {
       "i686-windows" "x86_64-windows"
     ];
   };
-}
+})