Skip to main content

solar_cli/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(
3    html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/solar/main/assets/logo.png",
4    html_favicon_url = "https://raw.githubusercontent.com/paradigmxyz/solar/main/assets/favicon.ico"
5)]
6#![cfg_attr(docsrs, feature(doc_cfg))]
7
8use clap::Parser as _;
9use solar_interface::Result;
10use std::process::ExitCode;
11
12pub use solar_config::{self as config, CompileOpts, LspArgs, UnstableOpts, version};
13
14mod emit;
15pub mod standard_json;
16
17pub mod commands;
18pub mod utils;
19
20#[cfg(all(unix, any(target_env = "gnu", target_os = "macos")))]
21pub mod signal_handler;
22
23/// Signal handler to extract a backtrace from stack overflow.
24///
25/// This is a no-op because this platform doesn't support our signal handler's requirements.
26#[cfg(not(all(unix, any(target_env = "gnu", target_os = "macos"))))]
27pub mod signal_handler {
28    #[cfg(unix)]
29    use libc as _;
30
31    /// No-op function.
32    pub fn install() {}
33}
34
35mod args;
36use args::Args;
37
38pub use commands::compile::run_compiler_args;
39
40// `asm` feature.
41use alloy_primitives as _;
42
43use tracing as _;
44
45pub fn main() -> ExitCode {
46    signal_handler::install();
47    solar_interface::panic_hook::install();
48    let _guard = utils::init_logger(utils::LogDestination::Stderr);
49
50    let args = match parse_args(std::env::args_os()) {
51        Ok(args) => args,
52        Err(e) => e.exit(),
53    };
54    commands::run(args)
55}
56
57fn parse_args<I, T>(itr: I) -> Result<Args, clap::Error>
58where
59    I: IntoIterator<Item = T>,
60    T: Into<std::ffi::OsString> + Clone,
61{
62    let mut args = Args::try_parse_from(itr)?;
63    args.compile.finish()?;
64    Ok(args)
65}