
This allows you to expand {tmpDir} in the json "emulator" field, and uses it in wasmtime instead of custom TMPDIR mapping logic. Before, we had custom logic for wasmtime to create a separate tmpDir when running go tests. This overwrite the TMPDIR variable when running, after making a mount point. A simpler way to accomplish the end goal of writing temp files is to use wasmtime's map-dir instead. When code is compiled to wasm with the wasi target, tempDir is always /tmp, so we don't need to add variables (since we know what it is). Further, the test code is the same between normal go and run through wasmtime. So, we don't need to make a separate temp dir first, and avoiding that reduces logic, as well makes it easier to swap out the emulator (for wazero which has no depedencies). To map the correct directory, this introduces a {tmpDir} token whose value is the host-specific value taken from `os.TempDir()`. The motivation I have for this isn't so much to clean up the wasmtime code, but allow wazero to execute the same tests. After this change, the only thing needed to pass tests is to change the emulator, due to differences in how wazero deals with relative lookups (they aren't restricted by default, so there's not a huge amount of custom logic needed). In other words, installing wazero from main, `make tinygo-test-wasi` works with no other changes except this PR and patching `targets/wasi.json`. ```json "emulator": "wazero run -mount=.:/ -mount={tmpDir}:/tmp {}", ``` On that note, if there's a way to override the emulator via arg or env, this would be even better, but in any case patching json is fine. Signed-off-by: Adrian Cole <adrian@tetrate.io>
26 строки
654 Б
JSON
26 строки
654 Б
JSON
{
|
|
"llvm-target": "wasm32-unknown-wasi",
|
|
"cpu": "generic",
|
|
"features": "+bulk-memory,+nontrapping-fptoint,+sign-ext",
|
|
"build-tags": ["tinygo.wasm", "wasi", "runtime_memhash_leveldb"],
|
|
"goos": "linux",
|
|
"goarch": "arm",
|
|
"linker": "wasm-ld",
|
|
"libc": "wasi-libc",
|
|
"scheduler": "asyncify",
|
|
"default-stack-size": 16384,
|
|
"cflags": [
|
|
"-mbulk-memory",
|
|
"-mnontrapping-fptoint",
|
|
"-msign-ext"
|
|
],
|
|
"ldflags": [
|
|
"--stack-first",
|
|
"--no-demangle"
|
|
],
|
|
"extra-files": [
|
|
"src/runtime/asm_tinygowasm.S"
|
|
],
|
|
"emulator": "wasmtime --mapdir=/tmp::{tmpDir} {}",
|
|
"wasm-abi": "generic"
|
|
}
|