From 0d74097c8e684f084c9c51493ad6055abbc2fcf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sat, 9 Nov 2024 09:46:54 +0900 Subject: [PATCH] fix: drop linkname to allow exec on go 1.23+ (#112) --- .github/workflows/test_and_lint.yml | 23 +++++------------- go.mod | 15 ++++++------ go.sum | 36 ++++++++++++----------------- utils/crypto/rand.go | 14 ----------- utils/crypto/rand_1.21.go | 23 ++++++++++++++++++ utils/crypto/rand_1.22.go | 11 +++++++++ 6 files changed, 62 insertions(+), 60 deletions(-) delete mode 100644 utils/crypto/rand.go create mode 100644 utils/crypto/rand_1.21.go create mode 100644 utils/crypto/rand_1.22.go diff --git a/.github/workflows/test_and_lint.yml b/.github/workflows/test_and_lint.yml index 2720847c..6010695a 100644 --- a/.github/workflows/test_and_lint.yml +++ b/.github/workflows/test_and_lint.yml @@ -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 ./... @@ -34,27 +34,16 @@ 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 run: go vet ./... - name: GolangCI-Lint - uses: golangci/golangci-lint-action@v3 - if: github.event.name == 'pull_request' + uses: golangci/golangci-lint-action@v6 with: - version: 'v1.55.2' + version: 'v1.61.0' args: '--timeout 9999s' - only-new-issues: true - skip-pkg-cache: true - skip-build-cache: true - - - name: GolangCI-Lint - uses: golangci/golangci-lint-action@v3 - if: github.event.name != 'pull_request' - with: - version: 'v1.55.2' - args: '--timeout 9999s' - skip-pkg-cache: true - skip-build-cache: true + only-new-issues: ${{ github.event.name == 'pull_request' }} + skip-save-cache: true diff --git a/go.mod b/go.mod index bd462435..e93b01d2 100644 --- a/go.mod +++ b/go.mod @@ -5,21 +5,20 @@ go 1.20 require ( github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 - github.com/fumiama/gofastTEA v0.0.10 + github.com/fumiama/gofastTEA v0.1.0 github.com/fumiama/imgsz v0.0.4 github.com/mattn/go-colorable v0.1.13 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.3 - github.com/tidwall/gjson v1.17.1 - golang.org/x/net v0.25.0 - golang.org/x/sync v0.7.0 + github.com/tidwall/gjson v1.18.0 + golang.org/x/net v0.31.0 + golang.org/x/sync v0.9.0 ) require ( - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/stretchr/testify v1.8.0 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect - golang.org/x/image v0.18.0 // indirect - golang.org/x/sys v0.20.0 // indirect + golang.org/x/image v0.16.0 // indirect + golang.org/x/sys v0.27.0 // indirect ) diff --git a/go.sum b/go.sum index 14e5a824..ffe57b34 100644 --- a/go.sum +++ b/go.sum @@ -5,15 +5,14 @@ github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7/go.mod h1:vD7Ra3Q9o github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fumiama/gofastTEA v0.0.10 h1:JJJ+brWD4kie+mmK2TkspDXKzqq0IjXm89aGYfoGhhQ= -github.com/fumiama/gofastTEA v0.0.10/go.mod h1:RIdbYZyB4MbH6ZBlPymRaXn3cD6SedlCu5W/HHfMPBk= +github.com/fumiama/gofastTEA v0.1.0 h1:eW8yCq2BgqijIhgWcdjNuTs9RIOst8M81BKYvqHg0/g= +github.com/fumiama/gofastTEA v0.1.0/go.mod h1:RIdbYZyB4MbH6ZBlPymRaXn3cD6SedlCu5W/HHfMPBk= github.com/fumiama/imgsz v0.0.4 h1:Lsasu2hdSSFS+vnD+nvR1UkiRMK7hcpyYCC0FzgSMFI= github.com/fumiama/imgsz v0.0.4/go.mod h1:bISOQVTlw9sRytPwe8ir7tAaEmyz9hSNj9n8mXMBG0E= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -21,29 +20,24 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U= -github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= +github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= -golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= -golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw= +golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs= +golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= +golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= +golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= +golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/utils/crypto/rand.go b/utils/crypto/rand.go deleted file mode 100644 index 675e5c3e..00000000 --- a/utils/crypto/rand.go +++ /dev/null @@ -1,14 +0,0 @@ -package crypto - -import ( - _ "unsafe" // required by go:linkname -) - -// randuint32 returns a lock free uint32 value. -// -//go:linkname randuint32 runtime.fastrand -func randuint32() uint32 - -func RandU32() uint32 { - return randuint32() -} diff --git a/utils/crypto/rand_1.21.go b/utils/crypto/rand_1.21.go new file mode 100644 index 00000000..1db54d2b --- /dev/null +++ b/utils/crypto/rand_1.21.go @@ -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() +} diff --git a/utils/crypto/rand_1.22.go b/utils/crypto/rand_1.22.go new file mode 100644 index 00000000..e29278fc --- /dev/null +++ b/utils/crypto/rand_1.22.go @@ -0,0 +1,11 @@ +//go:build go1.22 + +package crypto + +import ( + "math/rand/v2" +) + +func RandU32() uint32 { + return rand.Uint32() +}