blob: 32cb13710740ef52c8fc7a9da324936464eec199 [file] [log] [blame]
Brian Silvermancc09f182022-03-09 15:40:20 -08001//! A tool for installing bootstrapped Rust binaries into the requested paths.
2
3use std::{
4 env,
5 fs::{copy, create_dir_all},
6 path::PathBuf,
7};
8
9fn install() -> std::io::Result<u64> {
10 let binary = PathBuf::from(env!("RULES_RUST_CARGO_BOOTSTRAP_BINARY"));
11
12 // Consume only the first argument as the destination
13 let dest = PathBuf::from(
14 env::args()
15 .nth(1)
16 .expect("No destination argument provided"),
17 );
18
19 // Create the parent directory structure if it doesn't exist
20 if let Some(parent) = dest.parent() {
21 if !parent.exists() {
22 create_dir_all(parent)?;
23 }
24 }
25
26 // Copy the file to the requested destination
27 copy(binary, dest)
28}
29
30fn main() {
31 if let Err(err) = install() {
32 eprintln!("{:?}", err);
33 std::process::exit(1);
34 };
35}