diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2d1c2aa --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/lua-cjson"] + path = vendor/lua-cjson + url = https://github.com/openresty/lua-cjson.git diff --git a/Makefile b/Makefile index fe5609d..dcf93ee 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,16 @@ # Overridable: `make bench LUAJIT=/path/to/luajit LUA_CPATH='...'` LUAJIT ?= $(shell command -v luajit 2>/dev/null || echo /usr/local/openresty/luajit/bin/luajit) -LUA_CPATH ?= ./?.so;/usr/local/openresty/lualib/?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so +LUA_CPATH ?= ./vendor/lua-cjson/?.so;./?.so;/usr/local/openresty/lualib/?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so + +LUAJIT_PREFIX ?= $(shell dirname $$(dirname $$(command -v $(LUAJIT) 2>/dev/null || echo /usr/local/openresty/luajit/bin/luajit))) +LUAJIT_INC ?= $(LUAJIT_PREFIX)/include/luajit-2.1 LIB_DIR := $(CURDIR)/target/release +ifeq ($(shell uname),Darwin) +LUA_ENV := DYLD_LIBRARY_PATH=$(LIB_DIR) LUA_CPATH='$(LUA_CPATH)' +else LUA_ENV := LD_LIBRARY_PATH=$(LIB_DIR) LUA_CPATH='$(LUA_CPATH)' +endif .PHONY: help build test lint bench clean @@ -22,8 +29,15 @@ test: build ## Run cargo tests + busted Lua tests lint: ## Run clippy with -D warnings cargo clippy --release --all-targets -- -D warnings -bench: build ## Run the LuaJIT vs cjson benchmark +bench: build vendor/lua-cjson/cjson.so ## Run the LuaJIT vs cjson benchmark $(LUA_ENV) $(LUAJIT) benches/lua_bench.lua +vendor/lua-cjson/cjson.so: | vendor/lua-cjson/Makefile +ifeq ($(shell uname),Darwin) + $(MAKE) -C vendor/lua-cjson PREFIX=$(LUAJIT_PREFIX) LUA_INCLUDE_DIR=$(LUAJIT_INC) LUA=$(LUAJIT) CJSON_LDFLAGS="-bundle -undefined dynamic_lookup" +else + $(MAKE) -C vendor/lua-cjson PREFIX=$(LUAJIT_PREFIX) LUA_INCLUDE_DIR=$(LUAJIT_INC) LUA=$(LUAJIT) +endif + clean: ## Remove build artifacts cargo clean diff --git a/vendor/lua-cjson b/vendor/lua-cjson new file mode 160000 index 0000000..617164a --- /dev/null +++ b/vendor/lua-cjson @@ -0,0 +1 @@ +Subproject commit 617164a0fe3bb647128178f9caefb304b8573bb6