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

blst Go bindings no longer compile with Go 1.24 #245

Open
mark-rushakoff opened this issue Dec 16, 2024 · 2 comments
Open

blst Go bindings no longer compile with Go 1.24 #245

mark-rushakoff opened this issue Dec 16, 2024 · 2 comments

Comments

@mark-rushakoff
Copy link

I tried building Go code that references blst at the latest release, and with go1.24rc1 the blst bindings fail to build.

This failure can be reproduced from the blst repository, in the bindings/go directory.

Tests run fine with go1.23:

$ go version ; go test
go version go1.23.4 darwin/arm64
PASS
ok  	github.com/supranational/blst/bindings/go	0.715

With go1.24rc1, the bindings fail to build:

$ ~/go/bin/go1.24rc1 version;  ~/go/bin/go1.24rc1 test .
go version go1.24rc1 darwin/arm64
# github.com/supranational/blst/bindings/go [github.com/supranational/blst/bindings/go.test]
./blst.go:237:11: cannot define new methods on non-local type SecretKey
./blst.go:324:15: cannot define new methods on non-local type SecretKey
./blst.go:444:11: cannot define new methods on non-local type Fp12
./blst.go:448:11: cannot define new methods on non-local type Fp12
./blst.go:452:11: cannot define new methods on non-local type Fp12
./blst.go:456:11: cannot define new methods on non-local type Fp12
./blst.go:462:12: cannot define new methods on non-local type Fp12
./blst.go:482:11: cannot define new methods on non-local type P1Affine
./blst.go:487:11: cannot define new methods on non-local type P1Affine
./blst.go:495:12: cannot define new methods on non-local type P2Affine
./blst.go:495:12: too many errors
FAIL	github.com/supranational/blst/bindings/go [build failed]
FAIL

This appears to be a deliberate change in the Go toolchain, according to the draft Go 1.24 release notes:

The compiler already disallowed defining new methods with receiver types that were cgo-generated, but it was possible to circumvent that restriction via an alias type. Go 1.24 now always reports an error if a receiver denotes a cgo-generated type, whether directly or indirectly (through an alias type).

The HTML comments at that paragraph indicate golang/go#60725 and golang/go#57926.

The fix is probably changing this set of types:

blst/bindings/go/blst.go

Lines 171 to 182 in bef14ca

type Scalar = C.blst_scalar
type Fp = C.blst_fp
type Fp2 = C.blst_fp2
type Fp6 = C.blst_fp6
type Fp12 = C.blst_fp12
type P1 = C.blst_p1
type P2 = C.blst_p2
type P1Affine = C.blst_p1_affine
type P2Affine = C.blst_p2_affine
type Message = []byte
type Pairing = []C.blst_pairing
type SecretKey = Scalar

to "normal" type definitions (e.g. type Scalar C.blst_scalar without the = in the middle) and then defining the required methods, including forwarding all the other methods that already exist on the C.blst_scalar type. I think this would avoid breaking any existing usage, but I haven't really used this package yet so it's a bit of a guess on my part.

@dot-asm
Copy link
Collaborator

dot-asm commented Dec 20, 2024

Thanks for the heads-up! Unfortunately getting rid of = in type declaration doesn't cut it. Could you test #247, i.e. go1.24 branch in https://github.com/dot-asm/blst, with whatever you're working on?

@mark-rushakoff
Copy link
Author

I commented on #247 too -- merging #247 will resolve this issue. Thanks for the quick fix.

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

No branches or pull requests

2 participants