Skip to content

Commit

Permalink
support wasi (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddddddO committed Aug 26, 2023
1 parent a46718c commit de1e0f2
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ root_h/
root_i/
root_j/
Primate/
cmd/gtree/gtree
cmd/gtree/gtree
gtree.wasm
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
hotreload:
air

# sudo GOOS=wasip1 GOARCH=wasm go build -o gtree.wasm ./cmd/gtree
wasi:
GOOS=wasip1 GOARCH=wasm go build -o gtree.wasm ./cmd/gtree

sweep:
rm -rf ./root/ ./root1/ ./root2/ ./root3/ ./root4/ ./root5/ ./root6/ ./root7/ ./root8/ Primate/ gtree/
rm -rf ./root_a/ ./root_b/ ./root_c/ ./root_d/ ./root_e/ ./root_f/ ./root_g/ ./root_h/ ./root_i/ ./root_j/
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ $ gtree web

# CLI

> **Note**<br>
> WASM binary with WASI support are also available.
> Basically, the usage is the same as the CLI built with Go.
> Please refer [here](README_wasi_wasm.md) for usage.
## Installation

<pre>
Expand Down Expand Up @@ -78,6 +83,9 @@ $ port install gtree

<a href="https://github.com/aquaproj/aqua-registry/blob/main/pkgs/ddddddO/gtree/pkg.yaml"><b>aqua</b></a>

<a href="https://github.com/ddddddO/gtree/releases"><b>WASI</b></a>
$ Go to GitHub releases and Download `gtree.wasm`

<a href="https://github.com/ddddddO/gtree/pkgs/container/gtree"><b>Docker</b></a>
$ docker pull ghcr.io/ddddddo/gtree:latest
$ docker run ghcr.io/ddddddo/gtree:latest template | docker run -i ghcr.io/ddddddo/gtree:latest output
Expand Down
139 changes: 139 additions & 0 deletions README_wasi_wasm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
## 1. Install WASM runtime
- https://wasmtime.dev/

## 2. Download *`gtree.wasm`*
- https://github.com/ddddddO/gtree/releases

## 3. Use in console!
### *Help*
```console
$ wasmtime gtree.wasm help
NAME:
gtree - This CLI uses Markdown to generate directory trees and directories itself, and also verifies directories.
The symbols that can be used in Markdown are '-', '+', '*', and '#'.

USAGE:
gtree [global options] command [command options] [arguments...]

VERSION:
1.9.6 / revision xxx

COMMANDS:
output, o, out Outputs tree from markdown.
Let's try 'gtree template | gtree output'.
mkdir, m Makes directories and files from markdown. It is possible to dry run.
Let's try 'gtree template | gtree mkdir -e .go -e .md -e Makefile'.
verify, vf Verifies tree structure represented in markdown by comparing it with existing directories.
Let's try 'gtree template | gtree verify'.
template, t, tmpl Outputs markdown template. Use it to try out gtree CLI.
web, w, www Opens "Tree Maker" in your browser and shows the URL in terminal.
gocode, gc, code Outputs a sample Go program calling "gtree" package.
version, v Prints the version.
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
```

### *Template*
```console
$ wasmtime gtree.wasm template
- gtree
- cmd
- gtree
- main.go
- testdata
- sample1.md
- sample2.md
- Makefile
- tree.go
```

### *Output*
```console
$ wasmtime gtree.wasm template | wasmtime gtree.wasm output
gtree
├── cmd
│ └── gtree
│ └── main.go
├── testdata
│ ├── sample1.md
│ └── sample2.md
├── Makefile
└── tree.go
```

### *Mkdir*
```console
$ wasmtime gtree.wasm template | wasmtime gtree.wasm mkdir --dry-run -e .go -e .md -e Makefile
gtree
├── cmd
│ └── gtree
│ └── main.go
├── testdata
│ ├── sample1.md
│ └── sample2.md
├── Makefile
└── tree.go

4 directories, 5 files
$ tree gtree
gtree [error opening dir]

0 directories, 0 files
$ wasmtime gtree.wasm template | wasmtime --dir=$PWD gtree.wasm mkdir -e .go -e .md -e Makefile
$ tree gtree
gtree
├── Makefile
├── cmd
│ └── gtree
│ └── main.go
├── testdata
│ ├── sample1.md
│ └── sample2.md
└── tree.go

3 directories, 5 files
```

### *Verify*
```console
$ tree example
example
├── find_pipe_programmable-gtree
│   └── main.go
├── go-list_pipe_programmable-gtree
│   └── main.go
├── like_cli
│   ├── adapter
│   │   ├── executor.go
│   │   └── indentation.go
│   └── main.go
├── noexist
│   └── xxx
└── programmable
└── main.go

6 directories, 7 files
$ cat testdata/sample9.md
- example
- find_pipe_programmable-gtree
- main.go
- go-list_pipe_programmable-gtree
- main.go
- like_cli
- adapter
- executor.go
- indentation.go
- main.go
- kkk
- programmable
- main.go
$ cat testdata/sample9.md | wasmtime --dir=$PWD gtree.wasm verify --strict
Extra paths exist:
example/noexist
example/noexist/xxx
Required paths does not exist:
example/like_cli/kkk
```
2 changes: 1 addition & 1 deletion cmd/gtree-wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ confirm:
# -> gzip圧縮で268KBだった。
# ただ、goのwasm_exec.jsではなく、tinygo/targets/wasm_exec.js を使用する。ref: https://tinygo.org/docs/guides/webassembly/#how-it-works
tinybuild:
tinygo build -o main.wasm -target wasm -tags wasm main.go
tinygo build -o main.wasm -target wasm -tags tinywasm main.go

deploy: confirm tinybuild
cleancss -o ../../docs/main.css main.css
Expand Down
2 changes: 1 addition & 1 deletion pipeline_tree.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion pipeline_tree_grower.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion pipeline_tree_mkdirer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion pipeline_tree_spreader.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion pipeline_tree_verifier.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion root_generator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion simple_tree.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion simple_tree_grower.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion simple_tree_mkdirer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion simple_tree_spreader.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion simple_tree_verifier.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion tree.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion tree_handler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion tree_handler_programmably.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !wasm
//go:build !tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion wasm_root_generator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build wasm
//go:build tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion wasm_tree.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build wasm
//go:build tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion wasm_tree_grower.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build wasm
//go:build tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion wasm_tree_handler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build wasm
//go:build tinywasm

package gtree

Expand Down
2 changes: 1 addition & 1 deletion wasm_tree_spreader.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build wasm
//go:build tinywasm

package gtree

Expand Down

0 comments on commit de1e0f2

Please sign in to comment.