2
2
3
3
use std:: str:: FromStr ;
4
4
5
- use crate :: install:: { ClientOpt , Malloc , ServerOpt } ;
5
+ use crate :: install:: { ClientOpt , ServerOpt } ;
6
6
7
7
xflags:: xflags! {
8
8
src "./src/flags.rs"
@@ -36,6 +36,10 @@ xflags::xflags! {
36
36
optional --dry-run
37
37
}
38
38
cmd dist {
39
+ /// Use mimalloc allocator for server
40
+ optional --mimalloc
41
+ /// Use jemalloc allocator for server
42
+ optional --jemalloc
39
43
optional --client-patch-version version: String
40
44
}
41
45
/// Read a changelog AsciiDoc file and update the GitHub Releases entry in Markdown.
@@ -81,35 +85,6 @@ pub enum XtaskCmd {
81
85
Codegen ( Codegen ) ,
82
86
}
83
87
84
- #[ derive( Debug ) ]
85
- pub struct Codegen {
86
- pub check : bool ,
87
- pub codegen_type : Option < CodegenType > ,
88
- }
89
-
90
- #[ derive( Debug , Default ) ]
91
- pub enum CodegenType {
92
- #[ default]
93
- All ,
94
- Grammar ,
95
- AssistsDocTests ,
96
- DiagnosticsDocs ,
97
- LintDefinitions ,
98
- }
99
-
100
- impl FromStr for CodegenType {
101
- type Err = String ;
102
- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
103
- match s {
104
- "all" => Ok ( Self :: All ) ,
105
- "grammar" => Ok ( Self :: Grammar ) ,
106
- "assists-doc-tests" => Ok ( Self :: AssistsDocTests ) ,
107
- "diagnostics-docs" => Ok ( Self :: DiagnosticsDocs ) ,
108
- "lints-definitions" => Ok ( Self :: LintDefinitions ) ,
109
- _ => Err ( "Invalid option" . to_owned ( ) ) ,
110
- }
111
- }
112
- }
113
88
#[ derive( Debug ) ]
114
89
pub struct Install {
115
90
pub client : bool ,
@@ -135,6 +110,8 @@ pub struct Promote {
135
110
136
111
#[ derive( Debug ) ]
137
112
pub struct Dist {
113
+ pub mimalloc : bool ,
114
+ pub jemalloc : bool ,
138
115
pub client_patch_version : Option < String > ,
139
116
}
140
117
@@ -145,6 +122,65 @@ pub struct PublishReleaseNotes {
145
122
pub dry_run : bool ,
146
123
}
147
124
125
+ #[ derive( Debug ) ]
126
+ pub struct Metrics {
127
+ pub measurement_type : Option < MeasurementType > ,
128
+ }
129
+
130
+ #[ derive( Debug ) ]
131
+ pub struct Bb {
132
+ pub suffix : String ,
133
+ }
134
+
135
+ #[ derive( Debug ) ]
136
+ pub struct Codegen {
137
+ pub codegen_type : Option < CodegenType > ,
138
+
139
+ pub check : bool ,
140
+ }
141
+
142
+ impl Xtask {
143
+ #[ allow( dead_code) ]
144
+ pub fn from_env_or_exit ( ) -> Self {
145
+ Self :: from_env_or_exit_ ( )
146
+ }
147
+
148
+ #[ allow( dead_code) ]
149
+ pub fn from_env ( ) -> xflags:: Result < Self > {
150
+ Self :: from_env_ ( )
151
+ }
152
+
153
+ #[ allow( dead_code) ]
154
+ pub fn from_vec ( args : Vec < std:: ffi:: OsString > ) -> xflags:: Result < Self > {
155
+ Self :: from_vec_ ( args)
156
+ }
157
+ }
158
+ // generated end
159
+
160
+ #[ derive( Debug , Default ) ]
161
+ pub enum CodegenType {
162
+ #[ default]
163
+ All ,
164
+ Grammar ,
165
+ AssistsDocTests ,
166
+ DiagnosticsDocs ,
167
+ LintDefinitions ,
168
+ }
169
+
170
+ impl FromStr for CodegenType {
171
+ type Err = String ;
172
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
173
+ match s {
174
+ "all" => Ok ( Self :: All ) ,
175
+ "grammar" => Ok ( Self :: Grammar ) ,
176
+ "assists-doc-tests" => Ok ( Self :: AssistsDocTests ) ,
177
+ "diagnostics-docs" => Ok ( Self :: DiagnosticsDocs ) ,
178
+ "lints-definitions" => Ok ( Self :: LintDefinitions ) ,
179
+ _ => Err ( "Invalid option" . to_owned ( ) ) ,
180
+ }
181
+ }
182
+ }
183
+
148
184
#[ derive( Debug ) ]
149
185
pub enum MeasurementType {
150
186
Build ,
@@ -185,33 +221,22 @@ impl AsRef<str> for MeasurementType {
185
221
}
186
222
}
187
223
188
- #[ derive( Debug ) ]
189
- pub struct Metrics {
190
- pub measurement_type : Option < MeasurementType > ,
191
- }
192
-
193
- #[ derive( Debug ) ]
194
- pub struct Bb {
195
- pub suffix : String ,
224
+ #[ derive( Clone , Copy , Debug ) ]
225
+ pub ( crate ) enum Malloc {
226
+ System ,
227
+ Mimalloc ,
228
+ Jemalloc ,
196
229
}
197
230
198
- impl Xtask {
199
- #[ allow( dead_code) ]
200
- pub fn from_env_or_exit ( ) -> Self {
201
- Self :: from_env_or_exit_ ( )
202
- }
203
-
204
- #[ allow( dead_code) ]
205
- pub fn from_env ( ) -> xflags:: Result < Self > {
206
- Self :: from_env_ ( )
207
- }
208
-
209
- #[ allow( dead_code) ]
210
- pub fn from_vec ( args : Vec < std:: ffi:: OsString > ) -> xflags:: Result < Self > {
211
- Self :: from_vec_ ( args)
231
+ impl Malloc {
232
+ pub ( crate ) fn to_features ( self ) -> & ' static [ & ' static str ] {
233
+ match self {
234
+ Malloc :: System => & [ ] [ ..] ,
235
+ Malloc :: Mimalloc => & [ "--features" , "mimalloc" ] ,
236
+ Malloc :: Jemalloc => & [ "--features" , "jemalloc" ] ,
237
+ }
212
238
}
213
239
}
214
- // generated end
215
240
216
241
impl Install {
217
242
pub ( crate ) fn server ( & self ) -> Option < ServerOpt > {
@@ -234,3 +259,15 @@ impl Install {
234
259
Some ( ClientOpt { code_bin : self . code_bin . clone ( ) } )
235
260
}
236
261
}
262
+
263
+ impl Dist {
264
+ pub ( crate ) fn allocator ( & self ) -> Malloc {
265
+ if self . mimalloc {
266
+ Malloc :: Mimalloc
267
+ } else if self . jemalloc {
268
+ Malloc :: Jemalloc
269
+ } else {
270
+ Malloc :: System
271
+ }
272
+ }
273
+ }
0 commit comments