ref: 669cccaa2d0e9a1508e0180094b6fbf00f10e14e
parent: c60f8cc10168f64505d2923db576301285f21671
author: Slashscreen <SlashScreen@users.noreply.github.com>
date: Wed Aug 9 21:12:07 EDT 2023
added manual page, setting up other program actions, updated wazero.
--- a/go.mod
+++ b/go.mod
@@ -2,4 +2,4 @@
go 1.19
-require github.com/tetratelabs/wazero v1.3.2-0.20230730235628-1f8c908f1c61 // indirect
+require github.com/tetratelabs/wazero v1.4.0
--- a/go.sum
+++ b/go.sum
@@ -2,3 +2,5 @@
github.com/tetratelabs/wazero v1.2.1/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
github.com/tetratelabs/wazero v1.3.2-0.20230730235628-1f8c908f1c61 h1:yPFIE2EV4ztzCwR5wC9IhZbKbCu2aokdk+v12wUSeZM=
github.com/tetratelabs/wazero v1.3.2-0.20230730235628-1f8c908f1c61/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
+github.com/tetratelabs/wazero v1.4.0 h1:9/MirYvmkJ/zSUOygKY/ia3t+e+RqIZXKbylIby1WYk=
+github.com/tetratelabs/wazero v1.4.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
--- a/ricket.go
+++ b/ricket.go
@@ -4,6 +4,7 @@
"context"
"crypto/rand"
_ "embed"
+ "fmt"
"log"
"os"
@@ -12,9 +13,28 @@
)
func main() {
+ if len(os.Args) == 1 {
+ fmt.Println("Not enough arguments. Type \"ricket help\" for usage.")
+ return
+ }
+
+ switch os.Args[1] {
+ case "run":
+ run_program()
+ case "package":
+ package_file()
+ case "help", "?":
+ help()
+ default:
+ fmt.Printf("Unknown command: %s", os.Args[1])
+ }
+}
+
+func run_program() {
// Check for arguments
- if len(os.Args) < 2 {
- log.Panicf("No path to WASM file given. Usage: ricket [path]")
+ if len(os.Args) < 3 {
+ log.Println("No path to WASM file provided.")
+ return
}
ctx := context.Background()
@@ -26,11 +46,16 @@
wasi_snapshot_preview1.MustInstantiate(ctx, r)
// Read program
- wasm, err := os.ReadFile(os.Args[1])
+ wasm, err := os.ReadFile(os.Args[2])
if err != nil {
log.Panicf("failed to read WASM file: %v", err)
}
+ var wasmArgs []string
+ if len(os.Args) > 3 {
+ wasmArgs = os.Args[3:]
+ }
+
// Run program
conf := wazero.NewModuleConfig().
WithStdout(os.Stdout).
@@ -40,10 +65,24 @@
WithSysNanotime().
WithSysWalltime().
WithFSConfig(wazero.NewFSConfig()).
- WithRandSource(rand.Reader)
+ WithRandSource(rand.Reader).
+ WithArgs(wasmArgs...)
_, err = r.InstantiateWithConfig(ctx, wasm, conf)
if err != nil {
log.Panicf("failed to instantiate WASM program: %v", err)
}
+}
+
+func package_file() {
+
+}
+
+func help() {
+ println(`
+usage:
+ ricket run path [ args ... ] - run a .wasm file at <path>, passing in any arguments.
+ ricket package path name bin_dir [ -o ] - package a .wasm file at <path> into a standalone program called <name> at <bin_dir>, <-o>ptionally <-o>mitting the copied ricket executable.
+ ricket help | ? - open this page. Plan 9 users should instead run 'man ricket'.
+ `)
}
--- /dev/null
+++ b/ricket.troff
@@ -1,0 +1,95 @@
+.TH MAN 1
+.SH NAME
+
+ricket \- run and manage WASI programs
+
+.SH SYNOPSIS
+
+.PP
+.B ricket run
+.B path
+[
+.BI args ...
+]
+
+.PP
+.B ricket package path name bin_dir
+[
+.B -o
+.I omit
+]
+
+.PP
+.B ricket
+.IR help | ?
+
+.SH DESCRIPTION
+
+.PP
+.I ricket
+is a WASI runtime for Plan 9 from Bell Labs, which allows for running CLI
+applications written in languages that cannot natively compile to Plan 9.
+
+.PP
+.B ricket run
+will run the .wasm file at the path specified by
+.BR path .
+Any
+.B args
+will be passed into the program.
+
+.PP
+.B ricket package
+will bundle the .wasm file at the path specified by
+.B path
+with a copy of the
+.I ricket
+executable, creating a standalone application with the name
+.B name
+and deposit the contents at
+.BR bin_dir .
+Passing in
+.B -o
+will omit the
+.I ricket
+executable, relying on an already-installed and globally-accessible
+.IR ricket .
+This will make the program smaller, at the cost of no longer being standalone.
+.PP
+In-depth, this process creates these files:
+.RS
+1. A copy of the
+.I ricket
+executable (by default).
+
+2. A copy of the desired .wasm file.
+
+3. An .rc file that calls the
+.I ricket
+executable (or otherwise installed if
+.B -o
+is passed) with the relevant arguments.
+
+4. an mk file that will finish installation into your system. see
+.BI mk (1)
+.RE
+The program itself is the .rc file, allowing the user to simply type
+.I my_program
+instead of
+.I ricket run my_program.wasm
+, and allow for easy (if large) distribution.
+
+.PP
+.B ricket
+.IR help | ?
+will open a brief help page. This is intended for non-Plan 9 users of
+.IR ricket ;
+Plan 9 users should use
+.B man ricket
+instead to open this page.
+
+.SH BUGS
+
+While not strictly a bug,
+.I ricket
+must interperet the WASM file, which can be slow as dirt. Perhaps JIT compilation will be availible in the future.
\ No newline at end of file