Skip to content

Commit af4508f

Browse files
zjcnarutozjc
andauthored
feature: support working on mac os (openresty#34)
Co-authored-by: zjc <[email protected]>
1 parent 5647c48 commit af4508f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ LDFLAGS := -shared
1818
# on Mac OS X, one should set instead:
1919
# LDFLAGS := -bundle -undefined dynamic_lookup
2020

21+
ifeq ($(shell uname),Darwin)
22+
LDFLAGS := -bundle -undefined dynamic_lookup
23+
C_SO_NAME := librestychash.dylib
24+
endif
25+
2126
MY_CFLAGS := $(CFLAGS) -DBUILDING_SO
2227
MY_LDFLAGS := $(LDFLAGS) -fvisibility=hidden
2328

lib/resty/chash.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ local function load_shared_lib(so_name)
5555

5656
local cpath = package.cpath
5757

58+
local postfix = ".so"
59+
if ffi.os == "OSX" then
60+
postfix = ".dylib"
61+
end
62+
so_name = so_name .. postfix
63+
5864
for k, _ in string_gmatch(cpath, "[^;]+") do
5965
local fpath = string_match(k, "(.*/)")
6066
fpath = fpath .. so_name
@@ -74,9 +80,9 @@ local _M = {}
7480
local mt = { __index = _M }
7581

7682

77-
local clib = load_shared_lib("librestychash.so")
83+
local clib = load_shared_lib("librestychash")
7884
if not clib then
79-
error("can not load librestychash.so")
85+
error("can not load librestychash")
8086
end
8187

8288
local CONSISTENT_POINTS = 160 -- points per server

0 commit comments

Comments
 (0)