@@ -939,3 +939,68 @@ Fenix also has examples with `buildRustPackage`,
939939[ crane] ( https://github.com/ipetkov/crane ) ,
940940[ naersk] ( https://github.com/nix-community/naersk ) ,
941941and cross compilation in its [ Examples] ( https://github.com/nix-community/fenix#examples ) section.
942+
943+ ## Using ` git bisect ` on the Rust compiler {#using-git-bisect-on-the-rust-compiler}
944+
945+ Sometimes an upgrade of the Rust compiler (` rustc ` ) will break a
946+ downstream package. In these situations, being able to ` git bisect `
947+ the ` rustc ` version history to find the offending commit is quite
948+ useful. Nixpkgs makes it easy to do this.
949+
950+ First, roll back your nixpkgs to a commit in which its ` rustc ` used
951+ * the most recent one which doesn't have the problem.* You'll need
952+ to do this because of ` rustc ` 's extremely aggressive
953+ version-pinning.
954+
955+ Next, add the following overlay, updating the Rust version to the
956+ one in your rolled-back nixpkgs, and replacing ` /git/scratch/rust `
957+ with the path into which you have ` git clone ` d the ` rustc ` git
958+ repository:
959+
960+ ``` nix
961+ (final: prev: /*lib.optionalAttrs prev.stdenv.targetPlatform.isAarch64*/ {
962+ rust_1_72 =
963+ lib.updateManyAttrsByPath [{
964+ path = [ "packages" "stable" ];
965+ update = old: old.overrideScope(final: prev: {
966+ rustc = prev.rustc.overrideAttrs (_: {
967+ src = lib.cleanSource /git/scratch/rust;
968+ # do *not* put passthru.isReleaseTarball=true here
969+ });
970+ });
971+ }]
972+ prev.rust_1_72;
973+ })
974+ ```
975+
976+ If the problem you're troubleshooting only manifests when
977+ cross-compiling you can uncomment the ` lib.optionalAttrs ` in the
978+ example above, and replace ` isAarch64 ` with the target that is
979+ having problems. This will speed up your bisect quite a bit, since
980+ the host compiler won't need to be rebuilt.
981+
982+ Now, you can start a ` git bisect ` in the directory where you checked
983+ out the ` rustc ` source code. It is recommended to select the
984+ endpoint commits by searching backwards from ` origin/master ` for the
985+ * commits which added the release notes for the versions in
986+ question.* If you set the endpoints to commits on the release
987+ branches (i.e. the release tags), git-bisect will often get confused
988+ by the complex merge-commit structures it will need to traverse.
989+
990+ The command loop you'll want to use for bisecting looks like this:
991+
992+ ``` bash
993+ git bisect {good,bad} # depending on result of last build
994+ git submodule update --init
995+ CARGO_NET_OFFLINE=false cargo vendor \
996+ --sync ./src/tools/cargo/Cargo.toml \
997+ --sync ./src/tools/rust-analyzer/Cargo.toml \
998+ --sync ./compiler/rustc_codegen_cranelift/Cargo.toml \
999+ --sync ./src/bootstrap/Cargo.toml
1000+ nix-build $NIXPKGS -A package-broken-by-rust-changes
1001+ ```
1002+
1003+ The ` git submodule update --init ` and ` cargo vendor ` commands above
1004+ require network access, so they can't be performed from within the
1005+ ` rustc ` derivation, unfortunately.
1006+
0 commit comments