google / wuffs

Wrangling Untrusted File Formats Safely
Other
4.06k stars 129 forks source link

Installation is deprecated and difficult #62

Closed magnus-ISU closed 2 years ago

magnus-ISU commented 2 years ago

I cannot even figure out how to have wuffs test work.

Getting Started tells you to run go get -v github.com/google/wuffs/cmd/.... This gives the following deprecation notice:

go get: installing executables with 'go get' in module mode is deprecated.
        Use 'go install pkg@version' instead.
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

This still installs binaries into $GOPATH/bin though, so now I run wuffs test and I get

 ╭─mag@magnus in ~/.local/share/go took 6ms
 ╰─λ wuffs test
could not find Wuffs root directory

I do some research and run strace wuffs test and find out its looking for some files in ~/.local/share/go/src/github.com/google/wuffs so I manually create ~/.local/share/go/src/github.com/google and git clone https://github.com/google/wuffs into there, hoping this will work. Now we get

 ╭─mag@magnus in ~/.local/share/go/src/github.com/google took 5s
 ╰─λ wuffs test
exec: "clang-format-5.0": executable file not found in $PATH
wuffs-c: failed

I'm on Arch, so I can't install clang-format v5 from 2017, so I pretend that this isn't a problem and create a link:

 ╭─mag@magnus in ~/.local/share/go/src/github.com/google took 1s
 ╰─λ doas ln -s /bin/clang-format /usr/local/bin/clang-format-5.0

Unsurprisingly, this doesn't work.

 ╭─mag@magnus in ~/.local/share/go/src/github.com/google took 4s
 ╰─λ wuffs test
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-base.c
parse: expected "(", got "implements" at /home/mag/.local/share/go/src/github.com/google/wuffs/std/adler32/common_adler32.wuffs:16

Then this somehow happens which I cannot reproduce:

 ╭─mag@magnus in repo: wuffs on  main via  v1.17.5 took 209ms
[🔴] × doas rm /usr/local/bin/clang-format-5.0 

 ╭─mag@magnus in repo: wuffs on  main via  v1.17.5 took 19ms
 ╰─λ go get -v github.com/google/wuffs/cmd/...
github.com/google/wuffs/lib/readerat
github.com/google/wuffs/lib/dumbindent
github.com/google/wuffs/lib/compression
github.com/google/wuffs/lib/cgozlib
github.com/google/wuffs/cmd/commonflags
github.com/google/wuffs/lang/token
github.com/google/wuffs/lib/flatecut
github.com/google/wuffs/lib/rac
github.com/google/wuffs/lib/interval
github.com/google/wuffs/lib/cgolz4
github.com/google/wuffs/lib/cgozstd
github.com/google/wuffs/cmd/dumbindent
github.com/google/wuffs/lib/zlibcut
github.com/google/wuffs/lang/render
github.com/google/wuffs/lang/wuffsroot
github.com/google/wuffs/lib/internal/racdict
github.com/google/wuffs/lang/ast
github.com/google/wuffs/lang/parse
github.com/google/wuffs/lib/raczlib
github.com/google/wuffs/lang/builtin
github.com/google/wuffs/cmd/wuffsfmt
github.com/google/wuffs/lang/check
github.com/google/wuffs/lib/raczstd
github.com/google/wuffs/lib/raclz4
github.com/google/wuffs/cmd/ractool
github.com/google/wuffs/lang/generate
github.com/google/wuffs/cmd/wuffs
github.com/google/wuffs/internal/cgen
github.com/google/wuffs/cmd/wuffs-c

 ╭─mag@magnus in repo: wuffs on  main via  v1.17.5 took 1s
 ╰─λ wuffs test
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-base.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-adler32.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/adler32.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-bmp.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/bmp.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-cbor.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/cbor.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-crc32.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/crc32.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-deflate.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/deflate.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-lzw.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/lzw.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-gif.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/gif.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-gzip.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/gzip.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-json.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/json.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-nie.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/nie.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-zlib.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/zlib.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-png.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/png.wuffs
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/c/wuffs-std-wbmp.c
gen wrote:      /home/mag/.local/share/go/src/github.com/google/wuffs/gen/wuffs/std/wbmp.wuffs
gen unchanged:  /home/mag/.local/share/go/src/github.com/google/wuffs/release/c/wuffs-unsupported-snapshot.c
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
exec: "clang-9": executable file not found in $PATH
wuffs test: some tests failed

So apparently it depends on both clang-format-5.0 and clang-9 existing in my PATH. And anyway whatever motivation I had to write Wuffs code is now overshadowed by my frustration.

