Can't compile Ristretto on Mac M2 Ventura

Hey, I can’t get Ristretto to compile using jemalloc installed using brew

$ brew install jemalloc
....
$ env|egrep 'LD|CGO'
LDFLAGS=-L/opt/homebrew/lib
CGO_CFLAGS=-I/opt/homebrew/include

$ go build -tags jemalloc
# github.com/dgraph-io/ristretto/z
z/calloc_jemalloc.go:73:9: could not determine kind of name for C.je_calloc
z/calloc_jemalloc.go:103:3: could not determine kind of name for C.je_free
z/calloc_jemalloc.go:143:2: could not determine kind of name for C.je_mallctl
z/calloc_jemalloc.go:170:2: could not determine kind of name for C.je_malloc_stats_print

Hey @cscetbon,

I’m able to build like this on my M1, which I should think would be the same. Maybe have a look at how Dgraph installs jemalloc in our Makefile here. Maybe it’s a version mismatch or some other difference.

You’re using an old version of homebrew, it doesn’t store libraries in /usr/local/lib/ anymore

$ brew list jemalloc
/opt/homebrew/Cellar/jemalloc/5.3.0/bin/jemalloc-config
/opt/homebrew/Cellar/jemalloc/5.3.0/bin/jemalloc.sh
/opt/homebrew/Cellar/jemalloc/5.3.0/bin/jeprof
/opt/homebrew/Cellar/jemalloc/5.3.0/include/jemalloc/jemalloc.h
/opt/homebrew/Cellar/jemalloc/5.3.0/lib/libjemalloc.2.dylib
/opt/homebrew/Cellar/jemalloc/5.3.0/lib/pkgconfig/jemalloc.pc
/opt/homebrew/Cellar/jemalloc/5.3.0/lib/ (3 other files)
/opt/homebrew/Cellar/jemalloc/5.3.0/share/doc/jemalloc/jemalloc.html
/opt/homebrew/Cellar/jemalloc/5.3.0/share/man/man3/jemalloc.3

$ ls /opt/homebrew/Cellar/jemalloc/5.3.0/lib/
libjemalloc.2.dylib libjemalloc.a       libjemalloc.dylib   libjemalloc_pic.a   pkgconfig

But still I don’t understand the errors I get

Ristretto has hard-coded paths to jemalloc and expects to find it in /usr/local/lib. See here e.g. Try running make jemalloc from the Makefile @matthewmcneely pointed out above. It will download the jemalloc library at the appropriate version and into /usr/local/lib.

Ouch I thought those were just comments and that I could overwrite it by setting my LDFLAGS which I did as you can see in my first message :confused:
I’m specifically trying to not install it manually as it’s been already installed using brew. Okay then if it’s hardcoded there is not much I can do besides creating symlinks for Ristretto to be happy …

On x64 Macbooks, this location is still used, but for arm64, true they use /opt/homebrew now. You can check the HOMEBREW_PREFIX and HOMEBREW_CELLAR for the correct location regardless of arch.

If those are not set up, you can set them up with: eval $(brew shellenv) (assuming brew is in your path)

The way you have this set up should be optimal, and having embedded build commands that override the build environment is less than ideal. I wish I knew more about the CGO build environment to change this and make it more dynamic, where this could be overridden. This consequently broke building cross platform binaries with the xgo tool. :cry:

On x64 Macbooks, this location is still used, but for arm64, true they use /opt/homebrew now. You can check the HOMEBREW_PREFIX and HOMEBREW_CELLAR for the correct location regardless of arch.

Oh interesting, I’ve moved to arm64 2y ago and thought they made that change across the board.

The way you have this set up should be optimal, and having embedded build commands that override the build environment is less than ideal. I wish I knew more about the CGO build environment to change this and make it more dynamic, where this could be overridden. This consequently broke building cross platform binaries with the xgo tool. :’(

I wish it too ! :grimacing: