forked from Rust-GPU/cargo-gpu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
41 lines (35 loc) · 1.18 KB
/
main.rs
File metadata and controls
41 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! main executable of cargo gpu
use cargo_gpu::Cli;
use clap::Parser as _;
fn main() {
#[cfg(debug_assertions)]
std::env::set_var("RUST_BACKTRACE", "1");
env_logger::builder().init();
if let Err(error) = run() {
log::error!("{error:?}");
#[expect(
clippy::print_stderr,
reason = "Our central place for outputting error messages"
)]
{
eprintln!("Error: {error}");
// `clippy::exit` seems to be a false positive in `main()`.
// See: https://github.com/rust-lang/rust-clippy/issues/13518
#[expect(clippy::restriction, reason = "Our central place for safely exiting")]
std::process::exit(1);
};
}
}
/// Wrappable "main" to catch errors.
fn run() -> anyhow::Result<()> {
let env_args = std::env::args()
.filter(|arg| {
// Calling our `main()` with the cargo subcommand `cargo gpu` passes "gpu"
// as the first parameter, so we want to ignore it.
arg != "gpu"
})
.collect::<Vec<_>>();
log::trace!("CLI args: {env_args:#?}");
let cli = Cli::parse_from(&env_args);
cli.command.run(env_args)
}