This language seems really cool and I want to try to learn it. I don't know if I'm just using a different target system than the only supported one or something, or if I just don't understand enough about go programming and there's one magic go install something@magic_version_thing? command that's analogous to the old go get that I should just automatically know, or if I'm just dumb, but somehow I'm unable to get wuffs working at the moment and I think the documentation should be updated with a newer, correct way to get this working.

nigeltao commented 2 years ago

Sorry that it's been so difficult. Yeah, upstream Go changed how go get works over the last year or three, introducing their modules concept.

You're almost there. You don't need clang-9 if you say wuffs test -ccompilers=gcc. You weren't to know this, but in hindsight, wuffs test -help would have told you the default value of the -ccompilers flag.

Another thing is that you're presumably trying to run Wuffs v0.2.0 (since it's talking about needing clang-format-5.0), and that Wuffs version is over 2 years old now. Since then, (1) it no longer depends on clang-format-XXX for any value of XXX, and (2) is smarter about finding the Wuffs checkout directory (the "could not find Wuffs root directory" error), which probably would have saved you a bunch of straceing.

I haven't tried it myself, but I'm guessing that if you start again, but with go install pkg@version, using latest instead of v0.2.0, then you'd have a better time.

magnus-ISU commented 2 years ago

go install github.com/google/wuffs@latest also installs v0.2.0 (into pkg/mod/github.com/google/wuffs@0.2.0 rather than src/thing though I assume newer versions of wuffs would use the pkg path maybe if I could figure out how to get one). I guess I'm not seeing what I should be doing differently.

nigeltao commented 2 years ago

Ah, latest "selects the highest available release version" (emphasis added), and "v0.3.0-beta.12" names a pre-release version.

Perhaps try go install github.com/googld/wuffs@v0.3.0-beta.12? I'm still just guessing, though. I haven't had much experience with Go modules, and I'm travelling at the moment so can't try things myself easily.

magnus-ISU commented 2 years ago

We need to rewrite go in wuffs:

 ╭─mag@magnus in ~/.local/share/go took 2s
[🔴] × go install github.com/google/wuffs@v0.3.0-beta.12
go: downloading github.com/google/wuffs v0.3.0-beta.12
go install: github.com/google/wuffs@v0.3.0-beta.12: create zip: test/data/non-ascii/😻.txt: malformed file path "test/data/non-ascii/😻.txt": invalid char '😻'

Is there a way I can just build wuffs from the git repository? I'm confused how I'm the first person to have this issue at this point

nigeltao commented 2 years ago

If you manage to get v0.3.0-beta.12 going, and want to dig into the "could not find Wuffs root directory" error, https://github.com/google/wuffs/blob/v0.3.0-beta.12/lang/wuffsroot/wuffsroot.go is the version 0.3 logic.

Is there a way I can just build wuffs from the git repository?

Try this? (Again, just guessing.)

cd ~/.local/share/go/src/github.com/google/wuffs # or cd your/local/checkout
go install -v github.com/google/wuffs/cmd/...

I'm confused how I'm the first person to have this issue at this point

Yeah, that's weird, hey.

magnus-ISU commented 2 years ago

Okay, that worked finally. I still had to symlink clang-9 to clang but it doesn't seem to matter if clang-9 or clang 13.0.0 is used, and all the tests pass.

I still really think that proper installation instructions should be added to the Getting Started guide, since otherwise its unlikely that many new people will get started with Wuffs.

As far as I can tell, these are:

# Because we can't install it with `go install`
mkdir -p ${GOPATH:-~/go}/pkg/mod/github.com/google && cd ${GOPATH:-~/go}/pkg/mod/github.com/google
rm -rf wuffs && git clone git@github.com:google/wuffs.git
cd wuffs
go install -v github.com/google/wuffs/cmd/...
cd ${GOPATH:-~/go}/
ln -s pkg/mod src

It seems like this should be easier, but I don't even think its a huge problem being hacky as long as the documentation is accurate about it. Also, I don't think hardcoding clang-9 as the binary name for clang is a good idea. I would just do clang, gcc. And probably more importantly since ccompilers is supposed to be a list, I don't think it makes sense for the default behaviour to be to fatally error if the first entry doesn't exist.

in hindsight, wuffs test -help

wuffs --help has nothing to indicate that the commands have their own --helps. (I suppose I could have guessed to try that because wuffs --help has almost nothing at all but indicates that there are potential arguments, but I don't think I should have to guess about how a program works after reading --help)

Thanks for getting back to me quickly, hopefully I can write a .qoi parser with this now.

nigeltao commented 2 years ago

Thanks for getting back to me quickly, hopefully I can write a .qoi parser with this now.

I filed #63 to talk specifically about QOI.