Skip to content

x/vgo: share local code inside custom $GOPATH #25053

@gobwas

Description

@gobwas

Hi!

I want to use $GOPATH as a root of git monorepo with several projects sharing some common library:

$ tree
├── Makefile
└── src
       ├── common
       ├── serviceA
       │   └── go.mod
       ├── serviceB 
       │   └── go.mod
       └── v

ServiceA and ServiceB are import some local common/stuff package inside their *.go files. They are also import, say, github.com/some/package with different versions (which are listed in their go.mod files).

How could I use vgo to build serviceA and serviceB separately, with same local code from src/common?

Im trying to compile with script like this:

$ (
  export GOPATH=$(pwd);
  cd src/serviceA;
  vgo build -o ../bin/serviceA;
)

Without any actions I get this error:

vgo: import "serviceA" ->
        import "common/stuff" [/usr/local/go/src/common/stuff]: open /usr/local/go/src/common/stuff: no such file or directory

If I change common to something like common.org:

vgo: import "serviceA" ->
        import "common.org": Get https://common.org?go-get=1: dial tcp: lookup common.org: no such host

Also, If I put something like this into serviceA/go.mod:

replace (
    "common.org" v1.0.0 => "../common"
)

The result is:

vgo: errors parsing go.mod:
<path to src>/src/serviceA/go.mod:6: invalid module version v1.0.0: Get https://common.org?go-get=1: dial tcp: lookup common.org: no such host

Am I doing something wrong, or is this know limitation, or any other suggestion?
Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions