easyjson icon indicating copy to clipboard operation
easyjson copied to clipboard

tinygo support?

Open dkegel-fastly opened this issue 4 years ago • 7 comments

It would be nice if easyjson worked in tinygo so it could be used on embedded systems that normal go does not target.

Easygo's tests do not yet run in tinygo. Attempting e.g.

tinygo test ./buffer

fails with

../../../../../../../Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/netdb.h:217:17: unexpected token ILLEGAL

Trying a minimal example without tests also fails, e.g.

$ more go.mod
module example.com/jsondemo

go 1.16

require github.com/mailru/easyjson v0.7.7 // indirect

$ more main.go
package main

import "example.com/jsondemo/demo"

func main() {
        demo.Hello()
}

$ more demo/demo.go 
package demo

import "fmt"
import "log"

type AwesomeStruct struct {
        Foo string
        Bar string
}

func Hello() {
        foo := AwesomeStruct{
                Foo: "buz",
                Bar: "",
        }
        marshaled, err := foo.MarshalJSON()
        if err != nil {
                log.Fatal(err)
        }
        fmt.Printf("%s\n", marshaled) // => {"foo":"buz"}
}

$ easyjson -all demo/demo.go 

$ go run main.go
{"Foo":"buz","Bar":""}

$ tinygo run main.go
# net
../../../../../../../Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/netdb.h:217:17: unexpected token ILLEGAL

dkegel-fastly avatar Apr 24 '21 00:04 dkegel-fastly

I'm still having issues with tinygo and easyjson. Trying to build the example from this issue (go 1.17) ends up with

tinygo build -o test main.go
Undefined symbols for architecture x86_64:
  "_crypto/x509/internal/macos.x509_CFStringCreateWithBytes_trampoline", referenced from:
      _crypto/x509/internal/macos$pack in main.o
  "_internal/abi.FuncPCABI0", referenced from:
      _crypto/x509/internal/macos.StringToCFString in main.o
  "_crypto/ed25519/internal/edwards25519/field.feSquare", referenced from:
      _(*crypto/ed25519/internal/edwards25519/field.Element).Square in main.o
  "_crypto/ed25519/internal/edwards25519/field.feMul", referenced from:
      _(*crypto/ed25519/internal/edwards25519/field.Element).Multiply in main.o
  "_vendor/golang.org/x/sys/cpu.xgetbv", referenced from:
      _runtime.run$1$gowrapper in main.o
  "_crypto/x509/internal/macos.syscall", referenced from:
      _crypto/x509/internal/macos.StringToCFString in main.o
  "_vendor/golang.org/x/sys/cpu.darwinSupportsAVX512", referenced from:
      _runtime.run$1$gowrapper in main.o
  "_vendor/golang.org/x/sys/cpu.cpuid", referenced from:
      _runtime.run$1$gowrapper in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: failed to link /var/folders/65/fslm_l1d40x_xjx2x8w4s5g00000gn/T/tinygo2000666702/main: exit status 1

ppedziwiatr avatar Mar 07 '22 17:03 ppedziwiatr

The tinygo pull requests mentioned that they got things working on linux and wasi but not mac, fwiw.

dkegel-fastly avatar Mar 07 '22 19:03 dkegel-fastly

I'm also still having this issue with Go 1.18.3 and tinygo 0.23.0

$ tinygo run main.go 
tinygo:ld.lld: error: undefined symbol: vendor/golang.org/x/sys/cpu.cpuid
>>> referenced by cpu_x86.go:64 (/usr/lib/go/src/vendor/golang.org/x/sys/cpu/cpu_x86.go:64)
>>>               /home/david/.cache/tinygo/thinlto/llvmcache-B1DAA9FCDD26FCE588056B11F8335D13B495CB67:(runtime.run$1$gowrapper)
>>> referenced by cpu_x86.go:70 (/usr/lib/go/src/vendor/golang.org/x/sys/cpu/cpu_x86.go:70)
>>>               /home/david/.cache/tinygo/thinlto/llvmcache-B1DAA9FCDD26FCE588056B11F8335D13B495CB67:(runtime.run$1$gowrapper)
>>> referenced by cpu_x86.go:109 (/usr/lib/go/src/vendor/golang.org/x/sys/cpu/cpu_x86.go:109)
>>>               /home/david/.cache/tinygo/thinlto/llvmcache-B1DAA9FCDD26FCE588056B11F8335D13B495CB67:(runtime.run$1$gowrapper)
>>> referenced 1 more times

tinygo:ld.lld: error: undefined symbol: vendor/golang.org/x/sys/cpu.xgetbv
>>> referenced by cpu_x86.go:88 (/usr/lib/go/src/vendor/golang.org/x/sys/cpu/cpu_x86.go:88)
>>>               /home/david/.cache/tinygo/thinlto/llvmcache-B1DAA9FCDD26FCE588056B11F8335D13B495CB67:(runtime.run$1$gowrapper)

tinygo:ld.lld: error: undefined symbol: crypto/ed25519/internal/edwards25519/field.feSquare
>>> referenced by fe.go:305 (/usr/lib/go/src/crypto/ed25519/internal/edwards25519/field/fe.go:305)
>>>               /home/david/.cache/tinygo/thinlto/llvmcache-B1DAA9FCDD26FCE588056B11F8335D13B495CB67:((*crypto/ed25519/internal/edwards25519/field.Element).Square)

