@@ -306,16 +306,25 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
306
306
// reads any files.
307
307
//
308
308
// Ex. run --dir=.. --dir=../.. --dir=../../..
309
- dirs := dirsToModuleRoot (result .MainDir , result .ModuleRoot )
309
+ var dirs []string
310
+ switch config .GOOS () {
311
+ case "wasip1" :
312
+ dirs = dirsToModuleRootRel (result .MainDir , result .ModuleRoot )
313
+ case "wasip2" , "linux" :
314
+ dirs = dirsToModuleRootAbs (result .MainDir , result .ModuleRoot )
315
+ default :
316
+ return fmt .Errorf ("unknown GOOS target: %v" , config .GOOS ())
317
+ }
318
+
310
319
args := []string {"run" }
311
- for _ , d := range dirs [ 1 :] {
320
+ for _ , d := range dirs {
312
321
args = append (args , "--dir=" + d )
313
322
}
314
323
315
- // The below re-organizes the arguments so that the current
316
- // directory is added last.
324
+ args = append ( args , "--env=PWD=" + cmd . Dir )
325
+
317
326
args = append (args , cmd .Args [1 :]... )
318
- cmd .Args = append ( cmd . Args [: 1 : 1 ], args ... )
327
+ cmd .Args = args
319
328
}
320
329
321
330
// Run the test.
@@ -356,7 +365,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
356
365
return passed , err
357
366
}
358
367
359
- func dirsToModuleRoot (maindir , modroot string ) []string {
368
+ func dirsToModuleRootRel (maindir , modroot string ) []string {
360
369
var dirs = []string {"." }
361
370
last := ".."
362
371
// strip off path elements until we hit the module root
@@ -369,6 +378,19 @@ func dirsToModuleRoot(maindir, modroot string) []string {
369
378
return dirs
370
379
}
371
380
381
+ func dirsToModuleRootAbs (maindir , modroot string ) []string {
382
+ var dirs = []string {maindir }
383
+ last := filepath .Join (maindir , ".." )
384
+ // strip off path elements until we hit the module root
385
+ // adding `..`, `../..`, `../../..` until we're done
386
+ for maindir != modroot {
387
+ dirs = append (dirs , last )
388
+ last = filepath .Join (last , ".." )
389
+ maindir = filepath .Dir (maindir )
390
+ }
391
+ return dirs
392
+ }
393
+
372
394
// Flash builds and flashes the built binary to the given serial port.
373
395
func Flash (pkgName , port string , options * compileopts.Options ) error {
374
396
config , err := builder .NewConfig (options )
@@ -820,7 +842,6 @@ func buildAndRun(pkgName string, config *compileopts.Config, stdout io.Writer, c
820
842
} else if config .EmulatorName () == "wasmtime" {
821
843
// Wasmtime needs some special flags to pass environment variables
822
844
// and allow reading from the current directory.
823
- emuArgs = append (emuArgs , "--dir=." )
824
845
for _ , v := range environmentVars {
825
846
emuArgs = append (emuArgs , "--env" , v )
826
847
}
@@ -1464,6 +1485,12 @@ func main() {
1464
1485
flag .StringVar (& outpath , "o" , "" , "output filename" )
1465
1486
}
1466
1487
1488
+ var witPackage , witWorld string
1489
+ if command == "help" || command == "build" || command == "test" {
1490
+ flag .StringVar (& witPackage , "wit-package" , "" , "wit package for wasm component embedding" )
1491
+ flag .StringVar (& witWorld , "wit-world" , "" , "wit world for wasm component embedding" )
1492
+ }
1493
+
1467
1494
var testConfig compileopts.TestConfig
1468
1495
if command == "help" || command == "test" {
1469
1496
flag .BoolVar (& testConfig .CompileOnly , "c" , false , "compile the test binary but do not run it" )
@@ -1543,6 +1570,8 @@ func main() {
1543
1570
Monitor : * monitor ,
1544
1571
BaudRate : * baudrate ,
1545
1572
Timeout : * timeout ,
1573
+ WitPackage : witPackage ,
1574
+ WitWorld : witWorld ,
1546
1575
}
1547
1576
if * printCommands {
1548
1577
options .PrintCommands = printCommand
0 commit comments