Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running mage with GOOS=foo influences the GOOS of the compiled magefile #169

Closed
natefinch opened this issue Sep 19, 2018 · 5 comments · Fixed by #202
Closed

running mage with GOOS=foo influences the GOOS of the compiled magefile #169

natefinch opened this issue Sep 19, 2018 · 5 comments · Fixed by #202

Comments

@natefinch
Copy link
Member

iF you have a target that builds your code and you decide you want to run it with GOOS=windows ... Mage will try to compile the magefile with GOOS=windows, and if you're not on windows, it'll break.

i.e.

GOOS=windows mage build

will compile the magefile itself with GOOS=windows ... and then try to run it and fail if you're not on windows.

We need to isolate mage's own compilation from the standard environment variables, with the possibility of something like MAGEFILE_GOOS for when you want to produce a magefile binary of a specific os/arch.

@fbettag
Copy link

fbettag commented Nov 22, 2018

This is currently the only blocker for me to change most of my projects to magefile. Otherwise this is an absolutely awesome project! thanks!

@natefinch
Copy link
Member Author

Ahh thanks for letting me know. I'll prioritize this, then. Glad you like it! :)

@natefinch
Copy link
Member Author

Oh, note that you can always specify the environment variable for commands that you run explicitly, so like

sh.RunWith(map[string]string{"GOOS":"linux"}, "go", "build")

But it would be nice to isolate mage compilation itself.

@fbettag
Copy link

fbettag commented Nov 23, 2018

Yup i found that already :) but for our build system i need to pass GOOS/GOARCH for all the OSes/Arches we build for (which is almost all legit combos :P)

@natefinch
Copy link
Member Author

natefinch commented Nov 26, 2018

So, I just had to do this for one of my own projects, and my solution was to use a different name for the variables:

// Runs "go build" and generates the version info the binary.
// Use GOOSE to set GOOS and GOARCHE to set GOARCH on the output binary. 
func Build() error {
	env := map[string]string{
		"GOOS": os.Getenv("GOOSE"),
		"GOARCH": os.Getenv("GOARCHE"),
	}
	return sh.RunWith(env, "go", "build")
}

Not that I won't fix this, but this could be a fix in the meantime.

natefinch added a commit that referenced this issue Dec 10, 2018
this fixes #169 - mage now ignores GOOS and GOARCH in the environment
when building its own binaries.  The exception is if you use -goos or -goarch
when running -compile.
natefinch added a commit that referenced this issue Dec 10, 2018
* GOOS and GOARCH fixes

this fixes #169 - mage now ignores GOOS and GOARCH in the environment
when building its own binaries.  The exception is if you use -goos or -goarch
when running -compile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants