doujiunai2169
doujiunai2169
2019-02-25 18:37
浏览 34
已采纳

Travis构建用于定位Wasm

I'm building a go module targeting Wasm that I need to test.

Current configuration

The travis.yml config:

language: go
go:
  - 1.11.x
before_install:
  - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
  - dep ensure

And the following makefile:

all: deps test 
deps:
    GOOS=js GOARCH=wasm go get ./...
test: 
    GOOS=js GOARCH=wasm go test ./...
test-cover:
    $(GOPATH)/bin/mockgen -source=dom/dom.go -destination=mock/dom.go -package=mock
    $(GOPATH)/bin/mockgen -source=vnode.go -destination=mock/node.go -package=mock
    GOOS=js GOARCH=wasm go test ./... -coverprofile=cover.out
    go tool cover -html=cover.out

And my go env:

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/marvinfrachet/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/marvinfrachet/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/t0/7bv6yclx1d913wtl6rdsvjtr0000gn/T/go-build435765871=/tmp/go-build -gno-record-gcc-switches -fno-common"

The problem

On my build, I'm having the following error:

GOOS=js GOARCH=wasm go get ./...
GOOS=js GOARCH=wasm go test ./...
fork/exec /tmp/go-build540008292/b001/go-vdom-wasm.test: exec format error
FAIL    github.com/mfrachet/go-vdom-wasm    0.004s
?       github.com/mfrachet/go-vdom-wasm/dom    [no test files]
fork/exec /tmp/go-build540008292/b118/helpers.test: exec format error
FAIL    github.com/mfrachet/go-vdom-wasm/helpers    0.005s
?       github.com/mfrachet/go-vdom-wasm/mock   [no test files]

https://travis-ci.org/mfrachet/go-vdom-wasm

On a locale machine, it's working great and my tests all pass.

I think the problem is due to the GOOS=js that doesn't seem to be understood.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqly83915
    dqly83915 2019-02-28 06:33
    已采纳

    It might be that you are missing go_js_wasm_exec in your $PATH, which is required when launching go test with GOOS=js GOARCH=wasm.

    It is located in the misc/wasm directory of the go SDK so this could fix your travis build:

    export PATH="$PATH:$(go env GOROOT)/misc/wasm"
    

    Note that you also need node in your $PATH.

    Another way that works for me is using the -exec option of go test:

    GOOS=js GOARCH=wasm go test -exec="node $(go env GOROOT)/misc/wasm/wasm_exec"
    

    But it is only useful for giving additional options to node (not possible when using go_js_wasm_exec).

    点赞 评论

相关推荐