Accept new #cgo directives introduced by go 1.24#23439
Conversation
|
Thanks for the PR! @tdyas would this be something you'd be able to review? Seems simple, but I know approximately nothing about Go. |
| @@ -0,0 +1,17 @@ | |||
| package directives | |||
There was a problem hiding this comment.
Source code under testprojects is not necessarily part of the Pants test suite by default. These would be better framed as part of a Python test file which sets up a Go project to be built. There should be existing CGo test files for this purpose.
There was a problem hiding this comment.
OK, thank you for the comment. I'm going to turn the test into a python test like the ones in https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/go/util_rules/cgo_test.py, so that we can have more fine-grained setup/assertions.
|
In 24f5353 I turned the test under |
|
Also needs a |
24f5353 to
82a24e3
Compare
(First of all thank you for the great build tool!)
Go 1.24 introduced new
#cgodirectives for performance improvements. Unfortunately the current pants go plugin does not understand the directives and results in the following error when building:The error message was obtained by running the new test
./pants test testprojects/src/go/pants_test/cgo/directives:with the following diff (to recognize code undertestprojects/src/go/).This PR fixes the issue by changing
saveCgofunction in go package analyzer. Specifically I updatedsaveCgobased on https://github.com/golang/go/blob/go1.26.4/src/go/build/build.go#L1710-L1713 (i.e. catch up with upstream) so that#cgo nocallbackdirective is not rejected.I also added a simple cgo test case. Please let me know if you have a better idea how to test this feature.