[build] use common toolchain configuration

Change-Id: I7058ae20568af8882257f583217463b43c5e38f6
diff --git a/rustc_deps/BUILD.gn b/rustc_deps/BUILD.gn
index bf45141..c6b9258 100644
--- a/rustc_deps/BUILD.gn
+++ b/rustc_deps/BUILD.gn
@@ -4,6 +4,7 @@
 
 import("//build/config/clang/clang.gni")
 import("//build/rust/rustc_artifact.gni") # for rustc_third_party_artifact
+import("//build/rust/config.gni") # for rust_build_{args,deps,inputs}
 
 third_party_lock = "//third_party/rust-crates/rustc_deps/Cargo.lock"
 third_party_toml = "//third_party/rust-crates/rustc_deps/Cargo.toml"
@@ -45,64 +46,22 @@
 action("build-third-party") {
   script = "//build/rust/compile_3p_crates.py"
 
-  # We want to force a recompile of the Rust world whenever Rust toolchain
-  # changes since artifacts from an older version of the toolchain may or
-  # may not be compatible with newer ones.
-  # To achieve this, we insert a synthetic argument to the script invocation.
-  cipd_version = read_file(
-          "//buildtools/${host_platform}/rust/.versions/rust.cipd_version",
-          "json")
-
   inputs = [ third_party_lock, third_party_toml ]
   inputs += fuchsia_zircon_src
   inputs += fuchsia_zircon_sys_src
 
-  if (is_debug) {
-    opt_level = "0"
-  } else {
-    opt_level = "z"
-  }
-
-  deps = []
-  args = []
-
-  assert(
-    current_os == "mac" || current_os == "linux" || current_os == "fuchsia",
-    "current_os was neither mac, linux, nor fuchsia"
-  )
-  if (current_os == "mac") {
-    target_triple = "x86_64-apple-darwin"
-    assert(current_cpu == "x64")
-  } else if (current_os == "linux") {
-    assert(current_cpu == "x64")
-    target_triple = "x86_64-unknown-linux-gnu"
-  } else if (current_os == "fuchsia") {
-    deps += [ "//garnet/public/sdk:zircon_sysroot_export" ]
-    args += ["--sysroot", rebase_path("$root_build_dir/sdks/zircon_sysroot/arch/$target_cpu/sysroot") ]
-    assert(current_cpu == "x64" || current_cpu == "arm64")
-    if (current_cpu == "x64") {
-      target_triple = "x86_64-unknown-fuchsia"
-    } else if (current_cpu == "arm64") {
-      target_triple = "aarch64-unknown-fuchsia"
-    }
-  }
-
   out_dir = "${root_out_dir}/rust_third_party"
   out_deps_data = "${out_dir}/deps_data.json"
-  args += [
-    "--rustc", rebase_path("${rustc_prefix}/rustc"),
-    "--cipd-version", cipd_version.instance_id,
+  args = [
     "--cargo", rebase_path("${rustc_prefix}/cargo"),
     "--crate-root", rebase_path("//third_party/rust-crates/rustc_deps"),
-    "--opt-level", opt_level,
     "--out-dir", rebase_path(out_dir),
     "--out-deps-data", rebase_path(out_deps_data),
-    "--target", target_triple,
-    "--cmake-dir", rebase_path("//buildtools/cmake/bin"),
-    "--shared-libs-root", rebase_path(
-      get_label_info("//default($shlib_toolchain)", "root_out_dir")),
-    "--clang_prefix", rebase_path(clang_prefix, "", root_build_dir),
   ]
 
+  args += rust_build_args
+  deps = rust_build_deps
+  inputs += rust_build_inputs
+
   outputs = [ out_deps_data ]
 }