diff --git a/compileopts/config.go b/compileopts/config.go index 7afdded3..b22db15d 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -544,6 +544,8 @@ func (c *Config) Emulator(format, binary string) ([]string, error) { var emulator []string for _, s := range parts { s = strings.ReplaceAll(s, "{root}", goenv.Get("TINYGOROOT")) + // Allow replacement of what's usually /tmp except notably Windows. + s = strings.ReplaceAll(s, "{tmpDir}", os.TempDir()) s = strings.ReplaceAll(s, "{"+format+"}", binary) emulator = append(emulator, s) } diff --git a/main.go b/main.go index 4e24a9ab..44eacb2c 100644 --- a/main.go +++ b/main.go @@ -293,17 +293,6 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options args = append(args, "--dir="+d) } - // Some tests create temp directories using os.MkdirTemp or via - // t.TempDir(). Create a writeable directory and map it to the - // default tempDir environment variable: TMPDIR. - tmpdir, err := os.MkdirTemp("", "tinygotmp") - if err != nil { - return fmt.Errorf("failed to create temporary directory: %w", err) - } - args = append(args, "--dir="+tmpdir, "--env=TMPDIR="+tmpdir) - // TODO: add option to not delete temp dir for debugging? - defer os.RemoveAll(tmpdir) - // The below re-organizes the arguments so that the current // directory is added last. args = append(args, cmd.Args[1:]...) diff --git a/targets/wasi.json b/targets/wasi.json index 6cec6be4..c6b418fe 100644 --- a/targets/wasi.json +++ b/targets/wasi.json @@ -21,6 +21,6 @@ "extra-files": [ "src/runtime/asm_tinygowasm.S" ], - "emulator": "wasmtime {}", + "emulator": "wasmtime --mapdir=/tmp::{tmpDir} {}", "wasm-abi": "generic" }