2024-08-31 13:39:50 -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
|
|
|
|
|
2024-09-03 06:20:53 -04:00
|
|
|
LUA_VERSIONS := luajit lua51
|
2024-09-03 04:09:13 -04:00
|
|
|
|
2024-08-31 13:39:50 -04:00
|
|
|
BUILD_DIR := build
|
2024-09-03 06:20:53 -04:00
|
|
|
BUILD_FROM_SOURCE ?= false
|
2024-09-03 04:09:13 -04:00
|
|
|
TARGET_LIBRARY ?= all
|
2024-08-31 13:39:50 -04:00
|
|
|
|
|
|
|
all: luajit
|
|
|
|
|
2024-09-03 04:09:13 -04:00
|
|
|
define make_definitions
|
2024-09-03 06:20:53 -04:00
|
|
|
ifeq ($(BUILD_FROM_SOURCE),true)
|
2024-09-03 04:09:13 -04:00
|
|
|
ifeq ($(TARGET_LIBRARY), all)
|
2025-02-06 19:13:47 +08:00
|
|
|
$1: $(BUILD_DIR)/libAvanteTokenizers-$1.$(EXT) $(BUILD_DIR)/libAvanteTemplates-$1.$(EXT) $(BUILD_DIR)/libAvanteRepoMap-$1.$(EXT) $(BUILD_DIR)/libAvanteHtml2md-$1.$(EXT)
|
2024-09-03 04:09:13 -04:00
|
|
|
else ifeq ($(TARGET_LIBRARY), tokenizers)
|
|
|
|
$1: $(BUILD_DIR)/libAvanteTokenizers-$1.$(EXT)
|
|
|
|
else ifeq ($(TARGET_LIBRARY), templates)
|
|
|
|
$1: $(BUILD_DIR)/libAvanteTemplates-$1.$(EXT)
|
2024-09-26 03:45:49 +08:00
|
|
|
else ifeq ($(TARGET_LIBRARY), repo-map)
|
|
|
|
$1: $(BUILD_DIR)/libAvanteRepoMap-$1.$(EXT)
|
2025-02-06 19:13:47 +08:00
|
|
|
else ifeq ($(TARGET_LIBRARY), html2md)
|
|
|
|
$1: $(BUILD_DIR)/libAvanteHtml2md-$1.$(EXT)
|
2024-09-03 04:09:13 -04:00
|
|
|
else
|
2025-02-06 19:13:47 +08:00
|
|
|
$$(error TARGET_LIBRARY must be one of all, tokenizers, templates, repo-map, html2md)
|
2024-09-03 04:09:13 -04:00
|
|
|
endif
|
2024-09-03 06:20:53 -04:00
|
|
|
else
|
|
|
|
$1:
|
2024-09-04 16:34:33 +02:00
|
|
|
LUA_VERSION=$1 bash ./build.sh
|
2024-09-03 06:20:53 -04:00
|
|
|
endif
|
2024-09-03 04:09:13 -04:00
|
|
|
endef
|
|
|
|
|
|
|
|
$(foreach lua_version,$(LUA_VERSIONS),$(eval $(call make_definitions,$(lua_version))))
|
2024-08-31 13:39:50 -04:00
|
|
|
|
2024-09-03 06:20:53 -04:00
|
|
|
define build_package
|
|
|
|
$1-$2:
|
2024-09-03 04:09:13 -04:00
|
|
|
cargo build --release --features=$1 -p avante-$2
|
2024-09-26 03:45:49 +08:00
|
|
|
cp target/release/libavante_$(shell echo $2 | tr - _).$(EXT) $(BUILD_DIR)/avante_$(shell echo $2 | tr - _).$(EXT)
|
2024-09-03 04:09:13 -04:00
|
|
|
endef
|
|
|
|
|
|
|
|
define build_targets
|
2024-09-03 06:20:53 -04:00
|
|
|
$(BUILD_DIR)/libAvanteTokenizers-$1.$(EXT): $(BUILD_DIR) $1-tokenizers
|
|
|
|
$(BUILD_DIR)/libAvanteTemplates-$1.$(EXT): $(BUILD_DIR) $1-templates
|
2024-09-26 03:45:49 +08:00
|
|
|
$(BUILD_DIR)/libAvanteRepoMap-$1.$(EXT): $(BUILD_DIR) $1-repo-map
|
2025-02-06 19:13:47 +08:00
|
|
|
$(BUILD_DIR)/libAvanteHtml2md-$1.$(EXT): $(BUILD_DIR) $1-html2md
|
2024-08-31 13:39:50 -04:00
|
|
|
endef
|
|
|
|
|
2024-09-03 06:20:53 -04:00
|
|
|
$(foreach lua_version,$(LUA_VERSIONS),$(eval $(call build_package,$(lua_version),tokenizers)))
|
|
|
|
$(foreach lua_version,$(LUA_VERSIONS),$(eval $(call build_package,$(lua_version),templates)))
|
2024-09-26 03:45:49 +08:00
|
|
|
$(foreach lua_version,$(LUA_VERSIONS),$(eval $(call build_package,$(lua_version),repo-map)))
|
2025-02-06 19:13:47 +08:00
|
|
|
$(foreach lua_version,$(LUA_VERSIONS),$(eval $(call build_package,$(lua_version),html2md)))
|
2024-09-03 04:09:13 -04:00
|
|
|
$(foreach lua_version,$(LUA_VERSIONS),$(eval $(call build_targets,$(lua_version))))
|
2024-08-31 13:39:50 -04:00
|
|
|
|
|
|
|
$(BUILD_DIR):
|
2024-09-03 06:20:53 -04:00
|
|
|
@mkdir -p $(BUILD_DIR)
|
2024-08-31 13:39:50 -04:00
|
|
|
|
|
|
|
clean:
|
2024-09-03 06:20:53 -04:00
|
|
|
@rm -rf $(BUILD_DIR)
|
2024-08-28 20:57:50 +08:00
|
|
|
|
2024-08-12 23:53:28 +08:00
|
|
|
luacheck:
|
2024-09-03 06:20:53 -04:00
|
|
|
@luacheck `find -name "*.lua"` --codes
|
2024-08-12 23:53:28 +08:00
|
|
|
|
2025-01-10 00:23:59 +08:00
|
|
|
luastylecheck:
|
|
|
|
@stylua --check lua/ plugin/ tests/
|
2024-08-12 23:53:28 +08:00
|
|
|
|
|
|
|
stylefix:
|
2024-09-03 06:20:53 -04:00
|
|
|
@stylua lua/ plugin/
|
|
|
|
|
|
|
|
.PHONY: ruststylecheck
|
|
|
|
ruststylecheck:
|
|
|
|
@rustup component add rustfmt 2> /dev/null
|
|
|
|
@cargo fmt --all -- --check
|
|
|
|
|
|
|
|
.PHONY: rustlint
|
|
|
|
rustlint:
|
|
|
|
@rustup component add clippy 2> /dev/null
|
|
|
|
@cargo clippy -F luajit --all -- -F clippy::dbg-macro -D warnings
|
2025-01-10 00:23:59 +08:00
|
|
|
|
|
|
|
.PHONY: rusttest
|
|
|
|
rusttest:
|
|
|
|
@cargo test --features luajit
|
|
|
|
|
|
|
|
.PHONY: luatest
|
|
|
|
luatest:
|
|
|
|
nvim --headless -c "PlenaryBustedDirectory tests/"
|
|
|
|
|
|
|
|
.PHONY: lint
|
|
|
|
lint: luacheck luastylecheck ruststylecheck rustlint
|