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

GH-32832: [Go] support building with tinygo #35723

Merged
merged 4 commits into from
Jun 12, 2023

Conversation

chriscasola
Copy link
Contributor

@chriscasola chriscasola commented May 23, 2023

Rationale for this change

To support compiling with tinygo which enables use of arrow in environments where binary size is important, like web assembly.

What changes are included in this PR?

Using an internal JSON package that uses goccy/go-json for regular builds as it does currently, but uses the native encoding/json for tinygo builds. This is necessary because go-json has a lot of code that is incompatible with tinygo.

Remove dependency on parquet package from non-parquet code since it is also incompatible with tinygo.

Other minor tweaks for compatibility with tinygo.

Are these changes tested?

Should we add a build step that compiles the example with tinygo?

Are there any user-facing changes?

None.

@github-actions
Copy link

@github-actions
Copy link

⚠️ GitHub issue #32832 has been automatically assigned in GitHub to PR creator.

@chriscasola
Copy link
Contributor Author

@zeroshade we're still testing this on our end, but it does work. I'm curious what your thoughts are.

Copy link
Member

@zeroshade zeroshade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this LGTM, just a few nit picks

dev/release/rat_exclude_files.txt Outdated Show resolved Hide resolved
go/arrow/array/string.go Outdated Show resolved Hide resolved
Comment on lines 221 to 226
beg := a.array.data.offset
end := beg + a.array.data.length
data := a.values[a.offsets[beg]:a.offsets[end]]

s := (*reflect.SliceHeader)(unsafe.Pointer(&ret))
s.Data = (*reflect.StringHeader)(unsafe.Pointer(&data)).Data
s.Len = len(data)
s.Cap = len(data)
return
return []byte(data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to get updated to no longer be copying the string (like the equivalent function for (*String)

go/arrow/bitutil/bitutil.go Show resolved Hide resolved
go/arrow/compute/arithmetic_test.go Show resolved Hide resolved
go/arrow/compute/cast_test.go Show resolved Hide resolved
go/internal/hashing/xxh3_memo_table.go Outdated Show resolved Hide resolved
@chriscasola chriscasola force-pushed the choff--wasm branch 3 times, most recently from 5f41f87 to 66cacfb Compare May 30, 2023 18:53
@github-actions github-actions bot added awaiting changes Awaiting changes awaiting change review Awaiting change review and removed awaiting review Awaiting review awaiting changes Awaiting changes awaiting change review Awaiting change review labels May 30, 2023
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels May 30, 2023
@chriscasola
Copy link
Contributor Author

@zeroshade thanks for the review, I think I addressed everything.

What are you thoughts on building with tinygo in CI? The CI setup on this repo seems complex so I'm not sure what that would entail, but it would be nice to avoid new code being introduced that does not build.

Comment on lines 27 to 28
"github.com/goccy/go-json"
"github.com/apache/arrow/go/v13/internal/json"

"github.com/apache/arrow/go/v13/arrow"
"github.com/apache/arrow/go/v13/arrow/array"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the failed dev scripts test is because when we run the auto update scripts this gets updated as a separate block. Can you remove the empty space below the updated import and just group all the arrow imports together (alphabetically)?

i.e.:

...
"strings"

"github.com/apache/arrow/go/v13/arrow"
"github.com/apache/arrow/go/v13/arrow/array"
"github.com/apache/arrow/go/v13/internal/json"
"github.com/google/uuid"
"golang.org/x/xerrors"

thanks.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jun 1, 2023
@zeroshade
Copy link
Member

@chriscasola Do you think it's sufficient to just have a single x86-64/linux CI run with tinygo? Or do you think we'd need for arm and other cases too?

@chriscasola
Copy link
Contributor Author

@chriscasola Do you think it's sufficient to just have a single x86-64/linux CI run with tinygo? Or do you think we'd need for arm and other cases too?

I think a single architecture is fine.

@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jun 1, 2023
remove parquet import in hashing

cleanup type check

fix uintptr usage

exclude goccy/go-json for tinygo builds

last uintptr problem
@chriscasola chriscasola force-pushed the choff--wasm branch 2 times, most recently from d066919 to b2fb989 Compare June 2, 2023 16:24
Comment on lines +399 to +403
name: TinyGo
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.title, 'WIP') }}
env:
TINYGO_VERSION: 0.27.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would suggest adding an image to the docker-compose.yml and a dockerfile to ci/docker/ which is an image with tinygo installed and then use archery docker run like other examples.

Comment on lines +22 to +27
cd ~
pushd /src
tinygo build -tags noasm -o ~/example_tinygo arrow/_examples/helloworld/main.go
popd

./example_tinygo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to not just have it run the unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately tinygo can't compile/run unit tests right now. At least it can't handle the ones in this project. See this issue.


cd ~
pushd /src
tinygo build -tags noasm -o ~/example_tinygo arrow/_examples/helloworld/main.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we update all of the go build constraints for noasm to be noasm || tinygo or whatever the equivalent is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeroshade I attempted to do this, but it seems like package outside arrow might also have a noasm flag. Even after adding the tinygo condition everywhere there was a noasm condition, I still couldn't build with out the noasm tag. Are you okay omitting this for now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea that's fine for now. We should probably figure out which package it is that has the noasm condition etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately tinygo is just erroring without enough context to find the file at fault. I'm not sure if there's a way to find it with the standard go toolchain.

@chriscasola chriscasola marked this pull request as ready for review June 12, 2023 15:48
@chriscasola
Copy link
Contributor Author

@zeroshade this is ready for review and has been fully tested to work with tinygo in our app's environment.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jun 12, 2023
Copy link
Member

@zeroshade zeroshade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one request: can you add to the go/arrow/doc.go file's package comment documentation the info about building with tinygo like needing the noasm tag, etc.?

Otherwise this looks good to me.

@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jun 12, 2023
@zeroshade zeroshade merged commit 245404e into apache:main Jun 12, 2023
@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels Jun 12, 2023
@ursabot
Copy link

ursabot commented Jun 13, 2023

Benchmark runs are scheduled for baseline = b642707 and contender = 245404e. 245404e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished ⬇️25.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Finished ⬇️1.24% ⬆️0.12%] test-mac-arm
[Finished ⬇️0.0% ⬆️0.65%] ursa-i9-9960x
[Finished ⬇️0.06% ⬆️0.48%] ursa-thinkcentre-m75q
Buildkite builds:
[Finished] 245404e2 ec2-t3-xlarge-us-east-2
[Finished] 245404e2 test-mac-arm
[Finished] 245404e2 ursa-i9-9960x
[Finished] 245404e2 ursa-thinkcentre-m75q
[Finished] b642707f ec2-t3-xlarge-us-east-2
[Finished] b642707f test-mac-arm
[Finished] b642707f ursa-i9-9960x
[Finished] b642707f ursa-thinkcentre-m75q
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@tschaub
Copy link
Contributor

tschaub commented Sep 21, 2023

Cool to see this got in. I wonder if anybody looked into what it would take to get the Parquet packages working as well. I may give it another try at some point.

@zeroshade
Copy link
Member

I believe the current blocker on the parquet packages is that something in the Thrift dependency is not compatible with tinygo

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

Successfully merging this pull request may close these issues.

[Go] Unable to build with tinygo
4 participants