Squashed 'third_party/rules_rust/' content from commit bf59038ca
git-subtree-dir: third_party/rules_rust
git-subtree-split: bf59038cac11798cbaef9f3bf965bad8182b97fa
Signed-off-by: Brian Silverman <bsilver16384@gmail.com>
Change-Id: I5a20e403203d670df467ea97dde9a4ac40339a8d
diff --git a/cargo/bootstrap/bootstrap_installer.rs b/cargo/bootstrap/bootstrap_installer.rs
new file mode 100644
index 0000000..32cb137
--- /dev/null
+++ b/cargo/bootstrap/bootstrap_installer.rs
@@ -0,0 +1,35 @@
+//! A tool for installing bootstrapped Rust binaries into the requested paths.
+
+use std::{
+ env,
+ fs::{copy, create_dir_all},
+ path::PathBuf,
+};
+
+fn install() -> std::io::Result<u64> {
+ let binary = PathBuf::from(env!("RULES_RUST_CARGO_BOOTSTRAP_BINARY"));
+
+ // Consume only the first argument as the destination
+ let dest = PathBuf::from(
+ env::args()
+ .nth(1)
+ .expect("No destination argument provided"),
+ );
+
+ // Create the parent directory structure if it doesn't exist
+ if let Some(parent) = dest.parent() {
+ if !parent.exists() {
+ create_dir_all(parent)?;
+ }
+ }
+
+ // Copy the file to the requested destination
+ copy(binary, dest)
+}
+
+fn main() {
+ if let Err(err) = install() {
+ eprintln!("{:?}", err);
+ std::process::exit(1);
+ };
+}