Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't build for wasm (go 1.21 rc) #1394

Closed
imjasonh opened this issue Jul 14, 2023 · 3 comments
Closed

can't build for wasm (go 1.21 rc) #1394

imjasonh opened this issue Jul 14, 2023 · 3 comments

Comments

@imjasonh
Copy link

The upcoming Go 1.21 release includes support for compiling to Web Assembly (wasm): https://tip.golang.org/doc/go1.21#wasm

You can try out the RC:

$ go install golang.org/dl/go1.21rc2@latest
$ go1.21rc2 download
$ go1.21rc2 version
go version go1.21rc2 darwin/arm64

However, I've found that anything I try to build that depends on logrus fails when building for Wasm:

GOOS=wasip1 GOARCH=wasm go1.21rc2 build
# github.com/sirupsen/logrus
../../go/pkg/mod/github.com/sirupsen/[email protected]/terminal_check_notappengine.go:13:10: undefined: isTerminal

(source here: https://gist.github.com/imjasonh/1ca7e1bd0d95d5c54b8550c50fb557bd)

This isn't a big deal for now, because it's still an RC, but it could be nice to figure out how to avoid this dependency for wasm builds.

@imjasonh
Copy link
Author

I suspect we'd just need something like this, but for wasm: https://github.com/sirupsen/logrus/blob/master/terminal_check_js.go

@imjasonh
Copy link
Author

imjasonh commented Jul 14, 2023

Aaaaand you're already on it. 7165f5e

$ go get -u github.com/sirupsen/logrus@master
go: downloading github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af
$ GOOS=wasip1 GOARCH=wasm go1.21rc2 build
# works 

Thank you! 😄

@HarikrishnanBalagopal
Copy link

HarikrishnanBalagopal commented Aug 14, 2023

Update 2

Ok so it seems the PR #1388 is not part of the 1.9.3 release version
Changed the line in go.mod to require github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af and now it works

$ make build-wasm 
CGO_ENABLED=0 GOOS=wasip1 GOARCH=wasm go build -o bin/test.wasm .
# CGO_ENABLED=0 tinygo build -o bin/test.wasm -target=wasi .
$ echo $?
0

Update

With go 1.21

$ go version
go version go1.21.0 darwin/amd64
$ GOOS=wasip1 GOARCH=wasm go build -o main.wasm main.go
# github.com/sirupsen/logrus
/Users/user/go/pkg/mod/github.com/sirupsen/[email protected]/terminal_check_notappengine.go:13:10: undefined: isTerminal

The /Users/user/go/pkg/mod/github.com/sirupsen/[email protected]/terminal_check_notappengine.go file

// +build !appengine,!js,!windows,!nacl,!plan9

package logrus

import (
	"io"
	"os"
)

func checkIfTerminal(w io.Writer) bool {
	switch v := w.(type) {
	case *os.File:
		return isTerminal(int(v.Fd()))
	default:
		return false
	}
}

Original

Hi, I am running into this issue when compiling with TinyGo for WASI target

$ go version
go version go1.20.7 darwin/amd64
$ tinygo version
tinygo version 0.28.1 darwin/amd64 (using go version go1.20.7 and LLVM version 15.0.0)
$ tinygo build -o main.wasm -target=wasi main.go

tinygo:wasm-ld: error: /var/folders/dt/y3srs7vs6pz9bqwrbjwt38pc0000gp/T/tinygo4119433949/main.o: undefined symbol: golang.org/x/sys/unix.Syscall
failed to run tool: wasm-ld
error: failed to link /var/folders/dt/y3srs7vs6pz9bqwrbjwt38pc0000gp/T/tinygo4119433949/main: exit status 1

The main.go file

package main

import "github.com/sirupsen/logrus"

func main() {
	logrus.Infof("start")
	logrus.Infof("done")
}

The go.mod file

module foo.com/b

go 1.20

require github.com/sirupsen/logrus v1.9.3

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect

The go.sum file

github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants