Is src directory needed?

194 views
Skip to first unread message

Tharaneedharan Vilwanathan

unread,
Oct 2, 2015, 5:24:57 PM10/2/15
to golang-nuts
Hi All,

Sorry if this is a very basic question.

Let us say I have a package called mypkg in GOPATH and I am trying to build mytool in the corresponding source directory.

If I have mypkg source code in /home/dharani/gopath/src/mypkg, then build of mytool goes through fine:

bash-4.1$ go build -v
mypkg
_/home/dharani/tool/mytool

But if I remove the source code from /home/dharani/gopath, then build of mytool fails although the package is available in binary form in the corresponding package directory:

bash-4.1$ go build -v
mytool.go:9:2: cannot find package "mypkg" in any of:
/home/dharani/go/src/mypkg (from $GOROOT)
/home/dharani/gopath/src/mypkg (from $GOPATH)

bash-4.1$ ls -l gopath/pkg/linux_amd64/mcell*
-rw-r--r-- 1 dharani mygroup 254574 Jul 15 16:24 gopath/pkg/linux_amd64/mcell.a

I notice the same thing with GO base release as well. It looks like src directory should always be present.

Can someone tell me why it is so? Am I missing something?

Appreciate your help.

Thanks
dharani

Ian Lance Taylor

unread,
Oct 2, 2015, 5:39:49 PM10/2/15
to Tharaneedharan Vilwanathan, golang-nuts
I'm not completely certain, but I think you are asking about
https://golang.org/issue/2775 .

Ian

Tharaneedharan Vilwanathan

unread,
Oct 5, 2015, 5:33:38 PM10/5/15
to Ian Lance Taylor, golang-nuts
Hi Ian,

Sorry for the delay.

Yes, the issue is related.

I am surprised to see this is no cause for surprise among Go community. And, btw, this is the reason why pre-compiled Go binary release versions also have src directory?

Thanks
dharani

Dave Cheney

unread,
Oct 5, 2015, 6:52:18 PM10/5/15
to golang-nuts
The source is included for a number of reason.

1. It makes the go tool simpler,specifically the out of date logic
2. It enables cross compliation, which may need to build the runtime and stdlib for the target platform.
3. Tools that do source analysis like goimports and godoc need the stdlib source.

Also, as an open source project, it would be shortsighted to not include the source code of the stdlib compilers and runtime.

Thanks

Dave

Reply all
Reply to author
Forward
0 new messages