Confluent-kafka-go: With go 1.9.4, static build of applications fails with "invalid pkg-config package name: --static"

Created on 17 Feb 2018  路  8Comments  路  Source: confluentinc/confluent-kafka-go

Description

For security reasons, Go 1.9.4 compiler uses whitelist to filter out most of the flags that can be used in //cgo <...> directive, see here:
https://github.com/golang/go/issues/23672

(See also https://github.com/golang/go/issues/23749 for lots of other people complains and some workarounds)

How to reproduce

Use Go 1.9.4. compiler;
Get libdrkafka, build it;
Get confluent-kafka-go package;
cd to .../src/github.com/confluentinc/confluent-kafka-go/kafkatest/go_verifiable_consumer ;
run "go build -tags static";
see the error message: "go build github.com/confluentinc/confluent-kafka-go/kafka: invalid pkg-config package name: --static"

Checklist

Please provide the following information:

  • [ ] confluent-kafka-go and librdkafka version (LibraryVersion()):
  • [ ] Apache Kafka broker version:
  • [ ] Client configuration: ConfigMap{...}
  • [ ] Operating system:
  • [ ] Provide client logs (with "debug": ".." as necessary)
  • [ ] Provide broker log excerpts
  • [ ] Critical issue

Most helpful comment

Since pkg-config --static is problematic (with and without Go) I'm looking into providing separate .pc files for dynamic and static linking of librdkafka, that should solve this issue as well.

All 8 comments

We'll have to wait for Golang to be updated to allow the -static flag (mentioned on the referenced issues).
There isn't much we can do short of hard-coding the linker flags from the pkg-config command.

I just hit this issue rebuilding a docker image (alpine 3.7). I'm having some trouble getting any workarounds to work. Does anybody have any kind of hack to get around this until it's fixed? What would be the best way to hard code the linker flags? Just getting into go recently, so I may be missing something obvious.

-tags static appears to work fine with go 1.10, if upgrading go version is an option

Since pkg-config --static is problematic (with and without Go) I'm looking into providing separate .pc files for dynamic and static linking of librdkafka, that should solve this issue as well.

I see this issue being closed, does that mean I can now statically build a go application that uses confluent-kafka-go inside a small alpine image? How would I go about doing that? and does anyone have a dockerfile that uses multi-staging? eg you first make install librdkafka, go get confluent-kafka then transfer the executable to a new clean alpine image? seems like a standard use-case

I haven't tried building on Alpine, please report your findings.

I switched to a pure Go implementation, which resulted in about a 6.5 MB container. When I have the rest of the system up (Probably in a week or so), I will measure the performance of that small container, against a normal librdkafka-client container. And then decide if I need to switch back and solve this compile issue I had when trying to get everything down to one single binary file.

I'll be sure to report my findings unless someone beats me too it.

Maybe we should have an alpine-docker build in .travis.yml to verify that it works if this is a common use-case (PRs welcome!)

Was this page helpful?
0 / 5 - 0 ratings