holzschu / a-Shell-commands

shell commands, pre-compiled to webAssembly, ready to use in a-Shell
551 stars 21 forks source link

Add Fzf #50

Open bbb651 opened 1 month ago

bbb651 commented 1 month ago

This is a dependency to get ani-cli working.

I didn’t find any existing fzf wasm ports, looks like it’s written in go which seems doable.

holzschu commented 1 month ago

Over at https://github.com/holzschu/a-shell/issues/545 you can follow our adventures in cross-compiling a different command written in go (rclone). Let's just say it took several attempts and we still don't have it fully working.

I've tried cross-compiling fzf to WebAssembly already, and failed totally. I'll try again.

bbb651 commented 1 month ago

I did an attempt at compiling it to wasm with wasi, there are some parts that use unix to do unix syscalls that don't work and need porting (dummy.go is probably fine):

❯ rg "!windows"
src/terminal_unix.go
1://go:build !windows

src/util/util_unix.go
1://go:build !windows

src/tui/light_unix.go
1://go:build !windows

src/tui/ttyname_unix.go
1://go:build !windows

src/tui/dummy.go
1://go:build !tcell && !windows

I've never touched go so I'm not sure if I can port it, and there are things that seem difficult to port like terminal size (I remember there's a way to do it with escape sequences), the steps I did to attempt to compile it were make -n to get the go build command and bypass the Makefile, then added GOOS=wasip1 GOARCH=wasm, so:

GOOS=wasip1 GOARCH=wasm go build -a -ldflags "-s -w -X main.version=0.52.1 -X main.revision=01e76689" -tags "" -trimpath -o target/fzf