uutils

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 9 Imported by: 0

README

uutils

gonix compat layer for https://github.com/uutils

  1. embeds wasm build like coreutils.wasm
  2. provides FilterBuilderFunc for https://codeberg.org/gonix/sh
  3. implements unix.Filter so individual utilities can be exported.
  4. Supports passing of working dir and environment variables from a shell context.

This brings GNU compatible utilities to the gonix project.

Supported utilities

![WARNING] this project is structured to support more utilities from the project. However as of March 2026 the wasm build of coreutils is the only one available.

Example

For a full code see [test/internal/uutils_test.go], this example omits some details. It showcases the flexibility of a gonix project, where one can easily combine various tool implementations in a single script.

![NOTE] the $lang/$tool is just a convention to show that the various flavors working together. Exporting uutils.Wc as wc is fine.

// import "codeberg.org/gonix/gonix/cat"
builder, _ := uutils.NewBuilder(ctx)
runtime := builder.Runtime(ctx)
coreutils, err := root.Coreutils(ctx)

// Go(nix) cat implementation is exposed as "go/cat"
// and rust wc from coreutils as "rust/wc"
// naming is arbitrary - ham/cat or word-count would
// work as well
var cmds = map[string]sh.FilterBuilderFunc{
  "go/cat":  cat.FromArgs,
  "rust/wc": coreutils.Wc(),
}

const script = "go/cat test.me | rust/wc -l"
file, _ := syntax.NewParser().
  Parse(strings.NewReader(script), "")

runner, err := interp.New(
  ...
  interp.ExecHandlers(filters.ExecHandler),
)
_ = runner.Run(context.Background(), file)

fmt.Printf("gonix-shell> %s\n%s\n", script, got.String())

And a result is

gonix-shell> go/cat test.me | rust/wc -l
3

Supported tools

Coreutils
  • arch
  • b2sum
  • base32
  • base64
  • basename
  • basenc
  • cksum
  • cut
  • date
  • dircolors
  • dirname
  • echo
  • expand
  • factor
  • false
  • fmt
  • fold
  • join
  • link
  • md5sum
  • nl
  • numfmt
  • od
  • paste
  • pr
  • printenv
  • printf
  • ptx
  • pwd
  • seq
  • sha1sum
  • sha224sum
  • sha256sum
  • sha384sum
  • sha512sum
  • shred
  • shuf
  • sleep
  • sum
  • tee
  • true
  • truncate
  • uname
  • unexpand
  • uniq
  • unlink
  • wc
  • yes

Documentation

Overview

Package uutils exposes WebAssembly build of Rust-based implementations of common Unix utilities

It implements these utilities as unix.Filter interfaces and provides the integration with the sh package of a gonix so WASM-backed commands can be used transparently in pipelines and scripts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func License

func License() string

License returns uutils license text

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is a builder of a wazero runtime a main shared context for wasm execution - it contains the shared wazero Runtime and filesystem configuration and environment variables

func NewBuilder

func NewBuilder(ctx context.Context) (*Builder, error)

func (*Builder) Build

func (b *Builder) Build(ctx context.Context) *Runtime

func (*Builder) Close

func (b *Builder) Close(ctx context.Context) error

func (*Builder) SetCacheDir

func (b *Builder) SetCacheDir(dir string) error

func (*Builder) SetDirMounts

func (b *Builder) SetDirMounts(mounts []DirMount)

SetDirMounts sets the parameters for wazero.FSConfig

func (*Builder) SetFSMounts

func (b *Builder) SetFSMounts(mounts []FSMount)

SetFSMounts sets the parameters for wazero.FSConfig

type Coreutils

type Coreutils struct {
	// contains filtered or unexported fields
}

Coreutils wraps the coreutils WebAssembly module

func (Coreutils) All

func (c Coreutils) All(prefix string) unix.FilterLookupFunc

All returns a map of all coreutils commands with the given prefix

func (Coreutils) Arch

func (c Coreutils) Arch() unix.FilterBuilderFunc

func (Coreutils) B2sum

func (c Coreutils) B2sum() unix.FilterBuilderFunc

func (Coreutils) Base32

func (c Coreutils) Base32() unix.FilterBuilderFunc

func (Coreutils) Base64

func (c Coreutils) Base64() unix.FilterBuilderFunc

func (Coreutils) Basename

func (c Coreutils) Basename() unix.FilterBuilderFunc

func (Coreutils) Basenc

func (c Coreutils) Basenc() unix.FilterBuilderFunc

func (Coreutils) Cksum

