2024-08-15 08:59:01 -04:00
|
|
|
UNAME := $(shell uname)
|
|
|
|
ARCH := $(shell uname -m)
|
|
|
|
|
|
|
|
ifeq ($(UNAME), Linux)
|
|
|
|
OS := linux
|
|
|
|
EXT := so
|
|
|
|
else ifeq ($(UNAME), Darwin)
|
|
|
|
OS := macOS
|
|
|
|
EXT := dylib
|
|
|
|
else
|
|
|
|
$(error Unsupported operating system: $(UNAME))
|
|
|
|
endif
|
|
|
|
|
|
|
|
LUA_VERSIONS := luajit lua51
|
|
|
|
BUILD_DIR := build
|
2024-08-19 15:41:18 -04:00
|
|
|
BUILD_FROM_SOURCE := false
|
2024-08-15 08:59:01 -04:00
|
|
|
|
|
|
|
all: luajit
|
|
|
|
|
|
|
|
luajit: $(BUILD_DIR)/tiktoken_core.$(EXT)
|
|
|
|
lua51: $(BUILD_DIR)/tiktoken_core-lua51.$(EXT)
|
|
|
|
|
|
|
|
define build_from_source
|
2024-08-26 08:36:05 -04:00
|
|
|
git clone --branch v0.2.2 --depth 1 https://github.com/gptlang/lua-tiktoken.git $(BUILD_DIR)/lua-tiktoken-temp
|
2024-08-15 08:59:01 -04:00
|
|
|
cd $(BUILD_DIR)/lua-tiktoken-temp && cargo build --features=$1
|
|
|
|
cp $(BUILD_DIR)/lua-tiktoken-temp/target/debug/libtiktoken_core.$(EXT) $(BUILD_DIR)/tiktoken_core.$(EXT)
|
|
|
|
rm -rf $(BUILD_DIR)/lua-tiktoken-temp
|
|
|
|
endef
|
|
|
|
|
2024-08-26 08:36:05 -04:00
|
|
|
$(BUILD_DIR)/tiktoken_core.$(EXT): $(BUILD_DIR)
|
2024-08-15 08:59:01 -04:00
|
|
|
$(call build_from_source,luajit)
|
2024-08-26 08:36:05 -04:00
|
|
|
$(BUILD_DIR)/tiktoken_core-lua51.$(EXT): $(BUILD_DIR)
|
2024-08-15 08:59:01 -04:00
|
|
|
$(call build_from_source,lua51)
|
|
|
|
|
|
|
|
$(BUILD_DIR):
|
|
|
|
mkdir -p $(BUILD_DIR)
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf $(BUILD_DIR)
|
|
|
|
|
2024-08-12 23:53:28 +08:00
|
|
|
luacheck:
|
2024-08-15 08:59:01 -04:00
|
|
|
luacheck `find -name "*.lua"` --codes
|
2024-08-12 23:53:28 +08:00
|
|
|
|
|
|
|
stylecheck:
|
|
|
|
stylua --check lua/
|
|
|
|
|
|
|
|
stylefix:
|
|
|
|
stylua lua/
|