Skip to content

Commit

Permalink
Added support for Apple Silicon (for solc >= 0.8.24) (#40)
Browse files Browse the repository at this point in the history
* internal/version: init

* added support for darwin-arm64

* updated setup-go

* updated go version

* examples: updated go version

---------

Co-authored-by: lmittmann <[email protected]>
  • Loading branch information
lmittmann and lmittmann authored Mar 3, 2024
1 parent 32452e6 commit fedbcc3
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 30 deletions.
35 changes: 16 additions & 19 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module examples

go 1.21
go 1.22

require (
github.com/lmittmann/go-solc v0.0.0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -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)
}
47 changes: 47 additions & 0 deletions internal/version/version_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
13 changes: 13 additions & 0 deletions params_darwin_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions params_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
"fmt"
"net/http"
"os"
"slices"
"text/template"

"github.com/lmittmann/go-solc/internal/version"
)

var (
Expand All @@ -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",
},
}

Expand Down Expand Up @@ -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
}
Expand All @@ -93,6 +100,7 @@ type target struct {
BaseURL string
Fn string
BuildTarget string
MinVersion string
}

type build struct {
Expand Down

0 comments on commit fedbcc3

Please sign in to comment.