edsrzf / mmap-go

A portable mmap package for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot build with js environment

arranlomas opened this issue · comments

I am trying to build for WebAssembly using go web assembly (more info: https://github.com/golang/go/wiki/WebAssembly)

Running: GOOS=js GOARCH=wasm go build -o main.wasm
Error:

# github.com/edsrzf/mmap-go
./mmap.go:77:9: undefined: mmap
./mmap.go:92:10: m.lock undefined (type MMap has no field or method lock, but does have Lock)
./mmap.go:99:10: m.unlock undefined (type MMap has no field or method unlock, but does have Unlock)
./mmap.go:104:10: m.flush undefined (type MMap has no field or method flush, but does have Flush)
./mmap.go:114:10: m.unmap undefined (type *MMap has no field or method unmap, but does have Unmap)

same here, did you find the problem?

# github.com/edsrzf/mmap-go ../github.com/edsrzf/mmap-go/mmap.go:77:9: undefined: mmap ../github.com/edsrzf/mmap-go/mmap.go:92:10: m.lock undefined (type MMap has no field or method lock, but does have Lock) ../github.com/edsrzf/mmap-go/mmap.go:99:10: m.unlock undefined (type MMap has no field or method unlock, but does have Unlock) ../github.com/edsrzf/mmap-go/mmap.go:104:10: m.flush undefined (type MMap has no field or method flush, but does have Flush) ../github.com/edsrzf/mmap-go/mmap.go:114:10: m.unmap undefined (type *MMap has no field or method unmap, but does have Unmap)

The problem is that there is no mmap system call available in a WebAssembly environment. I think we'd need something like this to make it work: https://github.com/WebAssembly/design/blob/master/FutureFeatures.md#finer-grained-control-over-memory

We could make it so that this package at least compiles in a JS environment, similar to what #25 does on Plan 9. I'm not sure of the appropriate error to return in that case, but I'm open to suggestions or pull requests.