Skip to content

Commit afbdbf5

Browse files
committed
fix macos build
Signed-off-by: Ricardo Dias <[email protected]>
1 parent 18b8500 commit afbdbf5

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

src/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ endif
265265
ifeq ($(LUA_MODULE),$(LUA_MODULE_NAME))
266266
current_dir = $(shell pwd)
267267
FINAL_CFLAGS+=-DLUA_ENGINE_ENABLED -DLUA_ENGINE_LIB=libluaengine.so
268+
ifeq ($(uname_S),Darwin)
269+
FINAL_LDFLAGS+= -Wl,-rpath,$(PREFIX)/lib:$(current_dir)/modules/lua
270+
else
268271
FINAL_LDFLAGS+= -Wl,-rpath,$(PREFIX)/lib:$(current_dir)/modules/lua -Wl,--disable-new-dtags
272+
endif
269273
LUA_MODULE_INSTALL=install-lua-module
270274
endif
271275

src/eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ int evalExtractShebangFlags(sds body,
240240
}
241241

242242
if (out_engine) {
243-
uint32_t engine_name_len = sdslen(parts[0]) - 2;
243+
size_t engine_name_len = sdslen(parts[0]) - 2;
244244
*out_engine = zcalloc(engine_name_len + 1);
245245
valkey_strlcpy(*out_engine, parts[0] + 2, engine_name_len + 1);
246246
}

src/modules/lua/Makefile

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
1+
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
2+
13
DEPS_DIR=../../../deps
2-
CFLAGS= -I. -I$(DEPS_DIR)/lua/src -I$(DEPS_DIR)/fpconv -fPIC -W -Wall -fno-common $(OPTIMIZATION) -std=c99 -D_GNU_SOURCE
3-
SHOBJ_LDFLAGS= -shared
4+
5+
ifeq ($(uname_S),Linux)
6+
SHOBJ_CFLAGS= -I. -I$(DEPS_DIR)/lua/src -I$(DEPS_DIR)/fpconv -fPIC -W -Wall -fno-common $(OPTIMIZATION) -std=c99 -D_GNU_SOURCE $(CFLAGS)
7+
SHOBJ_LDFLAGS= -shared
8+
else
9+
SHOBJ_CFLAGS= -I. -I$(DEPS_DIR)/lua/src -I$(DEPS_DIR)/fpconv -fPIC -W -Wall -dynamic -fno-common $(OPTIMIZATION) -std=c99 -D_GNU_SOURCE $(CFLAGS)
10+
SHOBJ_LDFLAGS= -bundle -undefined dynamic_lookup
11+
endif
12+
413
LIBS= $(DEPS_DIR)/lua/src/liblua.a $(DEPS_DIR)/fpconv/libfpconv.a
5-
SRCS = $(wildcard *.c)
6-
OBJS = $(SRCS:.c=.o)
14+
SRCS= $(wildcard *.c)
15+
OBJS= $(SRCS:.c=.o) sha1.o rand.o
16+
17+
# OS X 11.x doesn't have /usr/lib/libSystem.dylib and needs an explicit setting.
18+
ifeq ($(uname_S),Darwin)
19+
ifeq ("$(wildcard /usr/lib/libSystem.dylib)","")
20+
SHOBJ_LDFLAGS+= -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lsystem
21+
endif
22+
endif
723

824
all: libluaengine.so
925

10-
libluaengine.so: $(LIBS) $(OBJS)
11-
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS)
26+
libluaengine.so: $(OBJS) $(LIBS)
27+
$(CC) -o $@ $(SHOBJ_LDFLAGS) $^
28+
29+
sha1.o: ../../sha1.c
30+
$(CC) $(SHOBJ_CFLAGS) -c $< -o $@
31+
32+
rand.o: ../../rand.c
33+
$(CC) $(SHOBJ_CFLAGS) -c $< -o $@
1234

1335
%.o: %.c
14-
$(CC) $(CFLAGS) -c $< -o $@
36+
$(CC) $(SHOBJ_CFLAGS) -c $< -o $@
1537

1638
$(DEPS_DIR)/lua/src/liblua.a:
1739
cd $(DEPS_DIR) && $(MAKE) lua

src/modules/lua/engine_lua.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <lauxlib.h>
44
#include <lualib.h>
55
#include <string.h>
6+
#if defined(__GLIBC__) && !defined(USE_LIBC)
67
#include <malloc.h>
8+
#endif
79
#include <errno.h>
810

911
#include "engine_structs.h"
@@ -321,7 +323,7 @@ static void resetLuaContext(void *context) {
321323
lua_gc(lua, LUA_GCCOLLECT, 0);
322324
lua_close(lua);
323325

324-
#if !defined(USE_LIBC)
326+
#if defined(__GLIBC__) && !defined(USE_LIBC)
325327
/* The lua interpreter may hold a lot of memory internally, and lua is
326328
* using libc. libc may take a bit longer to return the memory to the OS,
327329
* so after lua_close, we call malloc_trim try to purge it earlier.

0 commit comments

Comments
 (0)