I’m working on go1.24.2 compile tool. I add gonum package in cmd/compile and I use go get gonum… to get the package.
All things work well if i use go install cmd/compile.
But if i use make.bash in src directory, the following error occurs:
Building Go cmd/dist using /home/lqw/golangs/go1.24.1. (go1.24.1 linux/amd64)
Building Go toolchain1 using /home/lqw/golangs/go1.24.1.
../../../../src/cmd/compile/internal/xxx: no required module provides package gonum.org/v1/gonum/graph; to add it:
go get gonum.org/v1/gonum/graph
I use go mod tidy and go mod vendor in cmd directory to make a copy of gonum in cmd/vendor. Then again i use make.bash. But the above error still occurs. What should I do?
The following description is what I see when debugging the above error.
I inspect the vendor package that cmd/compiler/internal uses, only cmd/compiler/internal/ssa/_gen/rulegen.go uses golang.org/x/tools/go/ast/astutil, while other imported packages are all standard libraries. So is compile special when using vendor package?
I think it’s limited to import vendor packages to avoid supply chain attack. Right? Or if using vendor package in compile, then it’s hard to maintain the dependency among different versions since the API and behavior of vendor package might change?
I inspect the process of cmd/dist/dist bootstrap -a, it will create bootstrap project in pkg/bootstrap/src directory.
To reproduce the process before removing the bootstrap project:
run ./make.bash --dist-tool in src directory to build cmd/dist and generate pkg/dist/dist.
run or debug pkg/dist/dist.
The boostrap project just copies code from src directory. For go1.24.2, it copies cmd/asm, cmd/cgo, cmd/compile, cmd/internal, cmd/link.
I find that the go.mod of bootstrap project does not add any package in src/go.mod and src/cmd/go.mod. It is:
module bootstrap
go 1.22
So if cmd/asm, cmd/cgo, cmd/compile, cmd/internal, cmd/link import vendor packages, and these vendor packages does not reside in GOROOT_BOOSTRAP/bin/go’s src/vendor and src/cmd/vendor directory, the above error occurs naturally.
Possible solution
Solution: Is it possible to run go mod tidy after creating go.mod?
The code for creating go.mod in bootstrap project:
I think it’s natural as most projects do. Besides, a NOTICE can be attached in README.vendor for using vendor packages in cmd directory(Or to be more specific, cmd/asm, cmd/cgo, …, i.e. the packages used when bootstrapping). The notice is “please use vendor packages that are compatible to the minBootstrapVers go”.
But there are also cases that the vendor packages for different boostrap version have some breaking changes. So bootstrap may fail if the behavior of vendor package of bootstrap is different from the one used when developing cmd/compile.
If adding go mod tidy is feasible, I’m happy to create a PR and add notices in README.vendor. If not, please kindly tell me the reason, which is invaluable experience I could learn. Thanks!
When trying to execute go mod tidy after creating go.mod, the following error shows that GOPROXY is off:
go: finding module for package gonum.org/v1/gonum/graph
go: finding module for package golang.org/x/telemetry/counter
go: finding module for package golang.org/x/telemetry
go: bootstrap/cmd/compile/internal/escape imports
gonum.org/v1/gonum/graph: cannot find module providing package gonum.org/v1/gonum/graph: module lookup disabled by GOPROXY=off
go: bootstrap/cmd/internal/telemetry imports
golang.org/x/telemetry: cannot find module providing package golang.org/x/telemetry: module lookup disabled by GOPROXY=off
go: bootstrap/cmd/internal/telemetry/counter imports
golang.org/x/telemetry/counter: cannot find module providing package golang.org/x/telemetry/counter: module lookup disabled by GOPROXY=off
go tool dist: FAILED: /home/l50047708/softwares/go1.24.3/bin/go mod tidy: exit status 1