Skip to content

Commit 270e0e5

Browse files
committed
recreate the binary and main function
1 parent 09870ab commit 270e0e5

File tree

2 files changed

+46
-43
lines changed

2 files changed

+46
-43
lines changed

crates/cargo-gpu/src/lib.rs

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use anyhow::Context as _;
5252

5353
use crate::dump_usage::dump_full_usage_for_readme;
5454
use build::Build;
55-
use clap::Parser as _;
5655
use install::Install;
5756
use show::Show;
5857

@@ -93,47 +92,9 @@ macro_rules! user_output {
9392
}
9493
}
9594

96-
fn main() {
97-
#[cfg(debug_assertions)]
98-
std::env::set_var("RUST_BACKTRACE", "1");
99-
100-
env_logger::builder().init();
101-
102-
if let Err(error) = run() {
103-
log::error!("{error:?}");
104-
105-
#[expect(
106-
clippy::print_stderr,
107-
reason = "Our central place for outputting error messages"
108-
)]
109-
{
110-
eprintln!("Error: {error}");
111-
112-
// `clippy::exit` seems to be a false positive in `main()`.
113-
// See: https://github.com/rust-lang/rust-clippy/issues/13518
114-
#[expect(clippy::restriction, reason = "Our central place for safely exiting")]
115-
std::process::exit(1);
116-
};
117-
}
118-
}
119-
120-
/// Wrappable "main" to catch errors.
121-
fn run() -> anyhow::Result<()> {
122-
let env_args = std::env::args()
123-
.filter(|arg| {
124-
// Calling our `main()` with the cargo subcommand `cargo gpu` passes "gpu"
125-
// as the first parameter, so we want to ignore it.
126-
arg != "gpu"
127-
})
128-
.collect::<Vec<_>>();
129-
log::trace!("CLI args: {env_args:#?}");
130-
let cli = Cli::parse_from(&env_args);
131-
cli.command.run(env_args)
132-
}
133-
13495
/// All of the available subcommands for `cargo gpu`
13596
#[derive(clap::Subcommand)]
136-
enum Command {
97+
pub enum Command {
13798
/// Install rust-gpu compiler artifacts.
13899
Install(Box<Install>),
139100

@@ -191,13 +152,14 @@ impl Command {
191152
/// the Cli struct representing the main cli
192153
#[derive(clap::Parser)]
193154
#[clap(author, version, about, subcommand_required = true)]
194-
pub(crate) struct Cli {
155+
pub struct Cli {
195156
/// The command to run.
196157
#[clap(subcommand)]
197-
command: Command,
158+
pub command: Command,
198159
}
199160

200-
fn cache_dir() -> anyhow::Result<std::path::PathBuf> {
161+
/// The central cache directory of cargo gpu
162+
pub fn cache_dir() -> anyhow::Result<std::path::PathBuf> {
201163
let dir = directories::BaseDirs::new()
202164
.with_context(|| "could not find the user home directory")?
203165
.cache_dir()

crates/cargo-gpu/src/main.rs

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

0 commit comments

Comments
 (0)