tinygo:ld.lld: error: undefined symbol: crypto/ed25519/internal/edwards25519/field.feMul
>>> referenced by fe.go:299 (/usr/lib/go/src/crypto/ed25519/internal/edwards25519/field/fe.go:299)
>>>               /home/david/.cache/tinygo/thinlto/llvmcache-B1DAA9FCDD26FCE588056B11F8335D13B495CB67:((*crypto/ed25519/internal/edwards25519/field.Element).Multiply)
failed to run tool: ld.lld
error: failed to link /tmp/tinygo3092260760/main: exit status 1

dvob avatar Jun 12 '22 08:06 dvob

dvob, are you on mac?

dkegel-fastly avatar Jun 12 '22 18:06 dkegel-fastly

dvob, are you on mac?

@dkegel-fastly no, on linux

dvob avatar Jun 15 '22 13:06 dvob

Same - issues using tinygo with @dkegel-fastly 's example:

~/Code/batch/easyjson-test                                                                                                    ⍉
❯ tinygo version
tinygo version 0.27.0 darwin/amd64 (using go version go1.20.4 and LLVM version 15.0.0)

~/Code/batch/easyjson-test
❯ tinygo run main.go
tinygo:ld.lld: error: undefined symbol: _vendor/golang.org/x/sys/cpu.cpuid
>>> referenced by cpu_x86.go:109 (/usr/local/go/src/vendor/golang.org/x/sys/cpu/cpu_x86.go:109)
>>>               /Users/dselans/Library/Caches/tinygo/thinlto/llvmcache-D836F2F57011FE0EF4FB5298B85CE500A673F1D5:(symbol _runtime.run$1$gowrapper+0x291)
>>> referenced by cpu_x86.go:70 (/usr/local/go/src/vendor/golang.org/x/sys/cpu/cpu_x86.go:70)
>>>               /Users/dselans/Library/Caches/tinygo/thinlto/llvmcache-D836F2F57011FE0EF4FB5298B85CE500A673F1D5:(symbol _runtime.run$1$gowrapper+0x1a2)
>>> referenced by cpu_x86.go:64 (/usr/local/go/src/vendor/golang.org/x/sys/cpu/cpu_x86.go:64)
>>>               /Users/dselans/Library/Caches/tinygo/thinlto/llvmcache-D836F2F57011FE0EF4FB5298B85CE500A673F1D5:(symbol _runtime.run$1$gowrapper+0x17e)

tinygo:ld.lld: error: undefined symbol: _vendor/golang.org/x/sys/cpu.xgetbv
>>> referenced by cpu_x86.go:88 (/usr/local/go/src/vendor/golang.org/x/sys/cpu/cpu_x86.go:88)
>>>               /Users/dselans/Library/Caches/tinygo/thinlto/llvmcache-D836F2F57011FE0EF4FB5298B85CE500A673F1D5:(symbol _runtime.run$1$gowrapper+0x254)

tinygo:ld.lld: error: undefined symbol: _crypto/internal/edwards25519/field.feSquare
>>> referenced by fe.go:309 (/usr/local/go/src/crypto/internal/edwards25519/field/fe.go:309)
>>>               /Users/dselans/Library/Caches/tinygo/thinlto/llvmcache-D836F2F57011FE0EF4FB5298B85CE500A673F1D5:(symbol _(*crypto/internal/edwards25519/field.Element).Square+0x5)

tinygo:ld.lld: error: undefined symbol: _crypto/internal/edwards25519/field.feMul
>>> referenced by fe.go:303 (/usr/local/go/src/crypto/internal/edwards25519/field/fe.go:303)
>>>               /Users/dselans/Library/Caches/tinygo/thinlto/llvmcache-D836F2F57011FE0EF4FB5298B85CE500A673F1D5:(symbol _(*crypto/internal/edwards25519/field.Element).Multiply+0x5)

tinygo:ld.lld: error: undefined symbol: _crypto/x509/internal/macos.syscall
>>> referenced by corefoundation.go:77 (/usr/local/go/src/crypto/x509/internal/macos/corefoundation.go:77)
>>>               /Users/dselans/Library/Caches/tinygo/thinlto/llvmcache-D836F2F57011FE0EF4FB5298B85CE500A673F1D5:(symbol _crypto/x509/internal/macos.StringToCFString+0x33)

tinygo:ld.lld: error: undefined symbol: _internal/abi.FuncPCABI0
>>> referenced by corefoundation.go:77 (/usr/local/go/src/crypto/x509/internal/macos/corefoundation.go:77)
>>>               /Users/dselans/Library/Caches/tinygo/thinlto/llvmcache-D836F2F57011FE0EF4FB5298B85CE500A673F1D5:(symbol _crypto/x509/internal/macos.StringToCFString+0x17)

tinygo:ld.lld: error: undefined symbol: _crypto/x509/internal/macos.x509_CFStringCreateWithBytes_trampoline
>>> referenced by /<unknown>
>>>               /Users/dselans/Library/Caches/tinygo/thinlto/llvmcache-D836F2F57011FE0EF4FB5298B85CE500A673F1D5:(symbol _crypto/x509/internal/macos$pack.6+0x8)
failed to run tool: ld.lld
error: failed to link /var/folders/f5/kj28b7cd72b133qnwx6t81wc0000gn/T/tinygo1400670608/main: exit status 1

dselans avatar May 09 '23 21:05 dselans

The x/sys/cpu.cpuid error can be avoided with -tags=purego, FWIW

chipaca avatar Nov 24 '23 12:11 chipaca