Skip to content

Tweak build scripts to enable cross-compiling#3383

Merged
mislav merged 1 commit intotrunkfrom
build-env
Apr 12, 2021
Merged

Tweak build scripts to enable cross-compiling#3383
mislav merged 1 commit intotrunkfrom
build-env

Conversation

@mislav
Copy link
Contributor

@mislav mislav commented Apr 9, 2021

The main build script for this project is script/build.go which implements Makefile-like building of the gh binary and associated man pages. Our Makefile defers to the Go script. #2748

However, when setting GOOS, GOARCH, and other environment variables to modify the target for the resulting binary, these environment variables would affect the execution of build.go as well, which was unintended.

This tweaks our Makefile to reset variables like GOOS and GOARCH when building the build.go script itself, ensuring that the built script runs on the same platform, and adds the ability to pass environment variables as arguments to go run script/build.go. This allows the following usage on platforms without make:

go run script/build.go GOOS=linux

With this style of invocation, the GOOS setting does not actually affect go run itself; just the go build that is executed in a child process.

Ref. #3237

The main build script for this project is `script/build.go` which
implements Makefile-like building of the `gh` binary and associated man
pages. Our Makefile defers to the Go script.

However, when setting GOOS, GOARCH, and other environment variables to
modify the target for the resulting binary, these environment variables
would affect the execution of `build.go` as well, which was unintended.

This tweaks our Makefile to reset variables like GOOS and GOARCH when
building the `build.go` script itself, ensuring that the built script
runs on the same platform, and adds the ability to pass environment
variables as arguments to `go run script/build.go`. This allows the
following usage on platforms without `make`:

    go run script/build.go GOOS=linux

With this style of invocation, the GOOS setting does not actually affect
`go run` itself; just the `go build` that is executed in a child process.
@mislav mislav merged commit a9bebff into trunk Apr 12, 2021
@mislav mislav deleted the build-env branch April 12, 2021 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants