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

cmd/go: Build constraints disallow subsequent Go releases #48397

Closed
klingtnet opened this issue Sep 15, 2021 · 4 comments
Closed

cmd/go: Build constraints disallow subsequent Go releases #48397

klingtnet opened this issue Sep 15, 2021 · 4 comments

Comments

@klingtnet
Copy link

klingtnet commented Sep 15, 2021

What version of Go are you using (go version)?

$ go version
go version go1.17.1 linux/amd64

Does this issue reproduce with the latest release?

Yes, even with the latest gotip version.

$ gotip version
go version devel go1.18-4847c47 Wed Sep 15 03:29:46 2021 +0000 linux/amd64
$ gotip get .
example imports
        github.com/golang-migrate/migrate/v4/source/iofs: cannot find module providing package github.com/golang-migrate/migrate/v4/source/iofs

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/anli/.cache/go-build"
GOENV="/home/anli/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/anli/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/anli/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/tmp.oODGF8c7us/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1486045652=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I wanted to use embedded SQL migration files in a Go 1.17 project and this required to use the github.com/golang-migrate/migrate/v4/source/iofs migration source driver. The source/iofs driver was added to golang-migrate/migrate shortly after Go 1.16 with embed.FS was released. In order to be compatible with Go versions prior 1.16 a build tag was added such that source/iofs can only be used with Go 1.16 and newer. The documentation about build constraints states:

  • a term for each Go major release, through the current version:
    "go1.1" from Go version 1.1 onward, "go1.12" from Go 1.12, and so on.

If this holds then the package must be importable in Go 1.17 projects as well, but it isn't. A minimal example that demonstrates this issue can be found in this playground. Here is the example's source code:

package main

import (
	"database/sql"
	"embed"

	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/database/postgres"
	"github.com/golang-migrate/migrate/v4/source/iofs"
	_ "github.com/lib/pq"
)

//go:embed *
var migrationFS embed.FS

func main() {
	db, _ := sql.Open("postgres", "postgres://localhost:5432/database?sslmode=enable")
	driver, _ := postgres.WithInstance(db, &postgres.Config{})
	src, _ := iofs.New(migrationFS, ".")
	m, _ := migrate.NewWithInstance("iofs", src, "postgres", driver)
}

Interestingly, the package can be imported when go1.17 was added to the build tags as well. I did this in golang-migrate/migrate#618 .

What did you expect to see?

That github.com/golang-migrate/migrate/v4/source/iofs can be imported in a Go 1.17 project since the build tag //go:build go1.16 allows all Go version starting from 1.16.

What did you see instead?

That go get refuses to add the import:

$ go get .
cmd/inject/inject.go:30:2: no required module provides package github.com/golang-migrate/migrate/v4/source/iofs; to add it:
        go get github.com/golang-migrate/migrate/v4/source/iofs
@seankhliao
Copy link
Member

go is correctly reporting that the latest released version (4.14.1) doesn't have iofs

@jayconrod
Copy link
Contributor

I don't think this is related to build constraints.

It looks like this package was deleted between v4.14.0 and v4.14.1 (the current latest version), then the deletion was reverted some time later (but not in a release version). One of these commands should work:

go get github.com/golang-migrate/migrate/v4@v4.14.0
go get github.com/golang-migrate/migrate/v4@v4.15.0-beta.3

@dhui
Copy link

dhui commented Sep 15, 2021

Oh yikes, good catch on iofs being removed in v4.14.1! We should release v4.15.0 soon...

@Fontinalis
Copy link

A follow up for @klingtnet - we just released v4.15.0 for migrate!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants