I'm trying to compile a specific go program to WASM: https://github.com/protomaps/go-pmtiles
Using this command: GOOS=js GOARCH=wasm go build -o go.wasm main.go gives me a following error:
package command-line-arguments
imports github.com/protomaps/go-pmtiles/pmtiles
imports zombiezen.com/go/sqlite
imports modernc.org/libc
imports modernc.org/libc/errno: build constraints exclude all Go files in /Users/patryk/go/pkg/mod/modernc.org/[email protected]/errno
package command-line-arguments
imports github.com/protomaps/go-pmtiles/pmtiles
imports zombiezen.com/go/sqlite
imports modernc.org/libc
imports modernc.org/libc/pthread: build constraints exclude all Go files in /Users/patryk/go/pkg/mod/modernc.org/[email protected]/pthread
package command-line-arguments
imports github.com/protomaps/go-pmtiles/pmtiles
imports zombiezen.com/go/sqlite
imports modernc.org/libc
imports modernc.org/libc/signal: build constraints exclude all Go files in /Users/patryk/go/pkg/mod/modernc.org/[email protected]/signal
package command-line-arguments
imports github.com/protomaps/go-pmtiles/pmtiles
imports zombiezen.com/go/sqlite
imports modernc.org/libc
imports modernc.org/libc/stdio: build constraints exclude all Go files in /Users/patryk/go/pkg/mod/modernc.org/[email protected]/stdio
package command-line-arguments
imports github.com/protomaps/go-pmtiles/pmtiles
imports zombiezen.com/go/sqlite
imports modernc.org/libc/sys/types: build constraints exclude all Go files in /Users/patryk/go/pkg/mod/modernc.org/[email protected]/sys/types
package command-line-arguments
imports github.com/protomaps/go-pmtiles/pmtiles
imports zombiezen.com/go/sqlite
imports modernc.org/libc
imports modernc.org/libc/time: build constraints exclude all Go files in /Users/patryk/go/pkg/mod/modernc.org/[email protected]/time
package command-line-arguments
imports github.com/protomaps/go-pmtiles/pmtiles
imports zombiezen.com/go/sqlite
imports modernc.org/libc
imports modernc.org/libc/unistd: build constraints exclude all Go files in /Users/patryk/go/pkg/mod/modernc.org/[email protected]/unistd
I don't have much experience with WASM. From what I understand, libc package has an issue here.
Any googled answers to "build constraints exclude all Go files" didn't do the trick.
It compiles to my Mac without a problem, so I guess WASM has limitations which prevent some packages from working? If yes, are these limitations described somewhere? Is it possible to make this program work in WASM or is it simply incompatible?
go-pmtiles utilities parts of modernc.org/sqlite and as per this issue:
So it looks like some work would be required to add WASM support.
The error
imports modernc.org/libc/errno: build constraints exclude all Go files in /Users/patryk/go/pkg/mod/modernc.org/[email protected]/errnoreally means what it says. If you take a look at the folder you will note that all files have suffixes like_amd64.go. The build tool will ignore files like this that don't match the target operating system/architecture. In this case you are building for WASM and all files are excluded (hence the error).You would need to look into how go-pmtiles is using modernc.org/libc (imported via zombiezen.com/go/sqlite). Based on a really quick look it appears this is used to "Convert an existing archive on disk to a new PMTiles specification version 3 archive.". So it may be possible to fork the library and remove the unneeded functionality (and hence remove the need to import zombiezen.com/go/sqlite).