chroot_version_hooks.d: Purge removed dev-rust package versions.

This purges a group of recently removed dev-rust packages because
some developers were running into build breakages due to old copies
of bitflags-1.1.0 remaining installed that depend on dev-util/cargo
which is incompatible with the available versions ofdev-lang/rust.

BUG=chromium:1124797
TEST=./update_chroot

Change-Id: Id3298465681b1944b8aa1eed2e46350e5fe57522
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/2402259
Tested-by: Allen Webb <allenwebb@google.com>
Commit-Queue: Allen Webb <allenwebb@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/chroot_version_hooks.d/181_rust_cleanup b/chroot_version_hooks.d/181_rust_cleanup
new file mode 100644
index 0000000..6bf0fc6
--- /dev/null
+++ b/chroot_version_hooks.d/181_rust_cleanup
@@ -0,0 +1,26 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Clean ebuilds that have been upgraded but aren't automatically removed.
+
+export CLEAN_DELAY=0
+
+to_remove=(
+  "~dev-rust/bitflags-1.1.0"
+  "~dev-rust/byteorder-1.3.1"
+  "~dev-rust/proc-macro2-1.0.8"
+  "~serde-1.0.81"
+  "~serde_derive-1.0.81"
+  "~syn-1.0.14"
+)
+
+sudo emerge -Cq "${to_remove[@]}" &
+
+for board_root in /build/*; do
+  board_name=${board_root##*/}
+  if [[ -d "${board_root}/var/db/pkg/dev-rust" ]]; then
+    emerge-"${board_name}" -Cq "${to_remove[@]}" &
+  fi
+done
+wait