[Buildroot] [PATCH] package/crucible: Pass 'osusergo netgo' tags

Arnout Vandecappelle arnout at mind.be
Fri Jul 22 22:03:16 UTC 2022



On 22/07/2022 23:15, Thomas Petazzoni wrote:
> Hello,
> 
> On Fri, 22 Jul 2022 23:04:57 +0200
> Arnout Vandecappelle <arnout at mind.be> wrote:
> 
>>    AFAICS, CGO_ENABLED is only set in HOST_GO_MAKE_ENV, which is only used in the
>> host-go build commands. So it's not really possible to set it per package.
>> However, apparently it is possible to override it:
> 
> I see this:
> 
> HOST_GO_COMMON_ENV = \
>          GO111MODULE=on \
>          GOFLAGS=-mod=vendor \
>          GOROOT="$(HOST_GO_ROOT)" \
>          GOPATH="$(HOST_GO_GOPATH)" \
>          GOPROXY=off \
>          PATH=$(BR_PATH) \
>          GOBIN= \
>          CGO_ENABLED=$(HOST_GO_CGO_ENABLED)
> 
> HOST_GO_TARGET_ENV = \
>          $(HOST_GO_COMMON_ENV) \
>          GOOS="linux" \
>          GOARCH=$(GO_GOARCH) \
>          GOCACHE="$(HOST_GO_TARGET_CACHE)" \
>          CC="$(TARGET_CC)" \
>          CXX="$(TARGET_CXX)" \
>          CGO_CFLAGS="$(TARGET_CFLAGS)" \
>          CGO_CXXFLAGS="$(TARGET_CXXFLAGS)" \
>          CGO_LDFLAGS="$(TARGET_LDFLAGS)" \
>          GOTOOLDIR="$(HOST_GO_TOOLDIR)"
> 
> so HOST_GO_TARGET_ENV has CGO_ENABLED=$(HOST_GO_CGO_ENABLED)
> 
> and then HOST_GO_TARGET_ENV gets used in:
> 
> # Build package for target
> define $(2)_BUILD_CMDS
>          $$(foreach d,$$($(2)_BUILD_TARGETS),\
>                  cd $$(@D); \
>                  $$(HOST_GO_TARGET_ENV) \
>                          $$($(2)_GO_ENV) \
>                          $$(GO_BIN) build -v $$($(2)_BUILD_OPTS) \
>                          -o $$(@D)/bin/$$(or $$($(2)_BIN_NAME),$$(notdir $$(d))) \
>                          $$($(2)_GOMOD)/$$(d)
>          )
> endef
> 
> Am I looking wrong?

  No, I'm looking wrong, of course. I didn't see the one in HOST_GO_COMMON_ENV 
because it comes before the definition of HOST_GO_CGO_ENABLED :-(

  So indeed, the question if we should have a per-package option to enable cgo 
is relevant.

  I'd actually expect that the package itself would specify whether it needs cgo 
or not. Can we test a build of a package that actually uses cgo to verify if we 
really need to set it in HOST_GO_COMMON_ENV?


  Regardless, we *will* need to set the 'osusergo netgo' tags for all cgo-using 
packages when they do use cgo - so either we still need a per-package "enable 
cgo" option, or we should just always add those tags if cgo is enabled and we're 
doing static linking.

  Is there any reason why this problem is only observed for the crucible package?

  Regards,
  Arnout



> 
> Thomas



More information about the buildroot mailing list