Skip to content

Commit

Permalink
fix: drop linkname to allow exec on go 1.23+
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Nov 8, 2024
1 parent c4ada2b commit 04416c7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '^1.23'
cache: false
- run: go get
- run: go generate ./...
Expand All @@ -34,7 +34,7 @@ jobs:
uses: actions/setup-go@v5
with:
cache: false
go-version: '1.20'
go-version: '^1.23'
- run: go get
- run: go generate ./...
- name: Go vet
Expand Down
14 changes: 0 additions & 14 deletions utils/crypto/rand.go

This file was deleted.

23 changes: 23 additions & 0 deletions utils/crypto/rand_1.21.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//go:build !go1.22

package crypto

import (
_ "unsafe" // required by go:linkname
)

// randuint32 returns a lock free uint32 value.
//
// Too much legacy code has go:linkname references
// to runtime.fastrand and friends, so keep these around for now.
// Code should migrate to math/rand/v2.Uint64,
// which is just as fast, but that's only available in Go 1.22+.
// It would be reasonable to remove these in Go 1.24.
// Do not call these from package runtime.
//
//go:linkname randuint32 runtime.fastrand
func randuint32() uint32

func RandU32() uint32 {
return randuint32()
}
11 changes: 11 additions & 0 deletions utils/crypto/rand_1.22.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build go1.22

package crypto

import (
"math/rand/v2"
)

func RandU32() uint32 {
return rand.Uint32()

Check failure on line 10 in utils/crypto/rand_1.22.go

View workflow job for this annotation

GitHub Actions / lint

undefined: rand (typecheck)
}

0 comments on commit 04416c7

Please sign in to comment.