gokrazy / tools

this repository contains the gok CLI tool of gokrazy
https://gokrazy.org
BSD 3-Clause "New" or "Revised" License
50 stars 28 forks source link

Add an alternative way to specify build enviroment variables #31

Closed oliverpool closed 2 years ago

oliverpool commented 2 years ago

Currently build variables like GOARM, GOOS and GOARCH are simply forwarded from the current environment with some default values: https://github.com/gokrazy/tools/blob/7f0229b37ad1164487e56cb6e73a4d387db96183/cmd/gokr-packer/gotool.go#L15-L28

However this does not play well with go run:

GOARCH=arm go run github.com/gokrazy/tools/cmd/gokr-packer
    github.com/gokrazy/hello

Since GOARCH will be used by go run, the resulting gokr-packer executable will not run on and amd64 machine for instance.


I would like to be able to use go run github.com/gokrazy/tools/cmd/gokr-packer, so that the gokr-packer version can be managed by go.mod using a tools.go file:

//go:build tools

package tools

import (
    _ "github.com/gokrazy/tools/cmd/gokr-packer"
)

Here are the possible solutions to this problem, that I thought of:

What do you think would be the most elegant way to fix this issue ? I can then try to craft a PR.

stapelberg commented 2 years ago

Instead of using go run, why not just go install && gokr-packer?

If you absolutely want to use go run, can you use its -exec flag to specify a wrapper that applies environment variables?

I’d like to avoid adding a custom way to pass environment variables.

oliverpool commented 2 years ago

Instead of using go run, why not just go install && gokr-packer?

Because I wasn't able to find gokr-packerafterwards :see_no_evil: it is actually simply in $(go env GOPATH)/bin/gokr-packer... (and it seems faster than go run)