Golang在M1芯片上使用动态链接进行Kafka测试

huangapple go评论76阅读模式
英文:

Golang testing with dynamic linking for Kafka on M1 chip

问题

我正在尝试为我在新的M1 Mac上使用Golang / Kafka进行的一个 poc 编写一些单元测试。我正在使用来自confluent的官方Golang Kafka库:

"github.com/confluentinc/confluent-kafka-go/kafka"

显然,这个包依赖于一个尚未为M1构建的 librdkafka。对于构建,有一个解决方法在这里,大致如下:

% brew install librdkafka openssl zstd
% PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"
% go build -tags dynamic *yadda yadda yadda*

这对于构建/运行是可以的。不幸的是,对于测试似乎不起作用。在描述解决方法的链接中,使用 go test -tags dynamic ./... 似乎可以工作,但在我的情况下,测试运行似乎没有读取导出的 PKG_CONFIG_PATH:

% go test -tags dynamic ./... -v
# pkg-config --cflags  -- rdkafka
Package libcrypto was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcrypto.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libcrypto', required by 'rdkafka', not found
pkg-config: exit status 1
FAIL	smartAC/shared [build failed]

尽管该环境变量在我的 shell 中已设置:

% echo $PKG_CONFIG_PATH
/opt/homebrew/opt/openssl@3/lib/pkgconfig

有没有什么技巧可以让 go test 工具看到这个环境变量?

英文:

I'm trying to write some unit tests for a poc I'm doing in Golang / Kafka on a new M1 Mac. I'm using the official Golang Kafka libs from confluent:

"github.com/confluentinc/confluent-kafka-go/kafka"

Apparently, this package has a dependency on a librdkafka which is not built for M1 (yet?). For the build, there is a work around here, which goes something like this:

% brew install librdkafka openssl zstd
% PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"
% go build -tags dynamic *yadda yadda yadda*

This is fine for build/run. Unfortunately, it doesn't seem to work for tests. In the link describing the workaround, using go test -tags dynamic ./... seems to work, but in my case the test run doesn't seem to read the exported PKG_CONFIG_PATH:

% go test -tags dynamic ./... -v
# pkg-config --cflags  -- rdkafka
Package libcrypto was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcrypto.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libcrypto', required by 'rdkafka', not found
pkg-config: exit status 1
FAIL	smartAC/shared [build failed]

Even though that env var is set, at least in my shell:

% echo $PKG_CONFIG_PATH
/opt/homebrew/opt/openssl@3/lib/pkgconfig

Is there some trick to get go test tool to see the env var?

答案1

得分: 4

好的,以下是翻译好的内容:

好的,没关系。我解决了这个问题...在我的~/.zshrc文件中,我没有导出PKG_CONFIG_PATH,所以我将它改成了:

PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"

改成了:

export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"

这样似乎可以工作了。我保留这个问题,以防对其他像我这样的新手有所帮助 :-).

英文:

Ok, never mind. I sorted this... in my ~/.zshrc I wasn't exporting the PKG_CONFIG_PATH, so I changed this:

PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"

to this:

export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"

Which seems to work. Leaving the question up, just in case it might help some other noob like me :-).

huangapple
  • 本文由 发表于 2022年5月10日 22:05:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/72187850.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定