22
33use std:: str:: FromStr ;
44
5- use crate :: install:: { ClientOpt , Malloc , ServerOpt } ;
5+ use crate :: install:: { ClientOpt , ServerOpt } ;
66
77xflags:: xflags! {
88 src "./src/flags.rs"
@@ -36,6 +36,10 @@ xflags::xflags! {
3636 optional --dry-run
3737 }
3838 cmd dist {
39+ /// Use mimalloc allocator for server
40+ optional --mimalloc
41+ /// Use jemalloc allocator for server
42+ optional --jemalloc
3943 optional --client-patch-version version: String
4044 }
4145 /// Read a changelog AsciiDoc file and update the GitHub Releases entry in Markdown.
@@ -81,35 +85,6 @@ pub enum XtaskCmd {
8185 Codegen ( Codegen ) ,
8286}
8387
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- }
11388#[ derive( Debug ) ]
11489pub struct Install {
11590 pub client : bool ,
@@ -135,6 +110,8 @@ pub struct Promote {
135110
136111#[ derive( Debug ) ]
137112pub struct Dist {
113+ pub mimalloc : bool ,
114+ pub jemalloc : bool ,
138115 pub client_patch_version : Option < String > ,
139116}
140117
@@ -145,6 +122,65 @@ pub struct PublishReleaseNotes {
145122 pub dry_run : bool ,
146123}
147124
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+
148184#[ derive( Debug ) ]
149185pub enum MeasurementType {
150186 Build ,
@@ -185,33 +221,22 @@ impl AsRef<str> for MeasurementType {
185221 }
186222}
187223
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 ,
196229}
197230
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+ }
212238 }
213239}
214- // generated end
215240
216241impl Install {
217242 pub ( crate ) fn server ( & self ) -> Option < ServerOpt > {
@@ -234,3 +259,15 @@ impl Install {
234259 Some ( ClientOpt { code_bin : self . code_bin . clone ( ) } )
235260 }
236261}
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