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:
1
.github/workflows/commit.yaml
vendored
1
.github/workflows/commit.yaml
vendored
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !plan9 && !js
|
||||
//go:build !plan9 && !js && !tinygo
|
||||
|
||||
package sock
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build plan9 || js
|
||||
//go:build plan9 || js || tinygo
|
||||
|
||||
package sock
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build linux
|
||||
//go:build linux && !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
13
internal/sysfs/datasync_tinygo.go
Normal file
13
internal/sysfs/datasync_tinygo.go
Normal 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
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
42
internal/sysfs/dirfs_supported.go
Normal file
42
internal/sysfs/dirfs_supported.go
Normal 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)
|
||||
}
|
||||
34
internal/sysfs/dirfs_unsupported.go
Normal file
34
internal/sysfs/dirfs_unsupported.go
Normal 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
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build unix
|
||||
//go:build unix && !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !unix && !windows
|
||||
//go:build !(unix || windows) || tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build linux || darwin
|
||||
//go:build (linux || darwin) && !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !linux && !darwin
|
||||
//go:build (!windows && !linux && !darwin) || tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !plan9
|
||||
//go:build !windows && !plan9 && !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
14
internal/sysfs/ino_tinygo.go
Normal file
14
internal/sysfs/ino_tinygo.go
Normal 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
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !plan9
|
||||
//go:build !windows && !plan9 && !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build plan9 || tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import "github.com/tetratelabs/wazero/experimental/sys"
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows
|
||||
//go:build !windows && !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
25
internal/sysfs/open_file_tinygo.go
Normal file
25
internal/sysfs/open_file_tinygo.go
Normal 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
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build windows || linux || darwin
|
||||
//go:build windows || (linux && !tinygo) || darwin
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !linux && !darwin && !windows
|
||||
//go:build !(linux || darwin || windows) || tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !plan9
|
||||
//go:build !windows && !plan9 && !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !plan9
|
||||
//go:build !windows && !plan9 && !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user