Add go.mod
Code using Go modules currently cannot import any Sia packages. If you try, you'll get this error:
# gitlab.com/NebulousLabs/Sia/persist
../go/pkg/mod/gitlab.com/!nebulous!labs/!sia@v1.4.0/persist/boltdb.go:6:2: imported and not used: "github.com/coreos/bbolt"
../go/pkg/mod/gitlab.com/!nebulous!labs/!sia@v1.4.0/persist/boltdb.go:13:2: undefined: bolt
For whatever reason, Go modules do not seem to play nice with implicit import renames. That is, we're importing bbolt
, but the actual package name is bolt
, and we don't explicitly rename the import to bolt
.
0a541b26 fixes this by renaming all imports of bbolt
. However, now we get a new error:
# gitlab.com/NebulousLabs/Sia/modules/consensus
modules/consensus/accept.go:291:22: undefined: bbolt.MmapError
Here, the problem is that Go thinks we want the actual bbolt
package, when we actually want our vendored version that adds MmapError
. Go modules do not play well with vendoring; the only way to get go build
to use our vendored version is to create a go.mod
file for Sia with a replace
directive:
replace github.com/coreos/bbolt => ./vendor/github.com/coreos/bbolt
Go modules will be enabled by default starting in August (with the release of Go 1.13), so we should make sure we're ready for that. Ideally, we would add a go.mod
file right before tagging a new release. This is because, when other modules import Sia, they will automatically select the most recent version (note that the command above select sia@v1.4.0
). So we want the automatically-selected version to be compatible with modules.