From: Mike Lothian <mike@fireburn.co.uk>
Subject: [PATCH] Fix system rust wrapper inputs and bindgen libclang path

Use the selected Rust compiler for build inputs and allow the ebuild to
specify the libclang directory.
---
diff --git a/build/config/rust.gni b/build/config/rust.gni
index 87b5ae8..eef7e7b 100644
--- a/build/config/rust.gni
+++ b/build/config/rust.gni
@@ -62,6 +62,7 @@ declare_args() {
   # Directory under which to find `bin/bindgen` (a `bin` directory containing
   # the bindgen exectuable).
   rust_bindgen_root = "//third_party/rust-toolchain"
+  bindgen_libclang_path = ""

   # If you're using a Rust toolchain as specified by rust_sysroot_absolute,
   # set this to the output of `rustc -V`. Changing this string will cause all
@@ -433,5 +434,5 @@ rustc_wrapper_inputs = [
 if (host_os == "win") {
   rustc_wrapper_inputs += [ "//third_party/rust-toolchain/bin/rustc.exe" ]
 } else {
-  rustc_wrapper_inputs += [ "//third_party/rust-toolchain/bin/rustc" ]
+  rustc_wrapper_inputs += [ "${rust_sysroot}/bin/rustc" ]
 }
diff --git a/build/rust/cargo_crate.gni b/build/rust/cargo_crate.gni
index 5ba5f98..ef72c33 100644
--- a/build/rust/cargo_crate.gni
+++ b/build/rust/cargo_crate.gni
@@ -471,7 +471,7 @@ template("cargo_crate") {
       if (host_os == "win") {
         inputs += [ "//third_party/rust-toolchain/bin/rustc.exe" ]
       } else {
-        inputs += [ "//third_party/rust-toolchain/bin/rustc" ]
+        inputs += [ "${rust_sysroot}/bin/rustc" ]
       }

       build_script_target = ":${_build_script_name}($rust_macro_toolchain)"
diff --git a/build/rust/rust_bindgen_generator.gni b/build/rust/rust_bindgen_generator.gni
index bcc113e..b5e8768 100644
--- a/build/rust/rust_bindgen_generator.gni
+++ b/build/rust/rust_bindgen_generator.gni
@@ -27,7 +27,9 @@ if (host_os == "win") {
 # On Windows, the libclang.dll is beside the bindgen.exe, otherwise it is in
 # ../lib.
 _libclang_path = rust_bindgen_root
-if (!use_chromium_rust_toolchain &&
+if (bindgen_libclang_path != "") {
+  _libclang_path = bindgen_libclang_path
+} else if (!use_chromium_rust_toolchain &&
     (host_cpu == "ppc64" || host_cpu == "s390x")) {
   _libclang_path = rust_sysroot_absolute + "/lib64"
 } else if (host_os == "win") {
diff --git a/build/rust/std/BUILD.gn b/build/rust/std/BUILD.gn
index 105a1d5..c1295eb 100644
--- a/build/rust/std/BUILD.gn
+++ b/build/rust/std/BUILD.gn
@@ -271,7 +271,7 @@ if (toolchain_has_rust) {
       if (host_os == "win") {
         inputs = [ "//third_party/rust-toolchain/bin/rustc.exe" ]
       } else {
-        inputs = [ "//third_party/rust-toolchain/bin/rustc" ]
+        inputs = [ "${rust_sysroot}/bin/rustc" ]
       }

       # For the rustc sysroot we must include even the rlibs we don't pass to
