liblingo/
args.rs

1use crate::backends::BuildProfile;
2use clap::{Args, Parser, Subcommand};
3use serde_derive::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq, Hash)]
7#[value(rename_all = "lowercase")]
8pub enum TargetLanguage {
9    C,
10    UC,
11    CCpp,
12    Cpp,
13    Rust,
14    TypeScript,
15    Python,
16}
17
18#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq, Hash)]
19pub enum Platform {
20    Native,
21    Zephyr,
22    RP2040,
23    LF3PI,
24    FlexPRET,
25    Patmos,
26    RIOT,
27}
28
29#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq, Hash)]
30pub enum BuildSystem {
31    LFC,
32    CMake,
33    Cargo,
34    Npm,
35    Pnpm,
36}
37
38#[derive(Args, Debug)]
39pub struct BuildArgs {
40    /// Which build system to use
41    #[arg(short, long)]
42    pub build_system: Option<BuildSystem>,
43
44    /// Which target to build
45    #[arg(short, long)]
46    pub language: Option<TargetLanguage>,
47
48    /// Overwrites any possible board definition in Lingo.toml
49    #[arg(long)]
50    pub platform: Option<Platform>,
51
52    /// Tell lingo where the lfc toolchain can be found
53    #[arg(long)]
54    pub lfc: Option<PathBuf>,
55
56    /// Skips building aka invoking the build system so it only generates code
57    #[arg(short, long)]
58    pub no_compile: bool,
59
60    /// If one of the apps fails to build dont interrupt the build process
61    #[arg(short, long)]
62    pub keep_going: bool,
63
64    /// Compiles the binaries with optimizations turned on and strips debug symbols
65    #[arg(short, long)]
66    pub release: bool,
67
68    /// List of apps to build if left empty all apps are built
69    #[arg(short, long, value_delimiter = ',')]
70    pub apps: Vec<String>,
71
72    /// Number of threads to use for parallel builds. Zero means it will be determined automatically.
73    #[arg(short, long, default_value_t = 0)]
74    pub threads: usize,
75}
76
77impl BuildArgs {
78    pub fn build_profile(&self) -> BuildProfile {
79        if self.release {
80            BuildProfile::Release
81        } else {
82            BuildProfile::Debug
83        }
84    }
85}
86
87#[derive(Args, Debug)]
88pub struct InitArgs {
89    #[arg(value_enum, short, long)]
90    pub language: Option<TargetLanguage>,
91    #[arg(value_enum, short, long, default_value_t = Platform::Native)]
92    pub platform: Platform,
93}
94
95impl InitArgs {
96    pub fn get_target_language(&self) -> TargetLanguage {
97        self.language.unwrap_or({
98            // Target language for Zephyr and RP2040 is C
99            // Else use Cpp.
100            match self.platform {
101                Platform::Zephyr => TargetLanguage::C,
102                Platform::RP2040 => TargetLanguage::C,
103                _ => TargetLanguage::Cpp,
104            }
105        })
106    }
107}
108
109#[derive(Subcommand, Debug)]
110pub enum Command {
111    /// initializing a lingua-franca project
112    Init(InitArgs),
113
114    /// compiling one or multiple binaries in a lingua-franca package
115    Build(BuildArgs),
116
117    /// Updates the dependencies and potentially build tools
118    Update,
119
120    /// builds and runs binaries
121    Run(BuildArgs),
122
123    /// removes build artifacts
124    Clean,
125}
126
127#[derive(Parser)]
128#[command(name = "Lingua Franca package manager and build tool")]
129#[command(author = "tassilo.tanneberger@tu-dresden.de")]
130#[command(version = env!("CARGO_PKG_VERSION"))]
131#[command(about = "Build system for the Lingua Franca coordination language", long_about = None)]
132pub struct CommandLineArgs {
133    /// which command of lingo to use
134    #[clap(subcommand)]
135    pub command: Command,
136
137    /// lingo wouldn't produce any output
138    #[arg(short, long)]
139    pub quiet: bool,
140
141    /// lingo will give more detailed feedback
142    #[arg(short, long)]
143    pub verbose: bool,
144}