func (c Coreutils) Cksum() unix.FilterBuilderFunc

func (Coreutils) Cut

func (Coreutils) Date

func (c Coreutils) Date() unix.FilterBuilderFunc

func (Coreutils) Dircolors

func (c Coreutils) Dircolors() unix.FilterBuilderFunc

func (Coreutils) Dirname

func (c Coreutils) Dirname() unix.FilterBuilderFunc

func (Coreutils) Echo

func (c Coreutils) Echo() unix.FilterBuilderFunc

func (Coreutils) Expand

func (c Coreutils) Expand() unix.FilterBuilderFunc

func (Coreutils) Factor

func (c Coreutils) Factor() unix.FilterBuilderFunc

func (Coreutils) False

func (c Coreutils) False() unix.FilterBuilderFunc

func (Coreutils) Fmt

func (Coreutils) Fold

func (c Coreutils) Fold() unix.FilterBuilderFunc

func (Coreutils) Join

func (c Coreutils) Join() unix.FilterBuilderFunc
func (c Coreutils) Link() unix.FilterBuilderFunc

func (Coreutils) Md5sum

func (c Coreutils) Md5sum() unix.FilterBuilderFunc

func (Coreutils) Nl

func (Coreutils) Numfmt

func (c Coreutils) Numfmt() unix.FilterBuilderFunc

func (Coreutils) Od

func (Coreutils) Paste

func (c Coreutils) Paste() unix.FilterBuilderFunc

func (Coreutils) Pr

func (Coreutils) Printenv

func (c Coreutils) Printenv() unix.FilterBuilderFunc

func (Coreutils) Printf

func (c Coreutils) Printf() unix.FilterBuilderFunc

func (Coreutils) Ptx

func (Coreutils) Pwd

func (Coreutils) Seq

func (Coreutils) Sha1sum

func (c Coreutils) Sha1sum() unix.FilterBuilderFunc

func (Coreutils) Sha224sum

func (c Coreutils) Sha224sum() unix.FilterBuilderFunc

func (Coreutils) Sha256sum

func (c Coreutils) Sha256sum() unix.FilterBuilderFunc

func (Coreutils) Sha384sum

func (c Coreutils) Sha384sum() unix.FilterBuilderFunc

func (Coreutils) Sha512sum

func (c Coreutils) Sha512sum() unix.FilterBuilderFunc

func (Coreutils) Shred

func (c Coreutils) Shred() unix.FilterBuilderFunc

func (Coreutils) Shuf

func (c Coreutils) Shuf() unix.FilterBuilderFunc

func (Coreutils) Sleep

func (c Coreutils) Sleep() unix.FilterBuilderFunc

func (Coreutils) Sum

func (Coreutils) Tee

func (Coreutils) True

func (c Coreutils) True() unix.FilterBuilderFunc

func (Coreutils) Truncate

func (c Coreutils) Truncate() unix.FilterBuilderFunc

func (Coreutils) Uname

func (c Coreutils) Uname() unix.FilterBuilderFunc

func (Coreutils) Unexpand

func (c Coreutils) Unexpand() unix.FilterBuilderFunc

func (Coreutils) Uniq

func (c Coreutils) Uniq() unix.FilterBuilderFunc
func (c Coreutils) Unlink() unix.FilterBuilderFunc

func (Coreutils) Version

func (c Coreutils) Version() string

func (Coreutils) Wc

func (Coreutils) Yes

type DirMount

type DirMount struct {
	Dir       string
	GuestPath string
	ReadOnly  bool
}

DirMount is a parameter for wazero.WithDirMount or wazero.WithReadOnlyDirMount

type FSMount

type FSMount struct {
	Dir       fs.FS
	GuestPath string
}

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter implements unix.Filter allowing the wasm implementation to be integrated into gonix

func (Filter) Run

func (f Filter) Run(ctx context.Context, stdio unix.StandardIO) error

type FilterBuilderFunc

type FilterBuilderFunc = func(argv []string) (unix.Filter, error)

FilterBuilderFunc is a function returning a filter for a given command name. This integrates with the gonix/sh package

type GetDirFunc

type GetDirFunc = func(context.Context) (string, bool)

GetDirFunc extracts working directory from shell context

type GetEnvFunc

type GetEnvFunc = func(context.Context) map[string]string

GetEnvFunc extracts env variables from context

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

func (*Runtime) Close

func (r *Runtime) Close(ctx context.Context) error

func (*Runtime) Coreutils

func (r *Runtime) Coreutils(ctx context.Context) (Coreutils, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL