makepad_studio/build_manager/
build_protocol.rs

1use crate::{
2    makepad_code_editor::text::Position, makepad_live_id::LiveId, makepad_platform::log::LogLevel,
3    makepad_micro_serde::*,
4};
5
6#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, SerRon, DeRon)]
7pub enum BuildTarget {
8    Release,
9    Debug,
10    ReleaseStudio,
11    DebugStudio,
12    Profiler,
13    IosSim,
14    IosDevice,
15    TvosSim,
16    TvosDevice,
17    Android,
18    Quest,
19    Harmony,
20    WebAssembly,
21    CheckMacos,
22    CheckWindows,
23    CheckLinux,
24    CheckAll,
25}
26
27impl BuildTarget {
28    pub fn runs_in_studio(&self) -> bool {
29        match self {
30            Self::ReleaseStudio => true,
31            Self::DebugStudio => true,
32            _ => false,
33        }
34    }
35
36    pub const RELEASE_STUDIO: u64 = 0;
37    pub const DEBUG_STUDIO: u64 = 1;
38    pub const RELEASE: u64 = 2;
39    pub const DEBUG: u64 = 3;
40    pub const PROFILER: u64 = 4;
41    pub const IOS_SIM: u64 = 5;
42    pub const IOS_DEVICE: u64 = 6;
43    pub const TVOS_SIM: u64 = 7;
44    pub const TVOS_DEVICE: u64 = 8;
45    pub const ANDROID: u64 = 9;
46    pub const QUEST: u64 = 10;
47    pub const HARMONY: u64 = 11;
48    pub const WEBASSEMBLY: u64 = 12;
49    pub const CHECK_MACOS: u64 = 13;
50    pub const CHECK_WINDOWS: u64 = 14;
51    pub const CHECK_LINUX: u64 = 15;
52    pub const CHECK_ALL: u64 = 16;
53    pub fn len() -> usize {
54        Self::CHECK_ALL as usize + 1
55    }
56    pub fn name(&self) -> &'static str {
57        match self {
58            Self::ReleaseStudio => "Studio Release",
59            Self::DebugStudio => "Studio Debug",
60            Self::Release => "Release",
61            Self::Debug => "Debug",
62            Self::Profiler => "Profiler",
63            Self::IosSim => "iOS Simulator",
64            Self::IosDevice => "iOS Device",
65            Self::TvosSim => "tvOS Simulator",
66            Self::TvosDevice => "tvOS Device",
67            Self::Android => "Android",
68            Self::Quest => "Quest",
69            Self::Harmony => "Harmony",
70            Self::WebAssembly => "WebAssembly",
71            Self::CheckMacos => "Check macOS",
72            Self::CheckWindows => "Check Windows",
73            Self::CheckLinux => "Check Linux",
74            Self::CheckAll => "Check All",
75        }
76    }
77    pub fn as_id(&self) -> usize {
78        (match self {
79            Self::ReleaseStudio => Self::RELEASE_STUDIO,
80            Self::DebugStudio => Self::DEBUG_STUDIO,
81            Self::Release => Self::RELEASE,
82            Self::Debug => Self::DEBUG,
83            Self::Profiler => Self::PROFILER,
84            Self::IosSim { .. } => Self::IOS_SIM,
85            Self::IosDevice { .. } => Self::IOS_DEVICE,
86            Self::TvosSim { .. } => Self::TVOS_SIM,
87            Self::TvosDevice { .. } => Self::TVOS_DEVICE,
88            Self::Android => Self::ANDROID,
89            Self::Quest => Self::QUEST,
90            Self::Harmony => Self::HARMONY,
91            Self::WebAssembly => Self::WEBASSEMBLY,
92            Self::CheckMacos => Self::CHECK_MACOS,
93            Self::CheckWindows => Self::CHECK_WINDOWS,
94            Self::CheckLinux => Self::CHECK_LINUX,
95            Self::CheckAll => Self::CHECK_ALL,
96        }) as usize
97    }
98    pub fn from_id(tgt: usize) -> Self {
99        match tgt as u64{
100            Self::RELEASE => Self::Release,
101            Self::DEBUG => Self::Debug,
102            Self::RELEASE_STUDIO => Self::ReleaseStudio,
103            Self::DEBUG_STUDIO => Self::DebugStudio,
104            Self::PROFILER => Self::Profiler,
105            Self::IOS_SIM => Self::IosSim,
106            Self::IOS_DEVICE => Self::IosDevice,
107            Self::TVOS_SIM => Self::TvosSim,
108            Self::TVOS_DEVICE => Self::TvosDevice,
109            Self::ANDROID => Self::Android,
110            Self::HARMONY => Self::Harmony,
111            Self::QUEST => Self::Quest,
112            Self::WEBASSEMBLY => Self::WebAssembly,
113            Self::CHECK_MACOS => Self::CheckMacos,
114            Self::CHECK_WINDOWS => Self::CheckWindows,
115            Self::CHECK_LINUX => Self::CheckLinux,
116            Self::CHECK_ALL => Self::CheckAll,
117            _ => panic!(),
118        }
119    }
120}
121
122#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, SerRon, DeRon)]
123pub struct BuildProcess {
124    pub root: String,
125    pub binary: String,
126    pub target: BuildTarget,
127}
128
129impl BuildProcess {
130    pub fn as_id(&self) -> LiveId {
131        LiveId::from_str(&self.binary).bytes_append(&self.target.as_id().to_be_bytes())
132    }
133}
134
135#[derive(Clone, Debug)]
136pub struct BuildCmdWrap {
137    pub cmd_id: LiveId,
138    pub cmd: BuildCmd,
139}
140
141#[derive(Clone, Debug)]
142pub enum BuildCmd {
143    Stop,
144    Run(BuildProcess, String),
145    HostToStdin(String),
146}
147
148#[derive(Clone)]
149pub struct BuildClientMessageWrap {
150    pub cmd_id: LiveId,
151    pub message: BuildClientMessage,
152}
153
154#[derive(Clone, Debug)]
155pub struct LogItemLocation {
156    pub level: LogLevel,
157    pub file_name: String,
158    pub start: Position,
159    pub end: Position,
160    pub message: String,
161    pub explanation: Option<String>
162}
163
164#[derive(Clone, Debug)]
165pub struct LogItemBare {
166    pub level: LogLevel,
167    pub line: String,
168}
169
170#[derive(Clone, Debug)]
171pub enum LogItem {
172    Bare(LogItemBare),
173    Location(LogItemLocation),
174    StdinToHost(String),
175}
176
177#[derive(Clone)]
178pub enum BuildClientMessage {
179    LogItem(LogItem),
180    AuxChanHostEndpointCreated(crate::makepad_platform::cx_stdin::aux_chan::HostEndpoint),
181}