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: go build support for importing/linking additional packages #14088

Open
CAFxX opened this Issue Jan 25, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@CAFxX
Contributor

CAFxX commented Jan 25, 2016

I would love to be able to specify during go build/run additional packages to be imported. This would be mostly useful for those packages that are imported for their side effects.

As an example consider:

$ go build example.com/myapp -import github.com/go-sql-driver/mysql

This should have the same effect as adding the following import in the root package of myapp:

import _ "github.com/go-sql-driver/mysql"

Right now I'm using a quick-and-dirty tool for this but I really can't help thinking this should be part of the go command.

This would basically enable a very rudimental form of (compiler-mediated) DI.

@CAFxX CAFxX changed the title from go build support for importing additional packages to go build support for importing/linking additional packages Jan 25, 2016

@minux

This comment has been minimized.

Member

minux commented Jan 25, 2016

@CAFxX

This comment has been minimized.

Contributor

CAFxX commented Jan 25, 2016

This assumes that the myapp author has either included all possible database/sql drivers, or that it provides a file for each database/sql driver with its own tag. Even just with SQL drivers (https://github.com/golang/go/wiki/SQLDrivers lists more than 20) this becomes hard quickly: imagine what could happen with application modules or plugins. Moreover, if the myapp maintainer doesn't want to import a specific package, you need to patch manually every time you build/run.

Sure, the current state is not unbearable... it just feels like an unneeded hop to jump through.

@minux

This comment has been minimized.

Member

minux commented Jan 25, 2016

@CAFxX

This comment has been minimized.

Contributor

CAFxX commented Jan 25, 2016

The fact that the use of something should be minimized doesn't imply that that something is not useful if used properly. I'm not advocating abuse of the feature I'm proposing; I'm advocating that it would be useful in certain limited scenarios - similarly to build tags, the -X flag to go tool link and cgo (all things that make reproducing an exact build basically impossible).

@ianlancetaylor ianlancetaylor changed the title from go build support for importing/linking additional packages to cmd/go: go build support for importing/linking additional packages Jan 25, 2016

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Jan 25, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment