Open rolsonquadras opened 2 years ago
This is the initial issue with the official tinygo:
$ tinygo build -o src/agent-js-worker.wasm -target wasm
# google.golang.org/protobuf/internal/descfmt
../../../../../../go/pkg/mod/google.golang.org/protobuf@v1.27.1/internal/descfmt/stringer.go:44:31: reflect.ValueOf(vs).MethodByName undefined (type reflect.Value has no field or method MethodByName)
../../../../../../go/pkg/mod/google.golang.org/protobuf@v1.27.1/internal/descfmt/stringer.go:93:29: reflect.ValueOf(vs).MethodByName undefined (type reflect.Value has no field or method MethodByName)
../../../../../../go/pkg/mod/google.golang.org/protobuf@v1.27.1/internal/descfmt/stringer.go:124:11: rv.MethodByName undefined (type reflect.Value has no field or method MethodByName)
../../../../../../go/pkg/mod/google.golang.org/protobuf@v1.27.1/internal/descfmt/stringer.go:194:9: rv.MethodByName undefined (type reflect.Value has no field or method MethodByName)
../../../../../../go/pkg/mod/google.golang.org/protobuf@v1.27.1/internal/descfmt/stringer.go:209:13: v.MethodByName undefined (type reflect.Value has no field or method MethodByName)
../../../../../../go/pkg/mod/google.golang.org/protobuf@v1.27.1/internal/descfmt/stringer.go:219:12: rv.MethodByName undefined (type reflect.Value has no field or method MethodByName)
$ tinygo version
tinygo version 0.22.0 darwin/amd64 (using go version go1.17.6 and LLVM version 13.0.0)
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 os/user
as shown here https://tinygo.org/docs/reference/lang-support/stdlib/.
~/development/securekey/fork/tinygo/build/tinygo version
tinygo version 0.23.0-dev-a7a69d38 darwin/amd64 (using go version go1.17.6 and LLVM version 13.0.0)
$ ~/development/securekey/fork/tinygo/build/tinygo build -o src/agent-js-worker.wasm -target wasm
# net
~/development/securekey/fork/tinygo/src/net/tcpsock.go:28:16: undeclared name: DefaultResolver
~/development/securekey/fork/tinygo/src/net/tcpsock.go:28:49: undeclared name: context
Adding -ldflags "-s -w"
reduced dist
directory from 8.3MB to 8MB
Adding
-ldflags "-s -w"
reduceddist
directory from 8.3MB to 8MB
@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 Steps.pdf
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
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/go@v1.6.1-0.20210519071714-58be99b3c4d0/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/glog@v0.0.0-20160126235308-23def4e6c14b/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 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/indexeddb@v0.0.0-20220202170435-bb5bedb39f36/indexeddb.go:19:2:
package syscall/js is not in GOROOT (/usr/local/go/src/syscall/js)
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.
https://github.com/trustbloc/agent-sdk/blob/ee6d0d474d63ba871fbdbfb82e1f2a53b0aa1518/cmd/agent-js-worker/scripts/build_assets.sh#L8