Tim Schaub created ARROW-17584:
----------------------------------

             Summary: [Go] Unable to build with tinygo
                 Key: ARROW-17584
                 URL: https://issues.apache.org/jira/browse/ARROW-17584
             Project: Apache Arrow
          Issue Type: Bug
          Components: Go
            Reporter: Tim Schaub


I was hoping to use TinyGo to build WASM binaries with Arrow.  TinyGo can 
generate builds that are [1% the 
size|https://tinygo.org/getting-started/overview/#:~:text=The%20only%20difference%20here%2C%20is,used%2C%20and%20the%20associated%20runtime.&text=In%20this%20case%20the%20Go,size%20(251k%20before%20stripping)!]
 of those generated with Go (significant for applications hosted on the web).

Arrow's use of `reflect.SliceHeader` fields limits the portability of the code. 
 For example, the `Len` and `Cap` fields are assumed to be `int` here: 
https://github.com/apache/arrow/blob/go/v9.0.0/go/arrow/bitutil/bitutil.go#L158-L159

Go's [reflect package 
warns|https://github.com/golang/go/blob/go1.19/src/reflect/value.go#L2675-L2685]
 that the SliceHeader "cannot be used safely or portably and its representation 
may change in a later release."

Attempts to build a WASM binary using the github.com/apache/arrow/go/v10 module 
result in failures like this:
{code}
tinygo build -tags noasm -o test.wasm ./main.go
{code}
{code}             
# github.com/apache/arrow/go/v10/arrow/bitutil
../../go/pkg/mod/github.com/apache/arrow/go/v10@v10.0.0-20220831082949-cf27001da088/arrow/bitutil/bitutil.go:158:10:
 invalid operation: h.Len / uint64SizeBytes (mismatched types uintptr and int)
../../go/pkg/mod/github.com/apache/arrow/go/v10@v10.0.0-20220831082949-cf27001da088/arrow/bitutil/bitutil.go:159:10:
 invalid operation: h.Cap / uint64SizeBytes (mismatched types uintptr and int)
{code}

This happens because TinyGo uses `uintptr` for the corresponding types: 
https://github.com/tinygo-org/tinygo/blob/v0.25.0/src/reflect/value.go#L773-L777

This feels like an issue with TinyGo, and it has been ticketed there multiple 
times (see https://github.com/tinygo-org/tinygo/issues/1284).  They lean on the 
warnings in the Go sources that use of the SliceHeader fields makes code 
unportable and suggest changes to the libraries that do not heed this warning.

I don't have a suggested fix or alternative for Arrow's use of SliceHeader 
fields, but I'm wondering if there would be willingness on the part of this 
package to make WASM builds work with TinyGo.  Perhaps the TinyGo authors could 
also offer suggested changes.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to