From 9d95308a57688fa0cb109115d5c11e6a6eb3d217 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Mon, 27 Sep 2021 14:59:41 -0400 Subject: [PATCH] build: Makefile cleanup --- runtime/Makefile | 29 +++++++++++++++++++---------- runtime/tests/Makefile | 33 ++++++++++++++++----------------- runtime/thirdparty/Makefile | 29 +++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 31 deletions(-) diff --git a/runtime/Makefile b/runtime/Makefile index 196cd44..9561c5c 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -83,7 +83,15 @@ CFLAGS += -D${ARCH} CFLAGS += -DUSE_MEM_VM # Preprocessor + +# SLEdge serverless functions are *.so shared-libraries. The runtime thus requires the dynamic linker +# to load these functions at runtime. These *.so shared-libraries also depend on specific symbols from +# the runtime to execute. The export-dynamic Linker flag adds all globals to the dynamic symbol table, +# allowing the libraries acess to such symbols. The libm math library is used several places, including +# in backing functions that implement the WebAssembly instruction set. LDFLAGS += -Wl,--export-dynamic -ldl -lm + +# Our third-party dependencies build into a single dist directory to simplify configuration here. LDFLAGS += -Lthirdparty/dist/lib/ INCLUDES += -Iinclude/ -Ithirdparty/dist/include/ @@ -99,34 +107,35 @@ CFILES += thirdparty/dist/lib/http_parser.o JSMNCFLAGS += -DJSMN_STATIC JSMNCFLAGS += -DJSMN_STRICT +.PHONY: all all: runtime -runtime: +bin/sledgert: ${CFILES} @echo "Compiling runtime" @mkdir -p bin/ - @${CC} ${CC_OPTIONS} ${INCLUDES} ${CFLAGS} ${LDFLAGS} ${CFILES} ${JSMNCFLAGS} -L/usr/lib/ $^ -o bin/${BINARY_NAME} + @${CC} ${CC_OPTIONS} ${INCLUDES} ${CFLAGS} ${LDFLAGS} ${CFILES} ${JSMNCFLAGS} -L/usr/lib/ $^ -o bin/sledgert + +.PHONY: runtime +runtime: bin/sledgert +.PHONY: thirdparty thirdparty: @echo "Compiling thirdparty" @make --no-print-directory -C thirdparty build -tools: -# @echo "Compiling tools" - @make --no-print-directory -C tools - +.PHONY: clean clean: @rm -f core @echo "Cleaning up runtime" @rm -f bin/${BINARY_NAME} -# @echo "Cleaning up tools" -# @make --no-print-directory -C tools clean +.PHONY: distclean distclean: clean @make --no-print-directory -C thirdparty clean +.PHONY: submodules fetch: @git submodule update --init --recursive +.PHONY: init init: fetch clean thirdparty runtime - -.PHONY: all init clean fetch thirdparty runtime tools diff --git a/runtime/tests/Makefile b/runtime/tests/Makefile index 14388e6..02004e8 100644 --- a/runtime/tests/Makefile +++ b/runtime/tests/Makefile @@ -4,46 +4,39 @@ TESTS=fibonacci empty work work1k work10k work100k work1m forever filesys sockse TESTSRT=$(TESTS:%=%_rt) -.PHONY: all clean rttests tinyekf cifar10 gocr sod - +.PHONY: all all: rttests tinyekf cifar10 gocr sod @echo "Test Compilation done!" +.PHONY: rttests rttests: $(TESTSRT) +.PHONY: clean clean: @echo "Cleaning Test Applications" - @make clean -C ./empty/ - @rm -f wasm/empty.wasm bc/empty.bc so/empty.so - @rm -rf ${SLEDGE_BIN_DIR}/empty.so ${SLEDGE_BIN_DIR}/test_empty.json - - @make clean -C ./echo/ - @rm -f wasm/echo.wasm bc/echo.bc so/echo.so - @rm -rf ${SLEDGE_BIN_DIR}/echo.so ${SLEDGE_BIN_DIR}/test_echo.json - - @make clean -C ./fibonacci/ - @rm -f wasm/fibonacci.wasm bc/fibonacci.bc so/fibonacci.so - @rm -rf ${SLEDGE_BIN_DIR}/fibonacci.so ${SLEDGE_BIN_DIR}/test_fibonacci.json - - @make clean -C ./TinyEKF/ -f wasm.mk - @rm -f wasm/gps_ekf.wasm bc/gps_ekf.bc so/gps_ekf.so - @rm -rf ${SLEDGE_BIN_DIR}/gps_ekf.so ${SLEDGE_BIN_DIR}/test_gps_ekf.json + @rm -rf ${TMP_DIR} + @make clean -C ./gocr/src/ -f wasm.mk + @make clean -C ./sod/ +.PHONY: tinyekf tinyekf: @echo "Making and Installing tinyekf" @make gps_ekf_fn.so -C ./TinyEKF/extras/c/ -f wasm.mk @cp ./TinyEKF/extras/c/gps_ekf_fn.so ${SLEDGE_BIN_DIR}/ekf_wasm.so +.PHONY: cifar10 cifar10: @echo "Making and Installing cifar10" @make cifar10.so -C ./CMSIS_5_NN/ -f Makefile @cp ./CMSIS_5_NN/cifar10.so ${SLEDGE_BIN_DIR}/cifar10_wasm.so +.PHONY: gocr gocr: @echo "Making and Installing gocr" @make gocr.so -C ./gocr/src/ -f wasm.mk @cp ./gocr/src/gocr.so ${SLEDGE_BIN_DIR}/gocr_wasm.so +.PHONY: sod sod: @echo "Making and Installing license_plate_detection and image_resize" @make dir samples.so -C ./sod/ @@ -52,10 +45,16 @@ sod: %_rt: @mkdir -p ${TMP_DIR} + # Compile the wasm file @echo "Compiling $(@:%_rt=%)" ${WASMCC} ${$(@:%_rt=%)_CFLAGS} ${WASMCFLAGS} ${OPTFLAGS} $(@:%_rt=%)/*.c $(AWSM_DUMMY) -o ${TMP_DIR}/$(@:%_rt=%).wasm + + # Compile the *.bc file + ${AWSM_NAME} --inline-constant-globals --runtime-globals ${TMP_DIR}/$(@:%_rt=%).wasm -o ${TMP_DIR}/$(@:%_rt=%).bc + # Compile the *.so file ${CC} --shared -fPIC ${OPTFLAGS} -I${SLEDGE_RT_INC} -D${USE_MEM} ${TMP_DIR}/$(@:%_rt=%).bc ${SLEDGE_MEMC} ${SLEDGE_WASMISA} -o ${TMP_DIR}/$(@:%_rt=%)_wasm.so + # Copy the *.so file to the binary directory @cp ${TMP_DIR}/$(@:%_rt=%)_wasm.so ${SLEDGE_BIN_DIR} # @rm -rf ${TMP_DIR} diff --git a/runtime/thirdparty/Makefile b/runtime/thirdparty/Makefile index ed69cc7..924acda 100644 --- a/runtime/thirdparty/Makefile +++ b/runtime/thirdparty/Makefile @@ -1,24 +1,45 @@ CURR_DIR= $(shell pwd) DIST_PREFIX=${CURR_DIR}/dist/ +.PHONY: all all: clean build +.PHONY: build build: ck jsmn http-parser -ck: +# Concurrency Kit +.PHONY: ck +ck: ck/configure ck/Makefile mkdir -p ${DIST_PREFIX} cd ck; ./configure --cores=$(shell getconf _NPROCESSORS_CONF) --prefix=${DIST_PREFIX} make -C ck all make -C ck install -http-parser: http-parser/http_parser.c +# HTTP Parser +${DIST_PREFIX}/include/http_parser.h: http-parser/http_parser.h + mkdir -p ${DIST_PREFIX} + mkdir -p ${DIST_PREFIX}/include/ + cp http-parser/http_parser.h ${DIST_PREFIX}/include/ + +${DIST_PREFIX}/lib/http_parser.o: http-parser/http_parser.c http-parser/http_parser.h + mkdir -p ${DIST_PREFIX} mkdir -p ${DIST_PREFIX}/lib/ - cd http-parser; $(CC) $(CFLAGS) -I. -c http_parser.c; mv http_parser.o ${DIST_PREFIX}/lib/; cp http_parser.h ${DIST_PREFIX}/include/ + cd http-parser; $(CC) $(CFLAGS) -I. -c http_parser.c + mv http-parser/http_parser.o ${DIST_PREFIX}/lib/ -jsmn: +.PHONY: http-parser +http-parser: ${DIST_PREFIX}/lib/http_parser.o ${DIST_PREFIX}/include/http_parser.h + +# Jasmine JSON Parser +${DIST_PREFIX}/include/jsmn.h: jsmn/jsmn.h + mkdir -p ${DIST_PREFIX} mkdir -p ${DIST_PREFIX}/include/ cp jsmn/jsmn.h ${DIST_PREFIX}/include/ +.PHONY: jsmn +jsmn: ${DIST_PREFIX}/include/jsmn.h + +.PHONY: clean clean: make -C ck uninstall rm -rf ${DIST_PREFIX}