Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds wasmtime-c-api dependency to support WASM scripts/functions #1183

Draft
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ fpconv: .make-prerequisites

.PHONY: fpconv

download-wasm-binary-deps: .make-prerequisites
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
cd wasmtime-c-api && $(MAKE)

.PHONY: download-wasm-binary-deps

ifeq ($(uname_S),SunOS)
# Make isinf() available
LUA_CFLAGS= -D__C99FEATURES__=1
Expand Down
5 changes: 5 additions & 0 deletions deps/wasmtime-c-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LICENSE
README*
lib
include
min
22 changes: 22 additions & 0 deletions deps/wasmtime-c-api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
WASMTIME_VERSION=v25.0.2
WASMTIME_PLATFORM=$(shell sh -c 'uname -s 2>/dev/null | tr A-Z a-z || echo not')
WASMTIME_ARCH=$(shell sh -c 'uname -m 2>/dev/null || echo not')

WASMTIME_PKG_NAME=wasmtime-$(WASMTIME_VERSION)-$(WASMTIME_ARCH)-$(WASMTIME_PLATFORM)-c-api
WASMTIME_PKG_URL=https://github.com/bytecodealliance/wasmtime/releases/download/$(WASMTIME_VERSION)/$(WASMTIME_PKG_NAME).tar.xz

WASTIME_FILE_LIST=lib min include LICENSE README.md

$(WASTIME_FILE_LIST):
curl -L -O $(WASMTIME_PKG_URL)
tar -xf $(WASMTIME_PKG_NAME).tar.xz
mv $(WASMTIME_PKG_NAME)/* .
rm -r $(WASMTIME_PKG_NAME)
rm $(WASMTIME_PKG_NAME).tar.xz


clean:
rm -rf $(WASTIME_FILE_LIST)


.PHONY: clean
35 changes: 34 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,30 @@ else
LIBCRYPTO_LIBS=-lcrypto
endif

# WASM Support
WASM_STATIC_LIB=
ifeq ($(BUILD_WITH_WASM),yes)
WASMTIME_ROOT?=../deps/wasmtime-c-api

WASM_LIB_EXISTS=$(shell test -f $(WASMTIME_ROOT)/lib/libwasmtime.a && echo $$?)
ifeq ($(WASM_LIB_EXISTS),0)
WASM_STATIC_LIB= $(WASMTIME_ROOT)/lib/libwasmtime.a
WASM_CFLAGS+= -I$(WASMTIME_ROOT)/include -DWASM_ENABLED -Wno-strict-prototypes
else
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), distclean)
ifneq ($(MAKECMDGOALS), download-wasm-binary-deps)
ifeq ($(WASMTIME_ROOT), ../deps/wasmtime-c-api)
$(error "WASMTIME library cannot be found in '$(WASMTIME_ROOT)', please run 'make download-wasm-binary-deps' to download wasmtime library.")
else
$(error "WASMTIME library cannot be found in '$(WASMTIME_ROOT)'.")
endif
endif
endif
endif
endif
endif

BUILD_NO:=0
BUILD_YES:=1
BUILD_MODULE:=2
Expand Down Expand Up @@ -467,6 +491,7 @@ persist-settings: distclean
echo SERVER_LDFLAGS=$(SERVER_LDFLAGS) >> .make-settings
echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> .make-settings
echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> .make-settings
echo BUILD_WITH_WASM=$(BUILD_WITH_WASM) >> .make-settings
-(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))

.PHONY: persist-settings
Expand All @@ -486,7 +511,7 @@ endif

# valkey-server
$(SERVER_NAME): $(ENGINE_SERVER_OBJ)
$(SERVER_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a ../deps/hdr_histogram/libhdrhistogram.a ../deps/fpconv/libfpconv.a $(FINAL_LIBS)
$(SERVER_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a ../deps/hdr_histogram/libhdrhistogram.a ../deps/fpconv/libfpconv.a $(WASM_STATIC_LIB) $(FINAL_LIBS)

# Valkey static library, used to compile against for unit testing
$(ENGINE_LIB_NAME): $(ENGINE_SERVER_OBJ)
Expand Down Expand Up @@ -536,6 +561,9 @@ DEP = $(ENGINE_SERVER_OBJ:%.o=%.d) $(ENGINE_CLI_OBJ:%.o=%.d) $(ENGINE_BENCHMARK_
unit/%.o: unit/%.c .make-prerequisites
$(SERVER_CC) -MMD -o $@ -c $<

wasm.o: wasm.c
$(SERVER_CC) $(WASM_CFLAGS) -MMD -o $@ -c $<

# The following files are checked in and don't normally need to be rebuilt. They
# are built only if python is available and their prereqs are modified.
ifneq (,$(PYTHON))
Expand Down Expand Up @@ -639,3 +667,8 @@ uninstall:
$(call MAYBE_UNINSTALL_REDIS_SYMLINK,$(INSTALL_BIN),$(ENGINE_CHECK_RDB_NAME))
$(call MAYBE_UNINSTALL_REDIS_SYMLINK,$(INSTALL_BIN),$(ENGINE_CHECK_AOF_NAME))
$(call MAYBE_UNINSTALL_REDIS_SYMLINK,$(INSTALL_BIN),$(ENGINE_SENTINEL_NAME))

download-wasm-binary-deps:
cd ../deps; $(MAKE) $@

.PHONY: download-wasm-binary-deps
Loading