Building go/src packages from golang/go Github Repository

234 Views Asked by At

Asking to see what the appropriate workaround is for building individual go packages from the go/std library when working on a github repo fork. The issue encountered is summarized by the following error when building for example the src/go/parser package.

parser.go 21:2 use of internal package go/internal/typeparams is not allowed

Of course the project import paths all reference GOROOT library paths

usr/local/go

And I am typically working on projects from my own directory where my go path is set.

/Users/andewx/github/go/src/github.com/andewx/my_go_extension_project

The crux of the issue is that the clone/fork project uses standard library import paths and I would like to be able to work on my repo from my own GOPATH. But internal packages can't be imported in this case because the import directives will always point to my GOROOT.

The only two options I can think of is:

  1. Extending my personal go project by initiating the repo inside of my /usr/local/go and working on the packages from there.

  2. Changing my GOROOT to point to my current project and including current go binary go fmt and toolchains in my project

  3. Ideally I can just leave everything as far as directory structure is concerned as is and I can redirect the standard import path for go standard library to my current project for this project only...

Any ideas from the community for solution #3 is what I'm looking for.

  1. Extending my personal go project by initiating the repo inside of my /usr/local/go and working on the packages from there.

  2. Changing my GOROOT to point to my current project and including current go binary go fmt and toolchains in my project

1

There are 1 best solutions below

1
On

If you are trying to work on the go compiler and extend it I actually found that changing your GOROOT to point to your workspace and then copying over the binaries and tools you need as a suitable fix and it doesn't create any additional issues.

  • Export your environment variable export GOROOT="/my/go/project"

  • Find out where your go tools are located with go env GOTOOLDIR copy this directory structure into your project folder.

  • Copy go bin cp /usr/local/bin/* ${GOROOT}"/bin" copy in your go binary

  • Copy toolscp /usr/local/go/pkg/tool/linux_amd64/* ${GOROOT}/pkg/tool/linux_amd64

Now your project should be able to run the copied binaries with your project directories temporarily set as the GOROOT.