From fedbcc3fcf1adc544d2a9e53242fb022d3264ee5 Mon Sep 17 00:00:00 2001 From: lmittmann <3458786+lmittmann@users.noreply.github.com> Date: Sun, 3 Mar 2024 16:09:33 +0100 Subject: [PATCH] Added support for Apple Silicon (for `solc >= 0.8.24`) (#40) * internal/version: init * added support for darwin-arm64 * updated setup-go * updated go version * examples: updated go version --------- Co-authored-by: lmittmann --- .github/workflows/go.yml | 35 +++++++++++------------- examples/go.mod | 2 +- go.mod | 2 +- internal/version/version.go | 11 ++++++++ internal/version/version_test.go | 47 ++++++++++++++++++++++++++++++++ params_darwin_arm64.go | 13 +++++++++ params_gen.go | 26 ++++++++++++------ 7 files changed, 106 insertions(+), 30 deletions(-) create mode 100644 internal/version/version.go create mode 100644 internal/version/version_test.go create mode 100644 params_darwin_arm64.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0d2f5d5..b9fe92d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -8,36 +8,33 @@ jobs: fmt_vet: name: Fmt & Vet runs-on: ubuntu-latest + strategy: + matrix: + path: [".", "./examples"] steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: - go-version: '1.21' - - name: go fmt + go-version: "1.22" + - name: go fmt ${{ matrix.path }} run: | + cd ${{ matrix.path }} gofmt -s -d . > fmt.out cat fmt.out test -z $(cat fmt.out) - - name: go vet - run: go vet ./... - - name: go fmt examples - run: | - cd examples/ - gofmt -s -d . > fmt.out - cat fmt.out - test -z $(cat fmt.out) - - name: go vet examples - run: cd examples/ && go vet ./... + - name: go vet ${{ matrix.path }} + run: cd ${{ matrix.path }} && go vet ./... test: name: Test runs-on: ubuntu-latest + strategy: + matrix: + path: [".", "./examples"] steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: - go-version: '1.21' - - name: go test - run: go test ./... - - name: go test examples - run: cd examples/ && go test ./... + go-version: "1.22" + - name: go test ${{ matrix.path }} + run: cd ${{ matrix.path }} && go test ./... diff --git a/examples/go.mod b/examples/go.mod index 83a52af..9aa9b49 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -1,6 +1,6 @@ module examples -go 1.21 +go 1.22 require ( github.com/lmittmann/go-solc v0.0.0 diff --git a/go.mod b/go.mod index 2958922..f36df47 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/lmittmann/go-solc -go 1.21 +go 1.22 require ( github.com/ethereum/go-ethereum v1.13.14 diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..d5f9f78 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,11 @@ +package version + +import "go/version" + +func IsValid(x string) bool { + return version.IsValid("go" + x) +} + +func Compare(x, y string) int { + return version.Compare("go"+x, "go"+y) +} diff --git a/internal/version/version_test.go b/internal/version/version_test.go new file mode 100644 index 0000000..85af718 --- /dev/null +++ b/internal/version/version_test.go @@ -0,0 +1,47 @@ +package version_test + +import ( + "strconv" + "testing" + + "github.com/lmittmann/go-solc/internal/version" +) + +func TestIsValid(t *testing.T) { + tests := []struct { + VersionStr string + Want bool + }{ + {"0.1.2", true}, + {"go0.1.2", false}, + } + + for i, test := range tests { + t.Run(strconv.Itoa(i), func(t *testing.T) { + got := version.IsValid(test.VersionStr) + if test.Want != got { + t.Fatalf("want %t, got %t", test.Want, got) + } + }) + } +} + +func TestCompare(t *testing.T) { + tests := []struct { + X, Y string + Want int + }{ + {"0.5", "0.5", 0}, + {"0.1", "0.5", -1}, + {"0.5", "0.1", 1}, + } + + for i, test := range tests { + t.Run(strconv.Itoa(i), func(t *testing.T) { + got := version.Compare(test.X, test.Y) + if test.Want != got { + t.Fatalf("want %d, got %d", test.Want, got) + } + }) + } +} diff --git a/params_darwin_arm64.go b/params_darwin_arm64.go new file mode 100644 index 0000000..bee61f5 --- /dev/null +++ b/params_darwin_arm64.go @@ -0,0 +1,13 @@ +// Code generated by go generate; DO NOT EDIT. + +//go:build darwin && arm64 + +package solc + +func init() { + solcBaseURL = "https://binaries.soliditylang.org/macosx-amd64/" + + solcVersions = map[string]solcVersion{ + "0.8.24": {Sha256: [32]byte{0xcc, 0x2d, 0x44, 0xc7, 0x06, 0x90, 0x5c, 0xcc, 0x38, 0x2f, 0x48, 0x46, 0x25, 0xdf, 0xf6, 0x1d, 0x74, 0x1e, 0x0c, 0x24, 0x23, 0x2d, 0x22, 0x6f, 0x13, 0x9a, 0x68, 0x35, 0xfc, 0x64, 0x4f, 0x3f}, Path: "solc-macosx-amd64-v0.8.24+commit.e11b9ed9"}, + } +} diff --git a/params_gen.go b/params_gen.go index a80104c..e92398a 100644 --- a/params_gen.go +++ b/params_gen.go @@ -8,7 +8,10 @@ import ( "fmt" "net/http" "os" + "slices" "text/template" + + "github.com/lmittmann/go-solc/internal/version" ) var ( @@ -23,11 +26,19 @@ func main() { BaseURL: solcBaseURL + "linux-amd64/", Fn: "params_linux_amd64.go", BuildTarget: "linux && amd64", + MinVersion: "0.5.0", }, { BaseURL: solcBaseURL + "macosx-amd64/", Fn: "params_darwin_amd64.go", BuildTarget: "darwin && amd64", + MinVersion: "0.5.0", + }, + { + BaseURL: solcBaseURL + "macosx-amd64/", + Fn: "params_darwin_arm64.go", + BuildTarget: "darwin && arm64", + MinVersion: "0.8.24", }, } @@ -68,16 +79,12 @@ func gen(target *target) error { defer f.Close() // execute template - filteredBuilds := make([]*build, 0) - for _, build := range list.Builds { - if major, minor, _, err := parseVersion(build.Version); err != nil { - return err - } else if major == 0 && minor <= 4 { - continue - } - filteredBuilds = append(filteredBuilds, build) + model := &model{ + Target: target, + Builds: slices.DeleteFunc(list.Builds, func(build *build) bool { + return version.Compare(build.Version, target.MinVersion) < 0 + }), } - model := &model{target, filteredBuilds} if err := tmpl.Execute(f, model); err != nil { return err } @@ -93,6 +100,7 @@ type target struct { BaseURL string Fn string BuildTarget string + MinVersion string } type build struct {