ajstarks / decksh

decksh implements a domain-specific scripting language for presentations, visualizations, and information displays
Other
59 stars 2 forks source link

wasm and wasi tinygo compilation fails due to xml reflection when encoding. #2

Closed gedw99 closed 1 year ago

gedw99 commented 2 years ago

The xml generation is blocking compilation to wasm and wasi.

Am playing around with building a basic editor and want to run decksh in the browser, so its easier for people to use. Doing compilation stages in the browser makes the editor experience much faster for the user.

This is compiling ./decksh/cmd/decksh/. to WASM using tinygo.

tinygo build -o decksh.wasm -target wasm .
# encoding/xml
/usr/local/opt/go/libexec/src/encoding/xml/typeinfo.go:318:14: typ.FieldByIndex undefined (type reflect.Type has no field or method FieldByIndex)
/usr/local/opt/go/libexec/src/encoding/xml/typeinfo.go:319:14: typ.FieldByIndex undefined (type reflect.Type has no field or method FieldByIndex)

Its when the xml is saved. This is really common problem with tinygo. need to see if there is equivalent for xml :) Its a well known limitation https://tinygo.org/docs/reference/lang-support/stdlib/#encodingxml

everyone uses https://github.com/buger/jsonparser for json encoding and decoding with tinygo. Its much faster at runtime too due to not using reflect.

gedw99 commented 2 years ago

https://github.com/ajstarks/deck/blob/master/deck.go is using struct tags and decksh imports and calls this for the generation. Also the utils package / repo also has xml related code

gedw99 commented 2 years ago

here is the IDE: https://github.com/zalify/easy-email Its react but shows the concept, as well as how a merge happens on a user changing something. But i am planning to build the equivalent with gioui, rather than react. You can try the live demo and its quickly apparent how it can be used for deck xml.

It can i think also be used for decksh. In this case the decksh is being parsed and the deck xml is rendered with giodeck, just like we od now with the pipeline. We just need to add the Design time edit gui to the GIO output. Then as the user ( via the Design time editor changes the decksh markup and it re-renders, but only the changes, which get merged. This is all explained in https://github.com/zalify/easy-email#how-does-it-work

This is using json, not xml though.

gedw99 commented 2 years ago

i got it down to less than 1 mb when stripped, wasm compressed and gzipped -rwxr-xr-x 1 apple staff 2.9M 9 Sep 10:27 decksh.wasm -rw-r--r-- 1 apple staff 862K 9 Sep 10:27 decksh.wasm.gz

gedw99 commented 2 years ago

@ajstarks If you are not at all interested in getting this working for WASM compilation, just let me know.

ajstarks commented 2 years ago

Note that decksh does it's own XML generation without using encoding/xml.

gedw99 commented 2 years ago

good point.. I thought i was going crazy initially cause there was no import of "encoding/xml" ....but the github.com/ajstarks/decksh go.mod imports bring in other things that do use the xml encoder from what i can see.

gedw99 commented 2 years ago

do you have any ideas on this ?

what i see are:

gedw99 commented 2 years ago

Hey @ajstarks this xml golang pkg can do xml encode / decode and get around the wasm tinygo issue perhaps. going to try it out.

https://github.com/beevik/etree