heroku / heroku-buildpack-go

Heroku Go Buildpack
https://devcenter.heroku.com/categories/go
MIT License
792 stars 511 forks source link

Further specifying build flags #400

Closed Julio-Guerra closed 1 week ago

Julio-Guerra commented 4 years ago

Hello,

I can't find any way of passing custom build flags to the Go compiler. I tried using the GOFLAGS environment with heroku config:set GOFLAGS="my extra flags" but I doesn't work.

Ideally, I need a solution to pre-install a tool that I pass to the compiler through its flags:

  1. go install my-tool
  2. go build <my options with my-tool> app

Is it possible? I will otherwise have to move to a Dockerfile solution for now. Or maybe should I create a separate buildpack for that :thinking: ?

For some context: I am the tool provider, willing to document the Heroku use-case ;-) Thanks!

Julio-Guerra commented 4 years ago

I am digging into the custom buildpack right now with a compile script doing:

  1. go install the tool
  2. create the $buildpack_dir/export script with the GOFLAGS env var value to use.

So that users should be able to use the default go buildpack + mine (first).

Julio-Guerra commented 4 years ago

I am digging into the custom buildpack right now with a compile script doing:

  1. go install the tool
  2. create the $buildpack_dir/export script with the GOFLAGS env var value to use.

So that users should be able to use the default go buildpack + mine (first).

FYI, this solution works: https://github.com/sqreen/heroku-buildpack-go/tree/master/bin

The only problem I foresee will be users compiling multiple Go binaries while not willing to use the tool on all of them, while GOFLAGS makes the tool generally available.

I thinks it a good enough solution for me now, but adding the ability to customize the Go compiler flags for each Go build, directly in this buildpack would be better.

ghost commented 4 years ago

These are the flags that are currently sourced from the environment: https://github.com/heroku/heroku-buildpack-go/blob/289f452a803b671c74da32caa98c132037c55e2b/lib/common.sh#L208-L221

Adding the following would solve your problem (AFAICT): envFlags+=("GOFLAGS")

Maybe @danp or @heroku/languages are interested in doing so.