On Tue, May 16, 2017 at 7:39 AM,  <flor...@smartmakers.de> wrote:
>
> recently, I replaced a script which we used for code generation by a small
> go program with the same functionality. The reason for this change was that
> windows failed running the script because it can't interprete the script's
> shebang and tried to treat it like a compiled executable. The change solved
> that problem nicely. However, this seems to have broken cross compilation.
> When setting GOOS=linux on a windows computer, that argument seems to get
> passed to go generate and from there to go run. go run the compiles the
> program for linux (on the windows computer) and tries to run it, which fails
> for obvious reasons.
>
> This doesn't sound like an extremely unusual situation, so I was puzzled
> that I couldn't find any information online on how to best handle this
> specific situation. If you have any hints, I'd be glad to take them.
> Resetting the environment in a script is no solution, as the point of the
> whole change is not to use a script. go generate doesn't provide any way to
> set environment variables.

The general expectation is that you will write //go:generate comments
that generate the same output regardless of GOOS.  Then you will run
`go generate` once, or whenever the input files change, but in general
not on every build.  So you would run `go generate` without setting
GOOS and then run `GOOS=linux go build` to build your actual code.

Ian

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to