@@ -79,15 +79,19 @@ enum CargoCommand {
79
79
Run ,
80
80
Test ,
81
81
Bench ,
82
+ Serve ,
82
83
}
83
84
84
85
impl CargoCommand {
85
86
fn buildable ( self ) -> bool {
86
- matches ! ( self , Self :: Build | Self :: Run | Self :: Test | Self :: Bench )
87
+ matches ! (
88
+ self ,
89
+ Self :: Build | Self :: Run | Self :: Test | Self :: Bench | Self :: Serve
90
+ )
87
91
}
88
92
89
93
fn runnable ( self ) -> bool {
90
- matches ! ( self , Self :: Run | Self :: Test | Self :: Bench )
94
+ matches ! ( self , Self :: Run | Self :: Test | Self :: Bench | Self :: Serve )
91
95
}
92
96
93
97
fn testable ( self ) -> bool {
@@ -103,6 +107,7 @@ impl fmt::Display for CargoCommand {
103
107
Self :: Run => write ! ( f, "run" ) ,
104
108
Self :: Test => write ! ( f, "test" ) ,
105
109
Self :: Bench => write ! ( f, "bench" ) ,
110
+ Self :: Serve => write ! ( f, "serve" ) ,
106
111
Self :: Other => write ! ( f, "<unknown>" ) ,
107
112
}
108
113
}
@@ -116,6 +121,7 @@ impl From<&str> for CargoCommand {
116
121
"r" | "run" => Self :: Run ,
117
122
"t" | "test" => Self :: Test ,
118
123
"bench" => Self :: Bench ,
124
+ "serve" => Self :: Serve ,
119
125
_ => Self :: Other ,
120
126
}
121
127
}
@@ -171,8 +177,8 @@ pub async fn run_cargo_command(
171
177
) ;
172
178
173
179
let mut cargo = Command :: new ( & cargo_path) ;
174
- if command == CargoCommand :: Run {
175
- // Treat a run as a build command as we need to componentize the output
180
+ if matches ! ( command, CargoCommand :: Run | CargoCommand :: Serve ) {
181
+ // Treat run and serve as build commands as we need to componentize the output
176
182
cargo. arg ( "build" ) ;
177
183
if let Some ( arg) = args. peek ( ) {
178
184
if Some ( ( * arg) . as_str ( ) ) == subcommand {
@@ -229,7 +235,7 @@ pub async fn run_cargo_command(
229
235
}
230
236
231
237
let runner = if needs_runner && command. runnable ( ) {
232
- Some ( get_runner ( ) ?)
238
+ Some ( get_runner ( command == CargoCommand :: Serve ) ?)
233
239
} else {
234
240
None
235
241
} ;
@@ -253,7 +259,7 @@ pub async fn run_cargo_command(
253
259
Ok ( outputs. into_iter ( ) . map ( |o| o. path ) . collect ( ) )
254
260
}
255
261
256
- fn get_runner ( ) -> Result < PathAndArgs > {
262
+ fn get_runner ( serve : bool ) -> Result < PathAndArgs > {
257
263
let cargo_config = cargo_config2:: Config :: load ( ) ?;
258
264
259
265
// We check here before we actually build that a runtime is present.
@@ -267,7 +273,11 @@ fn get_runner() -> Result<PathAndArgs> {
267
273
. unwrap_or_else ( || {
268
274
(
269
275
PathAndArgs :: new ( "wasmtime" )
270
- . args ( vec ! [ "-S" , "preview2" , "-S" , "common" ] )
276
+ . args ( if serve {
277
+ vec ! [ "serve" ]
278
+ } else {
279
+ vec ! [ "-S" , "preview2" , "-S" , "common" ]
280
+ } )
271
281
. to_owned ( ) ,
272
282
true ,
273
283
)
@@ -439,7 +449,8 @@ fn componentize_artifacts(
439
449
} ;
440
450
441
451
if command. testable ( ) && artifact. profile . test
442
- || ( command == CargoCommand :: Run && !artifact. profile . test )
452
+ || ( matches ! ( command, CargoCommand :: Run | CargoCommand :: Serve )
453
+ && !artifact. profile . test )
443
454
{
444
455
output. display = Some ( output_display_name (
445
456
cargo_metadata,
@@ -525,14 +536,14 @@ fn spawn_outputs(
525
536
} )
526
537
. collect :: < Vec < _ > > ( ) ;
527
538
528
- if command == CargoCommand :: Run && executables. len ( ) > 1 {
539
+ if matches ! ( command, CargoCommand :: Run | CargoCommand :: Serve ) && executables. len ( ) > 1 {
529
540
config. terminal ( ) . error (
530
- "`cargo component run ` can run at most one component, but multiple were specified" ,
541
+ "`cargo component {command} ` can run at most one component, but multiple were specified" ,
531
542
)
532
543
} else if executables. is_empty ( ) {
533
544
config. terminal ( ) . error ( format ! (
534
545
"a component {ty} target must be available for `cargo component {command}`" ,
535
- ty = if command == CargoCommand :: Run {
546
+ ty = if matches! ( command, CargoCommand :: Run | CargoCommand :: Serve ) {
536
547
"bin"
537
548
} else {
538
549
"test"
0 commit comments