adrg / sysfont

Golang identification and matching of system fonts
https://pkg.go.dev/github.com/adrg/sysfont
MIT License
41 stars 13 forks source link

Build failure using TinyGo #7

Open tdewolff opened 3 years ago

tdewolff commented 3 years ago

See https://github.com/tdewolff/canvas/issues/83#issuecomment-851223413

It appears that this library cannot be built using TinyGo, is this something you'd like to support?

# github.com/adrg/xdg
github.com/adrg/xdg@v0.3.3/paths_unix.go:18:87: Getuid not declared by package os
github.com/adrg/xdg@v0.3.3/utils.go:59:16: MkdirAll not declared by package os
github.com/adrg/xdg@v0.3.3/utils.go:59:33: ModeDir not declared by package os
adrg commented 3 years ago

Hi @tdewolff. It would be great if TinyGo was supported by xdg (and implicitly by sysfont). However, I think it might be better to raise the issues on the TinyGo repository. It would certainly avoid a lot of workarounds on my part in order to make it work.

From what I can tell, two of the three issues you mentioned are already in work there:

ModeDir not declared by package os: there's already an issue for this (https://github.com/tinygo-org/tinyfs/issues/4) and a PR (https://github.com/tinygo-org/tinygo/pull/1903) which has been merged already.

Getuid not declared by package os: there's already an issue for this one as well (https://github.com/tinygo-org/tinygo/issues/1886) and a PR (https://github.com/tinygo-org/tinygo/pull/1892) which will hopefully be merged soon.

So there's only MkdirAll not declared by package os left. Maybe @gedw99 can open an issue there regarding this because it's not specific to the xdg library.

Are these issues on Go 1.16 only or does this reproduce with Go 1.15 as well?

tdewolff commented 3 years ago

Hey Adrian, thanks for the quick and in-depth response. I agree this would be better to take up with TinyGo!

gedw99 commented 3 years ago

hey @tdewolff @adrg

"So there's only MkdirAll not declared by package os left ..."

Some ideas on this:

  1. Virtualise the OS file system using indexdb as the base store.

https://github.com/JohnStarich/go-wasm/blob/master/internal/js/fs/mkdir.go

Johns project wraps the golang file OS with a indexdb based implementation, allowing golang wasm to work. He uses file embeded at compile time to put the golang src code into the system it seems. This is not what we want though i think. As what you want is to be able to see if the fonts are on the real OS the browser is running on right ?

Yep its crazy but thats the golang src files, sitting there in indexdb. Screenshot 2021-06-04 at 14 49 43

  1. this supports Mkdir: https://github.com/tinygo-org/tinyfs/pull/5

Not sure if this is a viable option for the sysfont project though.

gedw99 commented 3 years ago

Hmm there is also this

https://web.dev/file-system-access/#storing-file-handles-or-directory-handles-in-indexeddb

gedw99 commented 3 years ago

BTW added "no-debug" flag sometimes helps things work

For example: tinygo build -o wasm.wasm -target=wasm -no-debug -tags=example ./examples/2048/

dkegel-fastly commented 2 years ago

tinygo now supports os.MkdirAll().

The next problem blocking "tinygo test" from working in sysfont seems to be unsupported uses of reflect in testify and go-spew, see https://github.com/tinygo-org/tinygo/issues/2650 https://github.com/tinygo-org/tinygo/issues/2649