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 #[arg(short, long)]
42 pub build_system: Option<BuildSystem>,
43
44 #[arg(short, long)]
46 pub language: Option<TargetLanguage>,
47
48 #[arg(long)]
50 pub platform: Option<Platform>,
51
52 #[arg(long)]
54 pub lfc: Option<PathBuf>,
55
56 #[arg(short, long)]
58 pub no_compile: bool,
59
60 #[arg(short, long)]
62 pub keep_going: bool,
63
64 #[arg(short, long)]
66 pub release: bool,
67
68 #[arg(short, long, value_delimiter = ',')]
70 pub apps: Vec<String>,
71
72 #[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 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 Init(InitArgs),
113
114 Build(BuildArgs),
116
117 Update,
119
120 Run(BuildArgs),
122
123 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 #[clap(subcommand)]
135 pub command: Command,
136
137 #[arg(short, long)]
139 pub quiet: bool,
140
141 #[arg(short, long)]
143 pub verbose: bool,
144}