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

go: Add Go modules support #486

Merged
merged 3 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ and this project adheres to [Semantic Versioning].

## [7.3.0] — unreleased

### Added

- Support for **Go modules**.
[#486](https://github.com/ethereum/evmc/pull/486)

### Changed

- The minimum **Go version** supported bumped to **1.11** (Go modules are required).
[#486](https://github.com/ethereum/evmc/pull/486)
- Removed dependency on go-ethereum in Go bindings by introducing own `Address` and `Hash` types.
[#513](https://github.com/ethereum/evmc/pull/513)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please visit the [documentation].
| ----------------------------- | --------------------- | ------------------------------ | -------------------
| **C** | C99, C11 | GCC 6+, clang 3.8+, MSVC 2015+ | Host- and VM-side
| **C++** | C++11, C++14, C++17 | GCC 6+, clang 3.8+, MSVC 2015+ | Host- and VM-side
| **Go** _(bindings)_ | 1.9 - 1.12 | | Host-side only
| **Go** _(bindings)_ | 1.11 - 1.14 (modules) | | Host-side only
| **Rust** _(bindings)_[¹](#n1) | 2018 edition | 1.37.0 and newer | VM-side only
| **Java** _(bindings)_ | 11 | | Host-side only

Expand Down
5 changes: 0 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ build_script:
gcc --version
go env

copy include/evmc/evmc.h bindings/go/evmc
copy include/evmc/helpers.h bindings/go/evmc
copy include/evmc/loader.h bindings/go/evmc
copy lib/loader/loader.c bindings/go/evmc

go build ./bindings/go/evmc
go generate ./bindings/go/evmc
go test -v ./bindings/go/evmc
Expand Down
2 changes: 1 addition & 1 deletion bindings/go/evmc/evmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package evmc

/*
#cgo CFLAGS: -I${SRCDIR}/.. -Wall -Wextra
#cgo CFLAGS: -I${SRCDIR}/../../../include -Wall -Wextra
#cgo !windows LDFLAGS: -ldl

#include <evmc/evmc.h>
Expand Down
1 change: 0 additions & 1 deletion bindings/go/evmc/evmc.h

This file was deleted.

1 change: 0 additions & 1 deletion bindings/go/evmc/helpers.h

This file was deleted.

2 changes: 1 addition & 1 deletion bindings/go/evmc/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package evmc

/*
#cgo CFLAGS: -I${SRCDIR}/.. -Wall -Wextra -Wno-unused-parameter
#cgo CFLAGS: -I${SRCDIR}/../../../include -Wall -Wextra -Wno-unused-parameter

#include <evmc/evmc.h>
#include <evmc/helpers.h>
Expand Down
1 change: 0 additions & 1 deletion bindings/go/evmc/loader.c

This file was deleted.

4 changes: 4 additions & 0 deletions bindings/go/evmc/loader.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Include evmc::loader in the Go package.
* The "go build" builds all additional C/C++ files in the Go package directory,
* but symbolic links are ignored so #include is used instead. */
#include "../../../lib/loader/loader.c"
1 change: 0 additions & 1 deletion bindings/go/evmc/loader.h

This file was deleted.

26 changes: 25 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,41 @@ jobs:
- image: circleci/golang
steps: &bindings-go-steps
- checkout
- run:
name: "Environment"
command: |
go version
go env
gcc --version
- run:
name: "Go Build"
command: |
go build -v ./bindings/go/evmc
go vet -v ./bindings/go/evmc
go generate -v ./bindings/go/evmc
go test -v ./bindings/go/evmc
- run:
name: "Go module integration test"
working_directory: test/gomod
command: |
V=$CIRCLE_TAG
if [ -z $V ]; then
V=$CIRCLE_SHA1
fi
echo "version: $V"

go mod init evmc.ethereum.org/evmc_use
go get -v github.com/ethereum/evmc/v7@$V
go mod tidy -v
go mod graph
gcc -shared -I../../include ../../examples/example_vm/example_vm.c -o example-vm.so
go test -v
go mod graph


bindings-go-min:
docker:
- image: circleci/golang:1.9
- image: circleci/golang:1.11
steps: *bindings-go-steps

bindings-java:
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/ethereum/evmc/v7
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is enough to only declare it as "v7" here but use dir structure unchanged?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it seems so

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a need for v7 here? If we bump to ABI 8 and this is changed to v8, will go modules still be able to download v7 things?

Or the only benefit is knowing it is v7 even if someone uses a commithash after it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required by go mod. The vX is required if you version is vX.Y.Z. Can be only omitted if X==1 || X==0.

Versions are marked with git tags, and v7 series will continue to work (because e.g. at v7.3.0 this line will be still module github.com/ethereum/evmc/v7.

The usage is something like this:

go get github.com/ethereum/evmc/v7@v7.3.0
go get github.com/ethereum/evmc/v7@v7.3.1
go get github.com/ethereum/evmc/v8@v8.0.0

And also

import "github.com/ethereum/evmc/v7"
import "github.com/ethereum/evmc/v8"

So users need to update their import directives when upgrading major version number. In case of EVMC where vX matches ABI version this is reasonable IMHO.

Copy link
Member

@axic axic May 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is just a convention required by go mod, it won't magically make v7 work when we move on to v8, because it still just downloads from the repo master, unless a commit hash is specified, correct? Or are the versions used as git tags?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. go get github.com/ethereum/evmc/v7@v8.0.0 will fail due to mismatch.
  2. go get github.com/ethereum/evmc/v7@master will also fail if the most recent version is v8.Y.Z. go mod uses a kind of git describe strategy to figure out the "current" version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in a future PR, one could update bumpversion to also update this line.


go 1.11
3 changes: 3 additions & 0 deletions test/gomod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/go.mod
/go.sum
/example-vm.so
9 changes: 9 additions & 0 deletions test/gomod/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Integration test for EVMC Go module

Usage:

go mod init evmc.ethereum.org/evmc_use
go get github.com/ethereum/evmc/v7@<commit-hash-to-be-tested>
go mod tidy
gcc -shared -I../../include ../../examples/example_vm/example_vm.c -o example-vm.so
go test
20 changes: 20 additions & 0 deletions test/gomod/use_evmc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package evmc_use

import (
"github.com/ethereum/evmc/v7/bindings/go/evmc"
"testing"
)

var exampleVmPath = "./example-vm.so"

func TestGetVmName(t *testing.T) {
vm, err := evmc.Load(exampleVmPath)
if err != nil {
t.Fatalf("%v", err)
}

expectedName := "example_vm"
if name := vm.Name(); name != expectedName {
t.Errorf("wrong VM name: %s, expected %s", name, expectedName)
}
}