edsrzf / mmap-go

A portable mmap package for Go
BSD 3-Clause "New" or "Revised" License
938 stars 129 forks source link

Cannot build with js environment #24

Closed arranlomas closed 2 weeks ago

arranlomas commented 5 years ago

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)
RELAXccc commented 5 years ago

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)

edsrzf commented 5 years ago

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

edsrzf commented 2 years ago

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.

ajalab commented 2 weeks ago

Hi, I made a PR to fix this issue. https://github.com/edsrzf/mmap-go/pull/35