@@ -64,7 +64,7 @@ type ServeCommand struct {
64
64
addr string
65
65
debug bool
66
66
env argparser.OptionalString
67
- file string
67
+ file argparser. OptionalString
68
68
profileGuest bool
69
69
profileGuestDir argparser.OptionalString
70
70
projectDir string
@@ -85,7 +85,7 @@ func NewServeCommand(parent argparser.Registerer, g *global.Data, build *BuildCo
85
85
c .CmdClause .Flag ("debug" , "Run the server in Debug Adapter mode" ).Hidden ().BoolVar (& c .debug )
86
86
c .CmdClause .Flag ("dir" , "Project directory to build (default: current directory)" ).Short ('C' ).Action (c .dir .Set ).StringVar (& c .dir .Value )
87
87
c .CmdClause .Flag ("env" , "The manifest environment config to use (e.g. 'stage' will attempt to read 'fastly.stage.toml')" ).Action (c .env .Set ).StringVar (& c .env .Value )
88
- c .CmdClause .Flag ("file" , fmt . Sprintf ( "The Wasm file to run (causes validation checks for %s to be skipped)" , binWasmPath )). Default ( binWasmPath ).StringVar (& c .file )
88
+ c .CmdClause .Flag ("file" , "The Wasm file to run (causes build process to be skipped)" ). Action ( c . file . Set ).StringVar (& c .file . Value )
89
89
c .CmdClause .Flag ("include-source" , "Include source code in built package" ).Action (c .includeSrc .Set ).BoolVar (& c .includeSrc .Value )
90
90
c .CmdClause .Flag ("language" , "Language type" ).Action (c .lang .Set ).StringVar (& c .lang .Value )
91
91
c .CmdClause .Flag ("metadata-disable" , "Disable Wasm binary metadata annotations" ).Action (c .metadataDisable .Set ).BoolVar (& c .metadataDisable .Value )
@@ -145,7 +145,16 @@ func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error) {
145
145
manifestPath = filepath .Join (c .projectDir , manifestFilename )
146
146
}
147
147
148
- if ! c .skipBuild {
148
+ wasmBinaryToRun := binWasmPath
149
+ if c .file .WasSet {
150
+ wasmBinaryToRun = c .file .Value
151
+ }
152
+
153
+ // We skip the build if explicitly told to with --skip-build but also when the
154
+ // user sets --file to specify their own wasm binary to pass to Viceroy. This
155
+ // is typically for users who compile a Wasm binary using an unsupported
156
+ // programming language for the Fastly Compute platform.
157
+ if ! c .skipBuild && ! c .file .WasSet {
149
158
err = c .Build (in , out )
150
159
if err != nil {
151
160
return err
@@ -169,13 +178,16 @@ func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error) {
169
178
// If the user doesn't set --skip-build then `compute serve` will call
170
179
// `compute build` and the logic there will update the manifest in-memory data
171
180
// with the relevant project directory and environment manifest content.
172
- if c .skipBuild {
181
+ if c .skipBuild || c . file . WasSet {
173
182
err := c .Globals .Manifest .File .Read (manifestPath )
174
183
if err != nil {
175
184
return fmt .Errorf ("failed to parse manifest '%s': %w" , manifestPath , err )
176
185
}
177
186
c .ViceroyVersioner .SetRequestedVersion (c .Globals .Manifest .File .LocalServer .ViceroyVersion )
178
187
if c .Globals .Verbose () {
188
+ if c .skipBuild || c .file .WasSet {
189
+ text .Break (out )
190
+ }
179
191
text .Info (out , "Fastly manifest set to: %s\n \n " , manifestPath )
180
192
}
181
193
}
@@ -210,13 +222,13 @@ func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error) {
210
222
debug : c .debug ,
211
223
errLog : c .Globals .ErrLog ,
212
224
extraArgs : c .ViceroyBinExtraArgs ,
213
- file : c .file ,
214
225
manifestPath : manifestPath ,
215
226
out : out ,
216
227
profileGuest : c .profileGuest ,
217
228
profileGuestDir : c .profileGuestDir ,
218
229
restarted : restart ,
219
230
verbose : c .Globals .Verbose (),
231
+ wasmBinPath : wasmBinaryToRun ,
220
232
watch : c .watch ,
221
233
watchDir : c .watchDir ,
222
234
})
@@ -276,9 +288,6 @@ func (c *ServeCommand) Build(in io.Reader, out io.Writer) error {
276
288
if c .projectDir != "" {
277
289
c .build .SkipChangeDir = true // we've already changed directory
278
290
}
279
- if c .file != "" {
280
- c .build .ServeFile = true
281
- }
282
291
return c .build .Exec (in , out )
283
292
}
284
293
@@ -548,13 +557,13 @@ type localOpts struct {
548
557
debug bool
549
558
errLog fsterr.LogInterface
550
559
extraArgs string
551
- file string
552
560
manifestPath string
553
561
out io.Writer
554
562
profileGuest bool
555
563
profileGuestDir argparser.OptionalString
556
564
restarted bool
557
565
verbose bool
566
+ wasmBinPath string
558
567
watch bool
559
568
watchDir argparser.OptionalString
560
569
}
@@ -564,7 +573,7 @@ func local(opts localOpts) error {
564
573
// NOTE: Viceroy no longer displays errors unless in verbose mode.
565
574
// This can cause confusion for customers: https://github.com/fastly/cli/issues/913
566
575
// So regardless of CLI --verbose flag we'll always set verbose for Viceroy.
567
- args := []string {"-v" , "-C" , opts .manifestPath , "--addr" , opts .addr , opts .file }
576
+ args := []string {"-v" , "-C" , opts .manifestPath , "--addr" , opts .addr , opts .wasmBinPath }
568
577
569
578
if opts .debug {
570
579
args = append (args , "--debug" )
@@ -591,7 +600,8 @@ func local(opts localOpts) error {
591
600
text .Break (opts .out )
592
601
}
593
602
text .Output (opts .out , "%s: %s" , text .BoldYellow ("Manifest" ), opts .manifestPath )
594
- text .Output (opts .out , "%s: %s" , text .BoldYellow ("Wasm binary" ), opts .file )
603
+ text .Output (opts .out , "%s: %s" , text .BoldYellow ("Wasm binary" ), opts .wasmBinPath )
604
+ text .Output (opts .out , "%s: %s" , text .BoldYellow ("Viceroy command" ), strings .Join (args , " " ))
595
605
text .Output (opts .out , "%s: %s" , text .BoldYellow ("Viceroy binary" ), opts .bin )
596
606
597
607
// gosec flagged this:
0 commit comments