makepad_studio/build_manager/
build_protocol.rs

1use crate::{
2    makepad_live_id::LiveId,
3    makepad_code_editor::text::{Position, Length},
4    makepad_micro_serde::{SerBin, DeBin, DeBinErr},
5};
6
7
8#[derive(PartialEq, Clone, Copy, Debug, SerBin, DeBin)]
9pub struct BuildCmdId(pub u64);
10
11#[cfg(not(target_os="windows"))]
12#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
13pub enum BuildTarget {
14    Release,
15    Debug,
16    ReleaseStudio,
17    DebugStudio,
18    Profiler,
19    IosSim{org:String, app:String},
20    IosDevice{org:String, app:String},
21    Android,
22    WebAssembly
23}
24
25#[cfg(not(target_os="windows"))]
26impl BuildTarget {
27    pub fn runs_in_studio(&self)->bool{
28        match self{
29            Self::ReleaseStudio=>true,
30            Self::DebugStudio=>true,
31            _=>false
32        }
33    }
34    
35    pub const RELEASE_STUDIO:u64 = 0;
36    pub const DEBUG_STUDIO:u64 = 1;
37    pub const RELEASE:u64 = 2;
38    pub const DEBUG:u64 = 3;
39    pub const PROFILER:u64 = 4;
40    pub const IOS_SIM:u64 = 5;
41    pub const IOS_DEVICE:u64 = 6;
42    pub const ANDROID:u64 = 7;
43    pub const WEBASSEMBLY:u64 = 8;
44    pub fn len() -> u64 {9}
45    pub fn name(idx: u64) -> &'static str {
46        match idx {
47            Self::RELEASE_STUDIO=> "Release Studio",
48            Self::DEBUG_STUDIO=> "Debug Studio",
49            Self::RELEASE=> "Release",
50            Self::DEBUG=> "Debug",
51            Self::PROFILER=> "Profiler",
52            Self::IOS_SIM=> "iOS Simulator",
53            Self::IOS_DEVICE=> "iOS Device",
54            Self::ANDROID=> "Android",
55            Self::WEBASSEMBLY=> "WebAssembly",
56            _=>"Unknown"
57        }
58    }
59    pub fn id(&self) -> u64 {
60        match self {
61            Self::ReleaseStudio=>Self::RELEASE_STUDIO,
62            Self::DebugStudio=>Self::DEBUG_STUDIO,
63            Self::Release=>Self::RELEASE,
64            Self::Debug=>Self::DEBUG,
65            Self::Profiler=>Self::PROFILER,
66            Self::IosSim{..}=>Self::IOS_SIM,
67            Self::IosDevice{..}=>Self::IOS_DEVICE,
68            Self::Android=>Self::ANDROID,
69            Self::WebAssembly=>Self::WEBASSEMBLY
70        }
71    }
72}
73
74#[cfg(target_os="windows")]
75#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
76pub enum BuildTarget {
77    Release,
78    Debug,
79    Profiler,
80    IosSim{org:String, app:String},
81    IosDevice{org:String, app:String},
82    Android,
83    WebAssembly
84}
85
86#[cfg(target_os="windows")]
87impl BuildTarget {
88    pub fn runs_in_studio(&self)->bool{
89        match self{
90            _=>false
91        }
92    }
93    
94    pub const RELEASE:u64 = 0;
95    pub const DEBUG:u64 = 1;
96    pub const PROFILER:u64 = 2;
97    pub const IOS_SIM:u64 = 3;
98    pub const IOS_DEVICE:u64 = 4;
99    pub const ANDROID:u64 = 5;
100    pub const WEBASSEMBLY:u64 = 6;
101    pub fn len() -> u64 {7}
102    pub fn name(idx: u64) -> &'static str {
103        match idx {
104            Self::RELEASE=> "Release",
105            Self::DEBUG=> "Debug",
106            Self::PROFILER=> "Profiler",
107            Self::IOS_SIM=> "iOS Simulator",
108            Self::IOS_DEVICE=> "iOS Device",
109            Self::ANDROID=> "Android",
110            Self::WEBASSEMBLY=> "WebAssembly",
111            _=>"Unknown"
112        }
113    }
114    pub fn id(&self) -> u64 {
115        match self {
116            Self::Release=>Self::RELEASE,
117            Self::Debug=>Self::DEBUG,
118            Self::Profiler=>Self::PROFILER,
119            Self::IosSim{..}=>Self::IOS_SIM,
120            Self::IosDevice{..}=>Self::IOS_DEVICE,
121            Self::Android=>Self::ANDROID,
122            Self::WebAssembly=>Self::WEBASSEMBLY
123        }
124    }
125}
126
127
128#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
129pub struct BuildProcess{
130    pub binary: String,
131    pub target: BuildTarget
132}
133
134impl BuildProcess{
135    pub fn as_id(&self)->LiveId{
136        LiveId::from_str(&self.binary).bytes_append(&self.target.id().to_be_bytes())
137    }
138}
139
140
141#[derive(Clone, Debug)]
142pub struct BuildCmdWrap {
143    pub cmd_id: BuildCmdId,
144    pub cmd: BuildCmd
145}
146
147impl BuildCmdId{
148    pub fn wrap_msg(&self, item:LogItem)->LogItemWrap{
149        LogItemWrap{
150            cmd_id: *self,
151            item,
152        }
153    }
154}
155
156#[derive(Clone, Debug)]
157pub enum BuildCmd {
158    Stop,
159    Run(BuildProcess, String),
160    HostToStdin(String)
161}
162
163#[derive(Clone)]
164pub struct LogItemWrap {
165    pub cmd_id: BuildCmdId,
166    pub item: LogItem
167}
168
169#[derive(Clone, Copy, Debug, SerBin, DeBin)]
170pub enum LogItemLevel{
171    Warning,
172    Error,
173    Log,
174    Wait,
175    Panic,
176}
177
178#[derive(Clone, Debug)]
179pub struct LogItemLocation{
180    pub level: LogItemLevel,
181    pub file_name: String,
182    pub start: Position,
183    pub length: Length,
184    pub msg: String
185}
186
187#[derive(Clone, Debug)]
188pub struct LogItemBare{
189    pub level: LogItemLevel,
190    pub line: String,
191}
192
193#[derive(Clone)]
194pub enum LogItem {
195    Bare(LogItemBare),
196    Location(LogItemLocation),
197    StdinToHost(String),
198    AuxChanHostEndpointCreated(crate::makepad_platform::cx_stdin::aux_chan::HostEndpoint),
199}