cargo_binstall/
main_impl.rs1use std::{process::Termination, time::Instant};
2
3use binstalk::{helpers::jobserver_client::LazyJobserverClient, TARGET};
4use log::LevelFilter;
5use tracing::debug;
6
7use crate::{
8 args,
9 bin_util::{run_tokio_main, MainExit},
10 entry,
11 logging::logging,
12};
13
14pub fn do_main() -> impl Termination {
15 let (args, cli_overrides) = args::parse();
16
17 if args.version {
18 let cargo_binstall_version = env!("CARGO_PKG_VERSION");
19 if args.verbose {
20 let build_date = env!("VERGEN_BUILD_DATE");
21
22 let features = env!("VERGEN_CARGO_FEATURES");
23
24 let git_sha = option_env!("VERGEN_GIT_SHA").unwrap_or("UNKNOWN");
25 let git_commit_date = option_env!("VERGEN_GIT_COMMIT_DATE").unwrap_or("UNKNOWN");
26
27 let rustc_semver = env!("VERGEN_RUSTC_SEMVER");
28 let rustc_commit_hash = env!("VERGEN_RUSTC_COMMIT_HASH");
29 let rustc_llvm_version = env!("VERGEN_RUSTC_LLVM_VERSION");
30
31 println!(
32 r#"cargo-binstall: {cargo_binstall_version}
33build-date: {build_date}
34build-target: {TARGET}
35build-features: {features}
36build-commit-hash: {git_sha}
37build-commit-date: {git_commit_date}
38rustc-version: {rustc_semver}
39rustc-commit-hash: {rustc_commit_hash}
40rustc-llvm-version: {rustc_llvm_version}"#
41 );
42 } else {
43 println!("{cargo_binstall_version}");
44 }
45 MainExit::Success(None)
46 } else if args.self_install {
47 MainExit::new(entry::self_install(args), None)
48 } else {
49 logging(
50 args.log_level.unwrap_or(LevelFilter::Info),
51 args.json_output,
52 );
53
54 let start = Instant::now();
55
56 let jobserver_client = LazyJobserverClient::new();
57
58 let result =
59 run_tokio_main(|| entry::install_crates(args, cli_overrides, jobserver_client));
60
61 let done = start.elapsed();
62 debug!("run time: {done:?}");
63
64 MainExit::new(result, Some(done))
65 }
66}