Let's say you have a package mypack
with two source files mypack/a.go
and mypack/b.go
. Both of those source files depend on each another but the Go compiler doesn't complain. If you split that package into two, apack/a.go
and bpack/b.go
, the Go compiler will say import cycle not allowed
.
My understanding of how package dependencies are handled is that the compiler will construct a graph of the imports. The graph is analyzed and somehow (I would love to learn about the algorithm that does this!) the order of compilation calculated. The order cannot be calculated if there is a cycle in the graph so the compiler complains.
What I don't understand is how the Go compiler is able to resolve dependencies between sources of a package but not able to resolve dependencies between packages. If the two sources depend on each other then you have to do some crazy acrobatics and compile them both at the same time somehow.
Could someone clear this up for me?