-
Notifications
You must be signed in to change notification settings - Fork 21
Use tinygo to build wasm #306
Comments
|
This is the initial issue with the official tinygo:
|
Trying with the source code for tinygo I made some changes to make those errors disappear, but those didin't work just changing the tinygo build because some new errors appeared, since tinygo doesn't support
|
Adding |
@victro this is the compressed file size. Can you add uncompressed wasm size as well ? |
I am attaching some documentation of the steps that I did and the current state of the errors for this ticket |
<style>
</style>
Tinygo The first step was to add placeholders for functions not implemented in the following files:
modified: loader/goroot.go modified: src/net/ipsock.go modified: src/net/net.go modified: src/net/tcpsock.go modified: src/os/errors.go modified: src/os/file_unix.go modified: src/os/file_windows.go modified: src/reflect/type.go modified: src/reflect/value.go modified: src/runtime/extern.go modified: src/runtime/symtab.go
And add a new package “user” for with the following content:
package user
func lookupUser(username string) (*User, error) { panic("unimplemented: User.lookupUser()") }
type User struct { // Uid is the user ID. // On POSIX systems, this is a decimal number representing the uid. // On Windows, this is a security identifier (SID) in a string format. // On Plan 9, this is the contents of /dev/user. Uid string // Gid is the primary group ID. // On POSIX systems, this is a decimal number representing the gid. // On Windows, this is a SID in a string format. // On Plan 9, this is the contents of /dev/user. Gid string // Username is the login name. Username string // Name is the user's real or display name. // It might be blank. // On POSIX systems, this is the first (or only) entry in the GECOS field // list. // On Windows, this is the user's display name. // On Plan 9, this is the contents of /dev/user. Name string // HomeDir is the path to the user's home directory (if they have one). HomeDir string }
func Current() (*User, error) { panic("unimplemented: user.Current()") }
I had to change a readonly file just to avoid having the issue of a int conversion error and the file is:
Changes in ../../../../../go/pkg/mod/github.com/google/tink/[email protected]/aead/subtle/aes_gcm.go
And had some issues with os/user that were bypassed by changing the following content in tinygo/loader/goroot.go // The boolean indicates whether to merge the subdirs. True means merge, false // means use the TinyGo version. func pathsToOverride(needsSyscallPackage bool) map[string]bool { paths := map[string]bool{ "": true, "crypto/": true, "crypto/rand/": false, "device/": false, "examples/": false, "internal/": true, "internal/bytealg/": false, "internal/reflectlite/": false, "internal/task/": false, "machine/": false, "net/": true, "os/": true, "os/user/": true, "reflect/": false, "runtime/": false, "sync/": true, "testing/": true, } if needsSyscallPackage { paths["syscall/"] = true // include syscall/js } return paths }
After that make again and the final operation I am working on right now is passing the following issue:
../../../../../../go/pkg/mod/github.com/golang/[email protected]/glog_file.go:118:7: Symlink not declared by package os
This is being called from tinygo/loader/goroot.go
GCCGO
Run all the following commands inside of a linux container in docker to have all the dependencies installedL:
apt install -y software-properties-common wget git gcc-11 add-apt-repository -y ppa:ubuntu-toolchain-r/testadd-apt-repository -y pya:ubuntu-toolchain-r/test update-alternatives --remove-all gcc update-alternatives --remove-all g++
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 10 update-alternatives --install /usr/bin/gccgo gccgo /usr/bin/gccgo-11 10 update-alternatives --install /usr/bin/gccgo gccgo /usr/bin/gccgo-9 20
update-alternatives --set cc /usr/bin/gcc
wget https://go.dev/dl/go1.17.6.linux-amd64.tar.gz rm -rf /usr/local/go && tar -C /usr/local -xzf go1.17.6.linux-amd64.tar.gz export PATH=$PATH:/usr/local/go/bin
The current error at the moment is: /root/go/pkg/mod/github.com/hyperledger/aries-framework-go/component/storage/[email protected]/indexeddb.go:19:2: package syscall/js is not in GOROOT (/usr/local/go/src/syscall/js) Tinygo The first step was to add placeholders for functions not implemented in the following files: modified: loader/goroot.go And add a new package “user” for with the following content: package user func lookupUser(username string) (*User, error) { type User struct { func Current() (*User, error) { I had to change a readonly file just to avoid having the issue of a int conversion error and the file is: Changes in ../../../../../go/pkg/mod/github.com/google/tink/[email protected]/aead/subtle/aes_gcm.go And had some issues with os/user that were bypassed by changing the following content in After that make again and the final operation I am working on right now is passing the following issue: gopkg.in/yaml.v3/Users/victor.rada/development/securekey/fork/tinygo/src/reflect/type.go:376:15: (reflect.Type).Elem() called on map type traceback: This is being called from tinygo/loader/goroot.go GCCGO Run all the following commands inside of a linux container in docker to have all the dependencies installedL: apt install -y software-properties-common wget git gcc-11 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 10 update-alternatives --set cc /usr/bin/gcc wget https://go.dev/dl/go1.17.6.linux-amd64.tar.gz The current error at the moment is: |
34MB |
The following bdd tests are failing with the tinygo build and working fine with the gc compiler:
|
Changes in tinygo are in this commit: |
At the moment after adding the runtime package manually to tinygo the current error to fix is:
|
Putting this ticket on hold, the latest goal for the ticket was to update gjson that doesn't use reflect in latest version |
Currently, the wasm size is around 8.3MB and its built with go bin. We can look to use tinygo inorder to reduce the wasm size.
agent-sdk/cmd/agent-js-worker/scripts/build_assets.sh
Line 8 in ee6d0d4
The text was updated successfully, but these errors were encountered: