cargo_openvm/
lib.rs

1#![cfg_attr(feature = "tco", allow(incomplete_features))]
2#![cfg_attr(feature = "tco", feature(explicit_tail_calls))]
3
4pub mod commands;
5pub mod default;
6pub mod input;
7pub mod util;
8
9use std::process::{Command, Stdio};
10
11use eyre::{Context, Result};
12pub use openvm_build::{get_rustup_toolchain_name, DEFAULT_RUSTUP_TOOLCHAIN_NAME};
13
14#[cfg(all(feature = "cuda", feature = "tco"))]
15pub const OPENVM_VERSION_MESSAGE: &str = concat!(
16    "v",
17    env!("CARGO_PKG_VERSION"),
18    " (",
19    env!("VERGEN_GIT_SHA"),
20    ") [cuda, tco]"
21);
22
23#[cfg(all(feature = "cuda", not(feature = "tco")))]
24pub const OPENVM_VERSION_MESSAGE: &str = concat!(
25    "v",
26    env!("CARGO_PKG_VERSION"),
27    " (",
28    env!("VERGEN_GIT_SHA"),
29    ") [cuda]"
30);
31
32#[cfg(all(not(feature = "cuda"), feature = "tco"))]
33pub const OPENVM_VERSION_MESSAGE: &str = concat!(
34    "v",
35    env!("CARGO_PKG_VERSION"),
36    " (",
37    env!("VERGEN_GIT_SHA"),
38    ") [tco]"
39);
40
41#[cfg(all(not(feature = "cuda"), not(feature = "tco")))]
42pub const OPENVM_VERSION_MESSAGE: &str = concat!(
43    "v",
44    env!("CARGO_PKG_VERSION"),
45    " (",
46    env!("VERGEN_GIT_SHA"),
47    ")"
48);
49
50#[allow(dead_code)]
51trait CommandExecutor {
52    fn run(&mut self) -> Result<()>;
53}
54
55impl CommandExecutor for Command {
56    fn run(&mut self) -> Result<()> {
57        self.stderr(Stdio::inherit())
58            .stdout(Stdio::inherit())
59            .stdin(Stdio::inherit())
60            .output()
61            .with_context(|| format!("while executing `{:?}`", &self))
62            .map(|_| ())
63    }
64}
65
66#[allow(unreachable_code)]
67pub fn is_supported_target() -> bool {
68    #[cfg(all(target_arch = "x86_64", target_os = "linux"))]
69    return true;
70
71    #[cfg(all(target_arch = "aarch64", target_os = "linux"))]
72    return true;
73
74    #[cfg(all(target_arch = "x86_64", target_os = "macos"))]
75    return true;
76
77    #[cfg(all(target_arch = "aarch64", target_os = "macos"))]
78    return true;
79
80    false
81}
82
83pub fn get_target() -> String {
84    target_lexicon::HOST.to_string()
85}