internal: add tags and stubs so wazero can be compiled for MCU targets (#2166)

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
Ron Evans
2024-03-31 11:11:31 +02:00
committed by GitHub
parent 9cdb0e32a2
commit 22e3861510
27 changed files with 151 additions and 67 deletions

View File

@@ -167,6 +167,7 @@ jobs:
with:
tinygo-version: "0.31.2"
- run: tinygo build ./cmd/wazero
- run: tinygo build -size short -target pico -stack-size=8kb ./cmd/wazero
bench:
name: Benchmark

View File

@@ -1,4 +1,4 @@
//go:build !plan9 && !js
//go:build !plan9 && !js && !tinygo
package sock

View File

@@ -1,4 +1,4 @@
//go:build plan9 || js
//go:build plan9 || js || tinygo
package sock

View File

@@ -1,4 +1,4 @@
//go:build linux
//go:build linux && !tinygo
package sysfs

View File

@@ -0,0 +1,13 @@
//go:build tinygo
package sysfs
import (
"os"
"github.com/tetratelabs/wazero/experimental/sys"
)
func datasync(f *os.File) sys.Errno {
return sys.ENOSYS
}

View File

@@ -63,18 +63,6 @@ func (d *dirFS) Mkdir(path string, perm fs.FileMode) (errno experimentalsys.Errn
return
}
// Chmod implements the same method as documented on sys.FS
func (d *dirFS) Chmod(path string, perm fs.FileMode) experimentalsys.Errno {
err := os.Chmod(d.join(path), perm)
return experimentalsys.UnwrapOSError(err)
}
// Rename implements the same method as documented on sys.FS
func (d *dirFS) Rename(from, to string) experimentalsys.Errno {
from, to = d.join(from), d.join(to)
return rename(from, to)
}
// Readlink implements the same method as documented on sys.FS
func (d *dirFS) Readlink(path string) (string, experimentalsys.Errno) {
// Note: do not use syscall.Readlink as that causes race on Windows.
@@ -91,20 +79,6 @@ func (d *dirFS) Rmdir(path string) experimentalsys.Errno {
return rmdir(d.join(path))
}
// Unlink implements the same method as documented on sys.FS
func (d *dirFS) Unlink(path string) (err experimentalsys.Errno) {
return unlink(d.join(path))
}
// Symlink implements the same method as documented on sys.FS
func (d *dirFS) Symlink(oldName, link string) experimentalsys.Errno {
// Note: do not resolve `oldName` relative to this dirFS. The link result is always resolved
// when dereference the `link` on its usage (e.g. readlink, read, etc).
// https://github.com/bytecodealliance/cap-std/blob/v1.0.4/cap-std/src/fs/dir.rs#L404-L409
err := os.Symlink(oldName, d.join(link))
return experimentalsys.UnwrapOSError(err)
}
// Utimens implements the same method as documented on sys.FS
func (d *dirFS) Utimens(path string, atim, mtim int64) experimentalsys.Errno {
return utimens(d.join(path), atim, mtim)

View File

@@ -1,15 +0,0 @@
//go:build !tinygo
package sysfs
import (
"os"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
)
// Link implements the same method as documented on sys.FS
func (d *dirFS) Link(oldName, newName string) experimentalsys.Errno {
err := os.Link(d.join(oldName), d.join(newName))
return experimentalsys.UnwrapOSError(err)
}

View File

@@ -1,12 +0,0 @@
//go:build tinygo
package sysfs
import (
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
)
// Link implements the same method as documented on sys.FS
func (d *dirFS) Link(oldName, newName string) experimentalsys.Errno {
return experimentalsys.ENOSYS
}

View File

@@ -0,0 +1,42 @@
//go:build !tinygo
package sysfs
import (
"io/fs"
"os"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
)
// Link implements the same method as documented on sys.FS
func (d *dirFS) Link(oldName, newName string) experimentalsys.Errno {
err := os.Link(d.join(oldName), d.join(newName))
return experimentalsys.UnwrapOSError(err)
}
// Unlink implements the same method as documented on sys.FS
func (d *dirFS) Unlink(path string) (err experimentalsys.Errno) {
return unlink(d.join(path))
}
// Rename implements the same method as documented on sys.FS
func (d *dirFS) Rename(from, to string) experimentalsys.Errno {
from, to = d.join(from), d.join(to)
return rename(from, to)
}
// Chmod implements the same method as documented on sys.FS
func (d *dirFS) Chmod(path string, perm fs.FileMode) experimentalsys.Errno {
err := os.Chmod(d.join(path), perm)
return experimentalsys.UnwrapOSError(err)
}
// Symlink implements the same method as documented on sys.FS
func (d *dirFS) Symlink(oldName, link string) experimentalsys.Errno {
// Note: do not resolve `oldName` relative to this dirFS. The link result is always resolved
// when dereference the `link` on its usage (e.g. readlink, read, etc).
// https://github.com/bytecodealliance/cap-std/blob/v1.0.4/cap-std/src/fs/dir.rs#L404-L409
err := os.Symlink(oldName, d.join(link))
return experimentalsys.UnwrapOSError(err)
}

View File

@@ -0,0 +1,34 @@
//go:build tinygo
package sysfs
import (
"io/fs"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
)
// Link implements the same method as documented on sys.FS
func (d *dirFS) Link(oldName, newName string) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Unlink implements the same method as documented on sys.FS
func (d *dirFS) Unlink(path string) (err experimentalsys.Errno) {
return experimentalsys.ENOSYS
}
// Rename implements the same method as documented on sys.FS
func (d *dirFS) Rename(from, to string) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Chmod implements the same method as documented on sys.FS
func (d *dirFS) Chmod(path string, perm fs.FileMode) experimentalsys.Errno {
return experimentalsys.ENOSYS
}
// Symlink implements the same method as documented on sys.FS
func (d *dirFS) Symlink(oldName, link string) experimentalsys.Errno {
return experimentalsys.ENOSYS
}

View File

@@ -1,4 +1,4 @@
//go:build unix
//go:build unix && !tinygo
package sysfs

View File

@@ -1,4 +1,4 @@
//go:build !unix && !windows
//go:build !(unix || windows) || tinygo
package sysfs

View File

@@ -1,4 +1,4 @@
//go:build linux || darwin
//go:build (linux || darwin) && !tinygo
package sysfs

View File

@@ -1,3 +1,5 @@
//go:build !tinygo
package sysfs
import (

View File

@@ -1,4 +1,4 @@
//go:build !windows && !linux && !darwin
//go:build (!windows && !linux && !darwin) || tinygo
package sysfs

View File

@@ -1,4 +1,4 @@
//go:build !windows && !plan9
//go:build !windows && !plan9 && !tinygo
package sysfs

View File

@@ -0,0 +1,14 @@
//go:build tinygo
package sysfs
import (
"io/fs"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/sys"
)
func inoFromFileInfo(_ string, info fs.FileInfo) (sys.Inode, experimentalsys.Errno) {
return 0, experimentalsys.ENOTSUP
}

View File

@@ -1,4 +1,4 @@
//go:build !windows && !plan9
//go:build !windows && !plan9 && !tinygo
package sysfs

View File

@@ -1,3 +1,5 @@
//go:build plan9 || tinygo
package sysfs
import "github.com/tetratelabs/wazero/experimental/sys"

View File

@@ -1,3 +1,5 @@
//go:build !tinygo
package sysfs
import (

View File

@@ -1,4 +1,4 @@
//go:build !windows
//go:build !windows && !tinygo
package sysfs

View File

@@ -0,0 +1,25 @@
//go:build tinygo
package sysfs
import (
"io/fs"
"os"
"github.com/tetratelabs/wazero/experimental/sys"
)
const supportedSyscallOflag = sys.Oflag(0)
func withSyscallOflag(oflag sys.Oflag, flag int) int {
// O_DIRECTORY not defined
// O_DSYNC not defined
// O_NOFOLLOW not defined
// O_NONBLOCK not defined
// O_RSYNC not defined
return flag
}
func openFile(path string, oflag sys.Oflag, perm fs.FileMode) (*os.File, sys.Errno) {
return nil, sys.ENOSYS
}

View File

@@ -1,4 +1,4 @@
//go:build windows || linux || darwin
//go:build windows || (linux && !tinygo) || darwin
package sysfs

View File

@@ -1,3 +1,5 @@
//go:build !tinygo
package sysfs
import (

View File

@@ -1,4 +1,4 @@
//go:build !linux && !darwin && !windows
//go:build !(linux || darwin || windows) || tinygo
package sysfs

View File

@@ -1,4 +1,4 @@
//go:build !windows && !plan9
//go:build !windows && !plan9 && !tinygo
package sysfs

View File

@@ -1,4 +1,4 @@
//go:build !windows && !plan9
//go:build !windows && !plan9 && !tinygo
package sysfs