Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposes writeable filesystem as experimentalsys.FS #1605

Merged
merged 2 commits into from
Jul 30, 2023
Merged

Conversation

codefromthecrypt
Copy link
Contributor

@codefromthecrypt codefromthecrypt commented Jul 30, 2023

This exposes our internal filesystem as experimentalsys.FS, configured with sysfs.FSConfig. This includes all the features used in the CLI including the following:

  • sysfs.NewDirFS - like os.DirFS
  • sysfs.NewReadFS - masks write commands
  • sysfs.Adapt - adapts an fs.FS

Implementors can use one of these or decorate by embedding one. When writing from scratch, embed UnimplementedFS/File accordingly.

Here's an example of how to use this until it is no longer experimental:

import (
	"github.com/tetratelabs/wazero"
	"github.com/tetratelabs/wazero/experimental/sysfs"
)

root := sysfs.NewDirFS(".")

moduleConfig = wazero.NewModuleConfig().
	WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(root, "/"))

Note: This does not yet expose a general testing framework, but someone can try to do that in another PR. It is tricky for reasons including windows portability which become better when we no longer have to support Go 1.18 (when Go 1.21 is released).

Fixes #1532
Fixes #1013
cc @tobychui who asked for this yesterday at COSCUP

This exposes our internal filesystem as `experimentalsys.FS`,
configured with `sysfs.FSConfig`. This includes all the features used in
the CLI including the following:

* `sysfs.NewDirFS` - like `os.DirFS`
* `sysfs.NewReadFS` - masks write commands
* `sysfs.Adapt` - adapts an `fs.FS`

Implementors can use one of these or decorate by embedding one. When
writing from scratch, embed `UnimplementedFS/File` accordingly.

Here's an example of how to use this until it is no longer experimental:
```
import (
	"github.com/tetratelabs/wazero"
	"github.com/tetratelabs/wazero/experimental/sysfs"
)

root := sysfs.NewDirFS(".")

moduleConfig = wazero.NewModuleConfig().
	WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(root, "/"))
```

Note: This does not yet expose a general testing framework, but someone
can try to do that in another PR. It is tricky for reasons including
windows portability which become better when we no longer have to
support Go 1.18 (when Go 1.21 is released).

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
@codefromthecrypt
Copy link
Contributor Author

#1607 polished the default impls a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants