@@ -100,14 +100,16 @@ impl FromStr for Target {
100
100
101
101
/// The build profile controls whether optimizations, debug info, and assertions
102
102
/// are enabled or disabled.
103
- #[ derive( Clone , Copy , Debug ) ]
103
+ #[ derive( Clone , Debug ) ]
104
104
pub enum BuildProfile {
105
105
/// Enable assertions and debug info. Disable optimizations.
106
106
Dev ,
107
107
/// Enable optimizations. Disable assertions and debug info.
108
108
Release ,
109
109
/// Enable optimizations and debug info. Disable assertions.
110
110
Profiling ,
111
+ /// User-defined profile with --profile flag
112
+ Custom ( String ) ,
111
113
}
112
114
113
115
/// Everything required to configure and run the `wasm-pack build` command.
@@ -160,6 +162,10 @@ pub struct BuildOptions {
160
162
/// Create a profiling build. Enable optimizations and debug info.
161
163
pub profiling : bool ,
162
164
165
+ #[ clap( long = "profile" ) ]
166
+ /// User-defined profile with --profile flag
167
+ pub profile : Option < String > ,
168
+
163
169
#[ clap( long = "out-dir" , short = 'd' , default_value = "pkg" ) ]
164
170
/// Sets the output directory with a relative path.
165
171
pub out_dir : String ,
@@ -196,6 +202,7 @@ impl Default for BuildOptions {
196
202
no_opt : false ,
197
203
release : false ,
198
204
profiling : false ,
205
+ profile : None ,
199
206
out_dir : String :: new ( ) ,
200
207
out_name : None ,
201
208
extra_options : Vec :: new ( ) ,
@@ -221,13 +228,19 @@ impl Build {
221
228
let out_dir = crate_path. join ( PathBuf :: from ( build_opts. out_dir ) ) . clean ( ) ;
222
229
223
230
let dev = build_opts. dev || build_opts. debug ;
224
- let profile = match ( dev, build_opts. release , build_opts. profiling ) {
225
- ( false , false , false ) | ( false , true , false ) => BuildProfile :: Release ,
226
- ( true , false , false ) => BuildProfile :: Dev ,
227
- ( false , false , true ) => BuildProfile :: Profiling ,
231
+ let profile = match (
232
+ dev,
233
+ build_opts. release ,
234
+ build_opts. profiling ,
235
+ build_opts. profile ,
236
+ ) {
237
+ ( false , false , false , None ) | ( false , true , false , None ) => BuildProfile :: Release ,
238
+ ( true , false , false , None ) => BuildProfile :: Dev ,
239
+ ( false , false , true , None ) => BuildProfile :: Profiling ,
240
+ ( false , false , false , Some ( profile) ) => BuildProfile :: Custom ( profile) ,
228
241
// Unfortunately, `clap` doesn't expose clap's `conflicts_with`
229
242
// functionality yet, so we have to implement it ourselves.
230
- _ => bail ! ( "Can only supply one of the --dev, --release, or --profiling flags" ) ,
243
+ _ => bail ! ( "Can only supply one of the --dev, --release, --profiling, or --profile 'name' flags" ) ,
231
244
} ;
232
245
233
246
Ok ( Build {
@@ -355,7 +368,7 @@ impl Build {
355
368
356
369
fn step_build_wasm ( & mut self ) -> Result < ( ) > {
357
370
info ! ( "Building wasm..." ) ;
358
- build:: cargo_build_wasm ( & self . crate_path , self . profile , & self . extra_options ) ?;
371
+ build:: cargo_build_wasm ( & self . crate_path , self . profile . clone ( ) , & self . extra_options ) ?;
359
372
360
373
info ! (
361
374
"wasm built at {:#?}." ,
@@ -430,7 +443,7 @@ impl Build {
430
443
self . weak_refs ,
431
444
self . reference_types ,
432
445
self . target ,
433
- self . profile ,
446
+ self . profile . clone ( ) ,
434
447
& self . extra_options ,
435
448
) ?;
436
449
info ! ( "wasm bindings were built at {:#?}." , & self . out_dir) ;
@@ -440,7 +453,7 @@ impl Build {
440
453
fn step_run_wasm_opt ( & mut self ) -> Result < ( ) > {
441
454
let mut args = match self
442
455
. crate_data
443
- . configured_profile ( self . profile )
456
+ . configured_profile ( self . profile . clone ( ) )
444
457
. wasm_opt_args ( )
445
458
{
446
459
Some ( args) => args,
0 commit comments