func icon indicating copy to clipboard operation
func copied to clipboard

Cannot set ldflags in buildpack

Open andrinbr opened this issue 10 months ago • 3 comments

When using the default buildpack image (ghcr.io/knative/builder-jammy-tiny) the BP_GO_BUILD_LDFLAGS environment variable has no effect.

It is picked up by the buildpack:

Provided Environment Variables
  BP_GO_BUILD_LDFLAGS=-X function/build.ProgramVersion=blafromflags

But not used for building:

  Executing: go build -o /workspace/bin/faas /workspace/faas
Processing layers

I would expect it to work like it is documented here: https://paketo.io/docs/howto/go/#set--ldflags-for-go-build

When using upstream variant (docker.io/paketobuildpacks/builder-jammy-base) the flags are correctly set:

Paketo Buildpack for Go Build 2.2.25
  Executing build process
    Running 'go build -o /layers/paketo-buildpacks_go-build/targets/bin "-ldflags=-X function/build.ProgramVersion=blafromflags" -buildmode pie -trimpath .'
      go: no main packages to build

It was set like this in the func.yaml

build:
  buildEnvs:
  - name: BP_GO_BUILD_LDFLAGS
    value: "-X function/build.ProgramVersion=blafromflags"

andrinbr avatar Feb 25 '25 15:02 andrinbr

Is this for local or on-cluster build?

matejvasek avatar Mar 04 '25 13:03 matejvasek

This is with a local build with Podman v5.2.2 on RHEL 9.5

andrinbr avatar Mar 04 '25 14:03 andrinbr

Hey @matejvasek, are you still working on this? If not, I’d like to take it up.

KapilSareen avatar Mar 15 '25 03:03 KapilSareen

This issue is stale because it has been open for 90 days with no activity. It will automatically close after 30 more days of inactivity. Reopen the issue with /reopen. Mark the issue as fresh by adding the comment /remove-lifecycle stale.

github-actions[bot] avatar Jun 14 '25 01:06 github-actions[bot]

Can we re-open this?

andrinbr avatar Jul 14 '25 07:07 andrinbr