Hi Paul!

Thank you for taking the time to reply.

On Friday, September 18, 2020 at 11:33:49 AM UTC+2 Paul Jolly wrote:

> Hi Andi, 
>
> > 1) I cannot do go install tools.go: 
>
> go install takes main packages as arguments, so no, this will not 
> work. The tools.go file (like the example you present) is simply a way 
> of declaring a dependency on a main package through a file that will 
> never be built (hence the +build tools constraint). Even though this 
> file is, in normal operation, ignored by all build commands (go build, 
> go install etc) it _is_ seen by go mod tidy (which ignores build 
> constraints). Hence the requirement is considered when collating the 
> main module's requirements. 
>
> > instead I need to duplicate each tool installation in the Makefile 
>
> If you want to install these commands then yes, this needs to happen 
> somewhere (could even be a go:generate step) 
>
> However, you can simply go run $mainpkg and this will work (see below) 
>
 
Understood. Unfortunately, that clashes with the simplistic approach to 
cross-building below.

> 2) The internal tools are currently not installed in invoked during 
> build: 
>
> Per my suggestion above, this is my preferred mechanism. It avoids any 
> unnecessary steps of ensuring the correct GOBIN, PATH etc. 
>
> > //go:generate go run ../cmd/tools/decorate.go ... 
> > 
> > This fails during cross-build: 
> > GOOS=linux GOARCH=arm make 
> > go install github.com/mjibson/esc 
> > go install github.com/golang/mock/mockgen 
> > Generating embedded assets 
> > go generate ./... 
> > ... 
> > fork/exec 
> /var/folders/pm/q2g_c0vn1hb414nqwdcsv4fm0000gn/T/go-build741389459/b001/exe/decorate:
>  
> exec format error 
> > charger/evsewifi.go:57: running "go": exit status 1 
> > fork/exec 
> /var/folders/pm/q2g_c0vn1hb414nqwdcsv4fm0000gn/T/go-build892585922/b001/exe/decorate:
>  
> exec format error 
> > meter/meter.go:16: running "go": exit status 1 
> > 
> > I've looked at https://golang.org/cmd/go/#hdr-Build_constraints but 
> couldn't find a description of best practices or even mention of +built 
> tools. 
>
> I'm not sure how you are getting into this situation, because go run 
> will build a binary for the platform on which cmd/go is running. 


> Unless you have GOOS and GOARCH set, in which case the go run during 
> the go generate phase will be building for potentially a different 
> platform? 
>

Exactly. User tried  GOOS=linux GOARCH=arm make which ended up as above. 
This can obviously be worked around by (in my case) make assets && 
GORACH/GOARM make build but it's not obvious.
 

> Paul 
>

Regards,
Andi 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8dcfc9de-c77d-47a4-af65-314b296f5dddn%40googlegroups.com.

Reply via email to