This removes WithWorkDirFS and any other attempts to resolve the current directory (".") in host functions. This is a reaction to reality of compilers who track this inside wasm (not via host functions). One nice side effect is substantially simpler internal implementation of file-systems.
This also allows experimental.WithFS to block file access via passing nil.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
22 lines
578 B
Go
22 lines
578 B
Go
package experimental
|
|
|
|
import (
|
|
"context"
|
|
"io/fs"
|
|
|
|
"github.com/tetratelabs/wazero/api"
|
|
internalfs "github.com/tetratelabs/wazero/internal/sys"
|
|
)
|
|
|
|
// WithFS overrides fs.FS in the context-based manner. Caller needs to take
|
|
// responsibility for closing the filesystem.
|
|
//
|
|
// Note: This has the same effect as the same function on wazero.ModuleConfig.
|
|
func WithFS(ctx context.Context, fs fs.FS) (context.Context, api.Closer) {
|
|
if fs == nil {
|
|
fs = internalfs.EmptyFS
|
|
}
|
|
fsCtx := internalfs.NewFSContext(fs)
|
|
return context.WithValue(ctx, internalfs.FSKey{}, fsCtx), fsCtx
|
|
}
|