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