Skip to content

Commit 02b5118

Browse files
Ibrahim Jarifdanielmai
andauthored
build(jemalloc): Install Jemalloc if missing via Makefile. (#6463)
This PR adds a jemalloc target to makefile to install jemalloc. The make install command will install jemalloc if it's not already installed. The make jemalloc target currently fails on docker with command sudo not found. I don't have a solution for it. The change doesn't work on macOS or Windows. Dgraph builds with jemalloc by default on Linux only. Co-authored-by: Daniel Mai <daniel@dgraph.io>
1 parent f7c88ee commit 02b5118

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

dgraph/Makefile

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ else
2929
BUILD_VERSION ?= $(shell git describe --always --tags)
3030
endif
3131

32-
BUILD_TAGS ?=
32+
GOOS ?= $(shell go env GOOS)
33+
# Only build with jemalloc on Linux
34+
ifeq ($(GOOS),linux)
35+
BUILD_TAGS ?= jemalloc
36+
endif
3337
GOPATH ?= $(shell go env GOPATH)
3438
MODIFIED = $(shell git diff-index --quiet HEAD || echo "-mod")
3539

@@ -62,10 +66,14 @@ ifneq ($(strip $(BUILD_RACE)),)
6266
BUILD_FLAGS += -race
6367
endif
6468

69+
# jemalloc stuff
70+
HAS_JEMALLOC = $(shell test -f /usr/local/lib/libjemalloc.a && echo "jemalloc")
71+
JEMALLOC_URL = "https://github.com/jemalloc/jemalloc/releases/download/5.2.1/jemalloc-5.2.1.tar.bz2"
72+
6573
.PHONY: all $(BIN)
6674
all: $(BIN)
6775

68-
$(BIN): clean
76+
$(BIN): clean jemalloc
6977
@go build $(BUILD_FLAGS) -o $(BIN)
7078

7179
clean:
@@ -74,8 +82,22 @@ clean:
7482
uninstall:
7583
@go clean -i -x
7684

77-
install:
85+
install: jemalloc
7886
@echo "Commit SHA256: `git rev-parse HEAD`"
7987
@echo "Old SHA256:" `sha256sum $(GOPATH)/bin/$(BIN) 2>/dev/null | cut -c-64`
8088
@go install $(BUILD_FLAGS)
8189
@echo "New SHA256:" `sha256sum $(GOPATH)/bin/$(BIN) 2>/dev/null | cut -c-64`
90+
91+
jemalloc:
92+
@if [ -z "$(HAS_JEMALLOC)" ] ; then \
93+
mkdir -p /tmp/jemalloc-temp && cd /tmp/jemalloc-temp ; \
94+
echo "Downloading jemalloc" ; \
95+
curl -s -L ${JEMALLOC_URL} -o jemalloc.tar.bz2 ; \
96+
tar xjf ./jemalloc.tar.bz2 ; \
97+
cd jemalloc-5.2.1 ; \
98+
./configure --with-jemalloc-prefix='je_' ; \
99+
make ; \
100+
echo "==== Need sudo access to install jemalloc" ; \
101+
sudo make install ; \
102+
fi
103+

0 commit comments

Comments
 (0)