diff --git a/.gitignore b/.gitignore index ef0fa359c..130dd0d91 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,11 @@ *.d *.clang-tidy *.deb +*.a +*.wasm build +pkg third-party/downloads third-party/mongoose-* src/remote-cartesi-machine @@ -22,6 +25,7 @@ doc/xml/ .vscode .ycm_extra_conf.py +*.tar.gz *.raw *.so *.dylib diff --git a/Dockerfile b/Dockerfile index 895c6d1dc..8de580650 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN apt-get update && \ DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \ build-essential vim wget git clang-tidy-15 clang-format-15 lcov \ libboost1.81-dev libssl-dev \ - ca-certificates automake libtool patchelf pkg-config lua5.4 liblua5.4-dev \ + ca-certificates automake libtool pkg-config lua5.4 liblua5.4-dev \ libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \ luarocks && \ update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 120 && \ diff --git a/Makefile b/Makefile index 2b6134afa..c82d5d5cd 100644 --- a/Makefile +++ b/Makefile @@ -30,43 +30,53 @@ SHARE_RUNTIME_PATH= $(PREFIX)/share/cartesi-machine IMAGES_RUNTIME_PATH= $(SHARE_RUNTIME_PATH)/images LUA_RUNTIME_CPATH= $(PREFIX)/lib/lua/5.4 LUA_RUNTIME_PATH= $(PREFIX)/share/lua/5.4 -INSTALL_PLAT = install-$(TARGET_OS) LIBCARTESI_Darwin=libcartesi.dylib LIBCARTESI_Linux=libcartesi.so LIBCARTESI_GRPC_Darwin=libcartesi_grpc.dylib LIBCARTESI_GRPC_Linux=libcartesi_grpc.so +LIBCARTESI_JSONRPC_Darwin=libcartesi_jsonrpc.dylib +LIBCARTESI_JSONRPC_Linux=libcartesi_jsonrpc.so LIBCARTESI_SO_Darwin:=libcartesi-$(MACHINE_EMULATOR_SO_VERSION).dylib LIBCARTESI_SO_Linux:=libcartesi-$(MACHINE_EMULATOR_SO_VERSION).so LIBCARTESI_SO_GRPC_Darwin:=libcartesi_grpc-$(MACHINE_EMULATOR_SO_VERSION).dylib LIBCARTESI_SO_GRPC_Linux:=libcartesi_grpc-$(MACHINE_EMULATOR_SO_VERSION).so - -BIN_INSTALL_PATH:= $(DESTDIR)$(BIN_RUNTIME_PATH) -LIB_INSTALL_PATH:= $(DESTDIR)$(LIB_RUNTIME_PATH) -DOC_INSTALL_PATH:= $(DESTDIR)$(DOC_RUNTIME_PATH) -SHARE_INSTALL_PATH:= $(DESTDIR)$(SHARE_RUNTIME_PATH) -IMAGES_INSTALL_PATH:= $(DESTDIR)$(IMAGES_RUNTIME_PATH) -UARCH_INSTALL_PATH:= $(SHARE_INSTALL_PATH)/uarch -LUA_INSTALL_CPATH:= $(DESTDIR)$(LUA_RUNTIME_CPATH) -LUA_INSTALL_PATH:= $(DESTDIR)$(LUA_RUNTIME_PATH) -INC_INSTALL_PATH:= $(DESTDIR)$(PREFIX)/include/cartesi-machine - -INSTALL= cp -RP +LIBCARTESI_SO_JSONRPC_Darwin:=libcartesi_jsonrpc-$(MACHINE_EMULATOR_SO_VERSION).dylib +LIBCARTESI_SO_JSONRPC_Linux:=libcartesi_jsonrpc-$(MACHINE_EMULATOR_SO_VERSION).so + +BIN_INSTALL_PATH:= $(abspath $(DESTDIR)$(BIN_RUNTIME_PATH)) +LIB_INSTALL_PATH:= $(abspath $(DESTDIR)$(LIB_RUNTIME_PATH)) +DOC_INSTALL_PATH:= $(abspath $(DESTDIR)$(DOC_RUNTIME_PATH)) +SHARE_INSTALL_PATH:= $(abspath $(DESTDIR)$(SHARE_RUNTIME_PATH)) +IMAGES_INSTALL_PATH:= $(abspath $(DESTDIR)$(IMAGES_RUNTIME_PATH)) +UARCH_INSTALL_PATH:= $(abspath $(SHARE_INSTALL_PATH)/uarch) +LUA_INSTALL_CPATH:= $(abspath $(DESTDIR)$(LUA_RUNTIME_CPATH)) +LUA_INSTALL_PATH:= $(abspath $(DESTDIR)$(LUA_RUNTIME_PATH)) +INC_INSTALL_PATH:= $(abspath $(DESTDIR)$(PREFIX)/include/cartesi-machine) + +INSTALL_FILE= install -m0644 +INSTALL_EXEC= install -m0755 +INSTALL_DIR= cp -RP +SYMLINK= ln -sf CHMOD_EXEC= chmod 0755 -CHMOD_DATA= chmod 0644 STRIP= strip -STRIP_EXEC= $(STRIP) -x - -EMU_TO_BIN= jsonrpc-remote-cartesi-machine remote-cartesi-machine merkle-tree-hash -EMU_TO_LIB= $(LIBCARTESI_SO_$(TARGET_OS)) $(LIBCARTESI_SO_GRPC_$(TARGET_OS)) -EMU_LUA_TO_BIN= cartesi-machine.lua cartesi-machine-stored-hash.lua rollup-memory-range.lua -EMU_LUA_TEST_TO_BIN= cartesi-machine-tests.lua uarch-riscv-tests.lua -EMU_TO_LUA_PATH= cartesi/util.lua cartesi/proof.lua cartesi/gdbstub.lua -EMU_TO_LUA_CPATH= cartesi.so -EMU_TO_LUA_CARTESI_CPATH= cartesi/grpc.so cartesi/jsonrpc.so +STRIP_BINARY= $(STRIP) +STRIP_SHARED= $(STRIP) -S -x +STRIP_STATIC= $(STRIP) -S + +EMU_TO_BIN= src/jsonrpc-remote-cartesi-machine src/remote-cartesi-machine src/merkle-tree-hash +EMU_TEST_TO_BIN= src/tests/test-merkle-tree-hash src/tests/test-machine-c-api +EMU_TO_LIB= src/$(LIBCARTESI_SO_$(TARGET_OS)) src/$(LIBCARTESI_SO_GRPC_$(TARGET_OS)) src/$(LIBCARTESI_SO_JSONRPC_$(TARGET_OS)) +EMU_TO_LIB_A= src/libcartesi.a +EMU_LUA_TO_BIN= src/cartesi-machine.lua src/cartesi-machine-stored-hash.lua src/rollup-memory-range.lua +EMU_LUA_TEST_TO_BIN= src/cartesi-machine-tests.lua src/uarch-riscv-tests.lua +EMU_TO_LUA_PATH= src/cartesi/util.lua src/cartesi/proof.lua src/cartesi/gdbstub.lua +EMU_TO_LUA_CPATH= src/cartesi.so +EMU_TO_LUA_CARTESI_CPATH= src/cartesi/grpc.so src/cartesi/jsonrpc.so EMU_TO_INC= $(addprefix lib/machine-emulator-defines/,pma-defines.h rtc-defines.h) \ $(addprefix src/,jsonrpc-machine-c-api.h grpc-machine-c-api.h machine-c-api.h machine-c-defines.h machine-c-version.h) + UARCH_TO_SHARE= uarch-ram.bin MONGOOSE_VERSION=7.12 @@ -109,9 +119,6 @@ else ifeq ($(TARGET_OS),Linux) export CC=gcc export CXX=g++ LIBRARY_PATH := "export LD_LIBRARY_PATH=$(SRCDIR)" -# Unknown platform -else -INSTALL_PLAT= endif all: source-default @@ -256,60 +263,47 @@ uarch-with-linux-env: uarch-tests-with-linux-env: @$(MAKE) linux-env-exec CONTAINER_COMMAND="make uarch-tests" -install-Darwin: - install_name_tool -delete_rpath $(SRCDIR) -add_rpath $(LIB_RUNTIME_PATH) $(LUA_INSTALL_CPATH)/cartesi.so - install_name_tool -delete_rpath $(SRCDIR) -add_rpath $(LIB_RUNTIME_PATH) $(LUA_INSTALL_CPATH)/cartesi/grpc.so - install_name_tool -delete_rpath $(SRCDIR) -add_rpath $(LIB_RUNTIME_PATH) $(LUA_INSTALL_CPATH)/cartesi/jsonrpc.so - cd $(BIN_INSTALL_PATH) && \ - for x in $(EMU_TO_BIN); do \ - install_name_tool -delete_rpath $(SRCDIR) -add_rpath $(LIB_RUNTIME_PATH) $$x ;\ - done +install-headers: $(INC_INSTALL_PATH) + $(INSTALL_FILE) $(EMU_TO_INC) $(INC_INSTALL_PATH) + +install-emulator: $(BIN_INSTALL_PATH) $(LIB_INSTALL_PATH) $(LUA_INSTALL_CPATH)/cartesi $(LUA_INSTALL_PATH)/cartesi $(IMAGES_INSTALL_PATH) + $(INSTALL_EXEC) $(EMU_TO_BIN) $(BIN_INSTALL_PATH) + $(INSTALL_EXEC) $(EMU_TO_LIB) $(LIB_INSTALL_PATH) + $(INSTALL_FILE) $(EMU_TO_LIB_A) $(LIB_INSTALL_PATH) + $(INSTALL_FILE) $(EMU_LUA_TO_BIN) $(LUA_INSTALL_PATH) + $(INSTALL_EXEC) $(EMU_TO_LUA_CPATH) $(LUA_INSTALL_CPATH) + $(INSTALL_EXEC) $(EMU_TO_LUA_CARTESI_CPATH) $(LUA_INSTALL_CPATH)/cartesi + $(INSTALL_FILE) $(EMU_TO_LUA_PATH) $(LUA_INSTALL_PATH)/cartesi + cat tools/template/cartesi-machine.template | sed 's|ARG_LUA_PATH|$(LUA_RUNTIME_PATH)/?.lua|g;s|ARG_LUA_CPATH|$(LUA_RUNTIME_CPATH)/?.so|g;s|ARG_INSTALL_PATH|$(IMAGES_RUNTIME_PATH)|g;s|ARG_LUA_RUNTIME_PATH|$(LUA_RUNTIME_PATH)|g' > $(BIN_INSTALL_PATH)/cartesi-machine + cat tools/template/cartesi-machine-stored-hash.template | sed 's|ARG_LUA_PATH|$(LUA_RUNTIME_PATH)/?.lua|g;s|ARG_LUA_CPATH|$(LUA_RUNTIME_CPATH)/?.so|g;s|ARG_LUA_RUNTIME_PATH|$(LUA_RUNTIME_PATH)|g' > $(BIN_INSTALL_PATH)/cartesi-machine-stored-hash + cat tools/template/rollup-memory-range.template | sed 's|ARG_LUA_PATH|$(LUA_RUNTIME_PATH)/?.lua|g;s|ARG_LUA_CPATH|$(LUA_RUNTIME_CPATH)/?.so|g;s|ARG_LUA_RUNTIME_PATH|$(LUA_RUNTIME_PATH)|g' > $(BIN_INSTALL_PATH)/rollup-memory-range + $(CHMOD_EXEC) $(BIN_INSTALL_PATH)/cartesi-machine $(BIN_INSTALL_PATH)/cartesi-machine-stored-hash $(BIN_INSTALL_PATH)/rollup-memory-range + $(SYMLINK) $(LIBCARTESI_SO_$(TARGET_OS)) $(LIB_INSTALL_PATH)/$(LIBCARTESI_$(TARGET_OS)) + $(SYMLINK) $(LIBCARTESI_SO_GRPC_$(TARGET_OS)) $(LIB_INSTALL_PATH)/$(LIBCARTESI_GRPC_$(TARGET_OS)) + $(SYMLINK) $(LIBCARTESI_SO_JSONRPC_$(TARGET_OS)) $(LIB_INSTALL_PATH)/$(LIBCARTESI_JSONRPC_$(TARGET_OS)) + $(INSTALL_DIR) tools/gdb $(SHARE_INSTALL_PATH)/gdb + +install-strip: install-emulator + $(STRIP_BINARY) $(subst src/,$(BIN_INSTALL_PATH)/,$(EMU_TO_BIN)) + $(STRIP_SHARED) $(subst src/,$(LUA_INSTALL_CPATH)/,$(EMU_TO_LUA_CPATH)) + $(STRIP_SHARED) $(subst src/,$(LIB_INSTALL_PATH)/,$(EMU_TO_LIB)) + $(STRIP_STATIC) $(subst src/,$(LIB_INSTALL_PATH)/,$(EMU_TO_LIB_A)) -install-Linux: - cd $(BIN_INSTALL_PATH) && for x in $(EMU_TO_BIN); do patchelf --set-rpath $(LIB_RUNTIME_PATH) $$x ; done - cd $(LIB_INSTALL_PATH) && for x in $(EMU_TO_LIB); do patchelf --set-rpath $(LIB_RUNTIME_PATH) $$x; done - cd $(LUA_INSTALL_CPATH) && for x in $(EMU_TO_LUA_CPATH) $(EMU_TO_LUA_CARTESI_CPATH); do patchelf --set-rpath $(LIB_RUNTIME_PATH) $$x ; done +install: install-strip install-headers install-tests: install - cd src && $(INSTALL) $(EMU_LUA_TEST_TO_BIN) $(LUA_INSTALL_PATH) - cd src && $(INSTALL) tests/test-merkle-tree-hash tests/test-machine-c-api $(BIN_INSTALL_PATH) + $(INSTALL_FILE) $(EMU_LUA_TEST_TO_BIN) $(LUA_INSTALL_PATH) + $(INSTALL_EXEC) $(EMU_TEST_TO_BIN) $(BIN_INSTALL_PATH) cat tools/template/cartesi-machine-tests.template | sed 's|ARG_LUA_PATH|$(LUA_RUNTIME_PATH)/?.lua|g;s|ARG_LUA_CPATH|$(LUA_RUNTIME_CPATH)/?.so|g;s|ARG_LUA_RUNTIME_PATH|$(LUA_RUNTIME_PATH)|g' > $(BIN_INSTALL_PATH)/cartesi-machine-tests cat tools/template/uarch-riscv-tests.template | sed 's|ARG_LUA_PATH|$(LUA_RUNTIME_PATH)/?.lua|g;s|ARG_LUA_CPATH|$(LUA_RUNTIME_CPATH)/?.so|g;s|ARG_LUA_RUNTIME_PATH|$(LUA_RUNTIME_PATH)|g' > $(BIN_INSTALL_PATH)/uarch-riscv-tests - cd $(LUA_INSTALL_PATH) && $(CHMOD_DATA) $(EMU_LUA_TEST_TO_BIN) - cd $(BIN_INSTALL_PATH) && $(CHMOD_EXEC) cartesi-machine-tests uarch-riscv-tests - patchelf --set-rpath $(LIB_RUNTIME_PATH) src/tests/test-merkle-tree-hash - patchelf --set-rpath $(LIB_RUNTIME_PATH) src/tests/test-machine-c-api - -install-emulator: $(BIN_INSTALL_PATH) $(LIB_INSTALL_PATH) $(LUA_INSTALL_CPATH)/cartesi $(LUA_INSTALL_PATH)/cartesi $(INC_INSTALL_PATH) $(IMAGES_INSTALL_PATH) - cd src && $(INSTALL) $(EMU_TO_BIN) $(BIN_INSTALL_PATH) - cd src && $(INSTALL) $(EMU_TO_LIB) $(LIB_INSTALL_PATH) - cd src && $(INSTALL) $(EMU_LUA_TO_BIN) $(LUA_INSTALL_PATH) - cd src && $(INSTALL) $(EMU_TO_LUA_CPATH) $(LUA_INSTALL_CPATH) - cd src && $(INSTALL) $(EMU_TO_LUA_CARTESI_CPATH) $(LUA_INSTALL_CPATH)/cartesi - cd src && $(INSTALL) $(EMU_TO_LUA_PATH) $(LUA_INSTALL_PATH)/cartesi - cat tools/template/cartesi-machine.template | sed 's|ARG_LUA_PATH|$(LUA_RUNTIME_PATH)/?.lua|g;s|ARG_LUA_CPATH|$(LUA_RUNTIME_CPATH)/?.so|g;s|ARG_INSTALL_PATH|$(IMAGES_RUNTIME_PATH)|g;s|ARG_LUA_RUNTIME_PATH|$(LUA_RUNTIME_PATH)|g' > $(BIN_INSTALL_PATH)/cartesi-machine - cat tools/template/cartesi-machine-stored-hash.template | sed 's|ARG_LUA_PATH|$(LUA_RUNTIME_PATH)/?.lua|g;s|ARG_LUA_CPATH|$(LUA_RUNTIME_CPATH)/?.so|g;s|ARG_LUA_RUNTIME_PATH|$(LUA_RUNTIME_PATH)|g' > $(BIN_INSTALL_PATH)/cartesi-machine-stored-hash - cat tools/template/rollup-memory-range.template | sed 's|ARG_LUA_PATH|$(LUA_RUNTIME_PATH)/?.lua|g;s|ARG_LUA_CPATH|$(LUA_RUNTIME_CPATH)/?.so|g;s|ARG_LUA_RUNTIME_PATH|$(LUA_RUNTIME_PATH)|g' > $(BIN_INSTALL_PATH)/rollup-memory-range - cd $(BIN_INSTALL_PATH) && $(CHMOD_EXEC) $(EMU_TO_BIN) cartesi-machine cartesi-machine-stored-hash rollup-memory-range - cd $(LIB_INSTALL_PATH) && ln -sf $(LIBCARTESI_SO_$(TARGET_OS)) $(LIBCARTESI_$(TARGET_OS)) - cd $(LIB_INSTALL_PATH) && ln -sf $(LIBCARTESI_SO_GRPC_$(TARGET_OS)) $(LIBCARTESI_GRPC_$(TARGET_OS)) - cd $(LUA_INSTALL_PATH) && $(CHMOD_DATA) $(EMU_LUA_TO_BIN) - $(INSTALL) $(EMU_TO_INC) $(INC_INSTALL_PATH) - $(INSTALL) tools/gdb $(SHARE_INSTALL_PATH)/gdb - cd $(LUA_INSTALL_CPATH) && $(CHMOD_EXEC) $(EMU_TO_LUA_CPATH) + $(CHMOD_EXEC) $(BIN_INSTALL_PATH)/cartesi-machine-tests $(BIN_INSTALL_PATH)/uarch-riscv-tests install-uarch: install $(UARCH_INSTALL_PATH) - $(INSTALL) uarch/$(UARCH_TO_SHARE) $(UARCH_INSTALL_PATH) - -install-strip: install-emulator - cd $(BIN_INSTALL_PATH) && $(STRIP_EXEC) $(EMU_TO_BIN) - cd $(LIB_INSTALL_PATH) && $(STRIP_EXEC) $(EMU_TO_LIB) - cd $(LUA_INSTALL_CPATH) && $(STRIP_EXEC) $(EMU_TO_LUA_CPATH) + $(INSTALL_FILE) uarch/$(UARCH_TO_SHARE) $(UARCH_INSTALL_PATH) -install: install-emulator install-strip $(INSTALL_PLAT) debian-package: install mkdir -p $(DESTDIR)/DEBIAN $(DOC_INSTALL_PATH) - $(INSTALL) COPYING $(DOC_INSTALL_PATH)/copyright + $(INSTALL_FILE) COPYING $(DOC_INSTALL_PATH)/copyright cat tools/template/control.template | sed 's|ARG_VERSION|$(MACHINE_EMULATOR_VERSION)|g;s|ARG_ARCH|$(DEB_ARCH)|g' > $(DESTDIR)/DEBIAN/control dpkg-deb -Zxz --root-owner-group --build $(DESTDIR) $(DEB_FILENAME) diff --git a/README.md b/README.md index b162582a8..94d160e97 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Obs: Please note that Apple Clang Version number does not follow upstream LLVM/C ``` sudo apt-get install build-essential wget git clang-tidy-15 clang-format-15 \ libboost1.81-dev libssl-dev \ - ca-certificates automake libtool patchelf pkg-config lua5.4 liblua5.4-dev \ + ca-certificates automake libtool pkg-config lua5.4 liblua5.4-dev \ libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \ luarocks diff --git a/src/Makefile b/src/Makefile index a4b0a1573..5861b7a5e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -52,13 +52,14 @@ endif SOLDFLAGS_Darwin:=-bundle -undefined dynamic_lookup CC_Darwin=clang CXX_Darwin=clang++ +AR_EXEC_Darwin=libtool -static INCS_Darwin= ifeq ($(TARGET_OS),Darwin) ifeq ($(MACOSX_DEPLOYMENT_TARGET),) export MACOSX_DEPLOYMENT_TARGET := $(shell sw_vers -productVersion | sed -r "s/([[:digit:]]+)\.([[:digit:]]+)\..+/\1.\2.0/") endif -SOLDFLAGS_Darwin+=-Wl,-rpath,$(CURDIR) +SOLDFLAGS_Darwin+= # Homebrew installation ifneq (,$(shell which brew)) BREW_PREFIX := $(shell brew --prefix) @@ -84,20 +85,18 @@ endif PTHREAD_LIB_Darwin:=-lpthread LIBCARTESI_Darwin=libcartesi-$(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR).dylib LIBCARTESI_LDFLAGS_Darwin=-dynamiclib -undefined dynamic_lookup -install_name '@rpath/$(LIBCARTESI_Darwin)' -LIBCARTESI_TESTS_LDFLAGS_Darwin=-Wl,-rpath,$(CURDIR) LIBCARTESI_GRPC_Darwin=libcartesi_grpc-$(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR).dylib LIBCARTESI_GRPC_LDFLAGS_Darwin=-dynamiclib -undefined dynamic_lookup -install_name '@rpath/$(LIBCARTESI_GRPC_Darwin)' -LIBCARTESI_GRPC_TESTS_LDFLAGS_Darwin=-Wl,-rpath,$(CURDIR) LIBCARTESI_JSONRPC_Darwin=libcartesi_jsonrpc-$(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR).dylib LIBCARTESI_JSONRPC_LDFLAGS_Darwin=-dynamiclib -undefined dynamic_lookup -install_name '@rpath/$(LIBCARTESI_JSONRPC_Darwin)' -LIBCARTESI_JSONRPC_TESTS_LDFLAGS_Darwin=-Wl,-rpath,$(CURDIR) -CARTESI_EXECUTABLE_LDFLAGS_Darwin=-Wl,-rpath,$(CURDIR) +CARTESI_EXECUTABLE_LDFLAGS_Darwin= PROFILE_DATA_Darwin=default.profdata # Linux specific setup SOLDFLAGS_Linux:=-shared -fPIC -pthread CC_Linux=gcc CXX_Linux=g++ +AR_EXEC_Linux=ar rcs INCS_Linux= PTHREAD_LIB_Linux:=-lpthread BOOST_INC_Linux:= @@ -106,19 +105,17 @@ GRPC_LIB_Linux:=$(shell pkg-config --libs grpc++) PROTOBUF_INC_Linux:=$(shell pkg-config --cflags-only-I protobuf) PROTOBUF_LIB_Linux:=$(shell pkg-config --libs protobuf) LIBCARTESI_Linux=libcartesi-$(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR).so -LIBCARTESI_LDFLAGS_Linux:=$(SOLDFLAGS_Linux) -LIBCARTESI_TESTS_LDFLAGS_Linux=-Wl,-rpath,'$$ORIGIN/..' +LIBCARTESI_LDFLAGS_Linux:=$(SOLDFLAGS_Linux) -Wl,-z,defs LIBCARTESI_GRPC_Linux=libcartesi_grpc-$(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR).so -LIBCARTESI_GRPC_LDFLAGS_Linux:=$(SOLDFLAGS_Linux) -LIBCARTESI_GRPC_TESTS_LDFLAGS_Linux=-Wl,-rpath,'$$ORIGIN/..' +LIBCARTESI_GRPC_LDFLAGS_Linux:=$(SOLDFLAGS_Linux) -Wl,-zdefs LIBCARTESI_JSONRPC_Linux=libcartesi_jsonrpc-$(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR).so -LIBCARTESI_JSONRPC_LDFLAGS_Linux:=$(SOLDFLAGS_Linux) -LIBCARTESI_JSONRPC_TESTS_LDFLAGS_Linux=-Wl,-rpath,'$$ORIGIN/..' -CARTESI_EXECUTABLE_LDFLAGS_Linux=-Wl,-rpath,'$$ORIGIN/' +LIBCARTESI_JSONRPC_LDFLAGS_Linux:=$(SOLDFLAGS_Linux) -Wl,-z,defs +CARTESI_EXECUTABLE_LDFLAGS_Linux= PROFILE_DATA_Linux= CC=$(CC_$(TARGET_OS)) CXX=$(CXX_$(TARGET_OS)) +AR_EXEC=$(AR_EXEC_$(TARGET_OS)) SOLDFLAGS:=$(SOLDFLAGS_$(TARGET_OS)) $(GCLDFLAGS) PTHREAD_LIB:=$(PTHREAD_LIB_$(TARGET_OS)) BOOST_INC:=$(BOOST_INC_$(TARGET_OS)) @@ -128,23 +125,26 @@ PROTOBUF_INC:=$(PROTOBUF_INC_$(TARGET_OS)) PROTOBUF_LIB:=$(PROTOBUF_LIB_$(TARGET_OS)) LIBCARTESI=$(LIBCARTESI_$(TARGET_OS)) LIBCARTESI_LDFLAGS=$(LIBCARTESI_LDFLAGS_$(TARGET_OS)) -LIBCARTESI_TESTS_LDFLAGS=$(LIBCARTESI_TESTS_LDFLAGS_$(TARGET_OS)) LIBCARTESI_LIB=-L. -lcartesi-$(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR) CARTESI_EXECUTABLE_LDFLAGS=$(CARTESI_EXECUTABLE_LDFLAGS_$(TARGET_OS)) LIBCARTESI_GRPC=$(LIBCARTESI_GRPC_$(TARGET_OS)) LIBCARTESI_GRPC_LDFLAGS=$(LIBCARTESI_GRPC_LDFLAGS_$(TARGET_OS)) -LIBCARTESI_GRPC_TESTS_LDFLAGS=$(LIBCARTESI_GRPC_TESTS_LDFLAGS_$(TARGET_OS)) LIBCARTESI_GRPC_LIB=-L. -lcartesi_grpc-$(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR) +LIBCARTESI_JSONRPC=$(LIBCARTESI_JSONRPC_$(TARGET_OS)) +LIBCARTESI_JSONRPC_LDFLAGS=$(LIBCARTESI_JSONRPC_LDFLAGS_$(TARGET_OS)) +LIBCARTESI_JSONRPC_LIB=-L. -lcartesi_jsonrpc-$(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR) + LIBCARTESI_LIBS:= LIBCARTESI_GRPC_LIBS:=$(GRPC_LIB) $(PROTOBUF_LIB) -LUACARTESI_LIBS:=$(LIBCARTESI_LIB) -LUACARTESI_GRPC_LIBS:=$(LIBCARTESI_LIB) $(LIBCARTESI_GRPC_LIB) -LUACARTESI_JSONRPC_LIBS:=$(LIBCARTESI_LIB) +LIBCARTESI_JSONRPC_LIBS:= +LUACARTESI_LIBS:= +LUACARTESI_GRPC_LIBS:=$(GRPC_LIB) $(PROTOBUF_LIB) +LUACARTESI_JSONRPC_LIBS:= REMOTE_CARTESI_MACHINE_LIBS:=$(GRPC_LIB) $(PROTOBUF_LIB) JSONRPC_REMOTE_CARTESI_MACHINE_LIBS:= -TEST_MACHINE_C_API_LIBS:=$(LIBCARTESI_LIB) $(LIBCARTESI_GRPC_LIB) $(PTHREAD_LIB) +TEST_MACHINE_C_API_LIBS:=$(GRPC_LIB) $(PROTOBUF_LIB) $(PTHREAD_LIB) HASH_LIBS:= #DEFS+= -DMT_ALL_DIRTY @@ -205,8 +205,6 @@ ifneq (,$(filter gcc,$(CC))) # This flag is usually enabled by default at -O3, # but we don't use -O3 because it enables some other flags that are not worth for the interpreter. OPTFLAGS+=-fgcse-after-reload -fpredictive-commoning -fsplit-paths -ftree-partial-pre -else ifneq (,$(filter emcc,$(CC))) -OPTFLAGS+=-O3 endif # Disable jump tables, because it degrades the instruction decoding performance in the interpret loop, # since it generates a memory indirection that has a high cost in opcode switches. @@ -301,7 +299,7 @@ CXXFLAGS+=$(MYCXXFLAGS) CFLAGS+=$(MYCFLAGS) LDFLAGS+=$(MYLDFLAGS) -all: luacartesi grpc hash c-api jsonrpc-remote-cartesi-machine +all: luacartesi libcartesi.a grpc hash c-api jsonrpc-remote-cartesi-machine .PHONY: all generate use clean test lint format format-lua check-format check-format-lua luacartesi grpc hash c-api compile_flags.txt @@ -329,19 +327,22 @@ LIBCARTESI_OBJS:= \ base64.o \ interpret.o \ virtual-machine.o \ - machine-c-api.o \ uarch-machine.o \ uarch-step.o \ - uarch-interpret.o + uarch-interpret.o \ + machine-c-api.o + +CARTESI_CLUA_OBJS:= \ + clua.o \ + clua-i-virtual-machine.o \ + clua-htif.o \ + clua-machine-util.o LUACARTESI_OBJS:= \ - sha3.o \ clua-cartesi.o \ - clua-i-virtual-machine.o \ clua-machine.o \ - clua-htif.o \ - clua-machine-util.o \ - clua.o + $(CARTESI_CLUA_OBJS) \ + $(LIBCARTESI_OBJS) PROTOBUF_GEN_OBJS:= \ versioning.pb.o \ @@ -353,41 +354,39 @@ GRPC_GEN_OBJS:= \ cartesi-machine-checkin.grpc.pb.o LIBCARTESI_GRPC_OBJS:= \ - sha3.o \ - machine-merkle-tree.o \ - pristine-merkle-tree.o \ - $(GRPC_GEN_OBJS) \ - $(PROTOBUF_GEN_OBJS) \ grpc-virtual-machine.o \ + grpc-machine-c-api.o \ protobuf-util.o \ - grpc-machine-c-api.o + $(GRPC_GEN_OBJS) \ + $(PROTOBUF_GEN_OBJS) \ + $(LIBCARTESI_OBJS) + +LIBCARTESI_JSONRPC_OBJS:= \ + jsonrpc-virtual-machine.o \ + jsonrpc-machine-c-api.o \ + mongoose.o \ + $(LIBCARTESI_OBJS) LUACARTESI_GRPC_OBJS:= \ - clua-i-virtual-machine.o \ - clua-htif.o \ - clua-machine-util.o \ clua-cartesi-grpc.o \ clua-grpc-machine.o \ - clua.o + $(CARTESI_CLUA_OBJS) \ + $(LIBCARTESI_GRPC_OBJS) LUACARTESI_JSONRPC_OBJS:= \ - clua-i-virtual-machine.o \ - clua-htif.o \ - clua-machine-util.o \ clua-cartesi-jsonrpc.o \ clua-jsonrpc-machine.o \ - json-util.o \ - base64.o \ - mongoose.o \ - jsonrpc-machine-c-api.o \ - jsonrpc-virtual-machine.o \ - clua.o + $(CARTESI_CLUA_OBJS) \ + $(LIBCARTESI_JSONRPC_OBJS) ifeq ($(gperf),yes) DEFS+=-DGPERF LIBCARTESI_LIBS+=-lprofiler LIBCARTESI_GRPC_LIBS+=-lprofiler +LIBCARTESI_JSONRPC_LIBS+=-lprofiler LUACARTESI_LIBS+=-lprofiler +LUACARTESI_GRPC_LIBS+=-lprofiler +LUACARTESI_JSONRPC_LIBS+=-lprofiler endif version: @@ -396,19 +395,25 @@ version: so-version: @echo $(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR) +libcartesi.a: $(LIBCARTESI_OBJS) + $(AR_EXEC) $@ $(LIBCARTESI_OBJS) + $(LIBCARTESI): $(LIBCARTESI_OBJS) $(CXX) $(LDFLAGS) $(LIBCARTESI_LDFLAGS) -o $@ $(LIBCARTESI_OBJS) $(LIBCARTESI_LIBS) -$(LIBCARTESI_GRPC): $(LIBCARTESI_GRPC_OBJS) $(LIBCARTESI) - $(CXX) $(LDFLAGS) $(LIBCARTESI_GRPC_LDFLAGS) -o $@ $(LIBCARTESI_GRPC_OBJS) $(LIBCARTESI_GRPC_LIBS) $(LIBCARTESI_LIB) +$(LIBCARTESI_GRPC): $(LIBCARTESI_GRPC_OBJS) + $(CXX) $(LDFLAGS) $(LIBCARTESI_GRPC_LDFLAGS) -o $@ $(LIBCARTESI_GRPC_OBJS) $(LIBCARTESI_GRPC_LIBS) -cartesi.so: $(LUACARTESI_OBJS) $(LIBCARTESI) +$(LIBCARTESI_JSONRPC): $(LIBCARTESI_JSONRPC_OBJS) + $(CXX) $(LDFLAGS) $(LIBCARTESI_JSONRPC_LDFLAGS) -o $@ $(LIBCARTESI_JSONRPC_OBJS) $(LIBCARTESI_JSONRPC_LIBS) + +cartesi.so: $(LUACARTESI_OBJS) $(CXX) $(LDFLAGS) $(SOLDFLAGS) -o $@ $(LUACARTESI_OBJS) $(LUACARTESI_LIBS) -cartesi/grpc.so: $(LUACARTESI_GRPC_OBJS) $(LIBCARTESI_GRPC) $(LIBCARTESI) +cartesi/grpc.so: $(LUACARTESI_GRPC_OBJS) $(CXX) $(LDFLAGS) $(SOLDFLAGS) -o $@ $(LUACARTESI_GRPC_OBJS) $(LUACARTESI_GRPC_LIBS) -cartesi/jsonrpc.so: $(LUACARTESI_JSONRPC_OBJS) $(LIBCARTESI_JSONRPC) $(LIBCARTESI) +cartesi/jsonrpc.so: $(LUACARTESI_JSONRPC_OBJS) $(CXX) $(LDFLAGS) $(SOLDFLAGS) -o $@ $(LUACARTESI_JSONRPC_OBJS) $(LUACARTESI_JSONRPC_LIBS) test: luacartesi @@ -527,7 +532,7 @@ jsonrpc: cartesi/jsonrpc.so jsonrpc-remote-cartesi-machine hash: merkle-tree-hash tests/test-merkle-tree-hash -c-api: $(LIBCARTESI) $(LIBCARTESI_GRPC) tests/test-machine-c-api +c-api: $(LIBCARTESI) $(LIBCARTESI_GRPC) $(LIBCARTESI_JSONRPC) tests/test-machine-c-api MERKLE_TREE_HASH_OBJS:= \ sha3.o \ @@ -545,9 +550,8 @@ TEST_MERKLE_TREE_HASH_OBJS:= \ TEST_MACHINE_C_API_OBJS:= \ test-machine-c-api.o \ - sha3.o \ back-merkle-tree.o \ - pristine-merkle-tree.o + $(LIBCARTESI_GRPC_OBJS) PROTO_OBJS:= \ $(PROTOBUF_GEN_OBJS) \ @@ -558,67 +562,19 @@ $(PROTO_OBJS): CXXFLAGS += -Wno-zero-length-array -Wno-unused-parameter -Wno-de PROTO_SOURCES:=$(PROTO_OBJS:.o=.cc) REMOTE_CARTESI_MACHINE_OBJS:= \ - $(GRPC_GEN_OBJS) \ - $(PROTOBUF_GEN_OBJS) \ - slog.o \ remote-machine.o \ protobuf-util.o \ - pma-driver.o \ - clint.o \ - clint-factory.o \ - dtb.o \ - tty.o \ - htif.o \ - htif-factory.o \ - shadow-state.o \ - shadow-state-factory.o \ - shadow-pmas.o \ - shadow-pmas-factory.o \ - shadow-tlb.o \ - shadow-tlb-factory.o \ - sha3.o \ - machine-merkle-tree.o \ - pristine-merkle-tree.o \ - pma.o \ - machine.o \ - machine-config.o \ - json-util.o \ - base64.o \ - interpret.o \ - uarch-machine.o \ - uarch-step.o \ - uarch-interpret.o + slog.o \ + $(GRPC_GEN_OBJS) \ + $(PROTOBUF_GEN_OBJS) \ + $(LIBCARTESI_OBJS) JSONRPC_REMOTE_CARTESI_MACHINE_OBJS:= \ - slog.o \ jsonrpc-remote-machine.o \ jsonrpc-discover.o \ mongoose.o \ - pma-driver.o \ - clint.o \ - clint-factory.o \ - dtb.o \ - tty.o \ - htif.o \ - htif-factory.o \ - json-util.o \ - base64.o \ - shadow-state.o \ - shadow-state-factory.o \ - shadow-pmas.o \ - shadow-pmas-factory.o \ - shadow-tlb.o \ - shadow-tlb-factory.o \ - sha3.o \ - machine-merkle-tree.o \ - pristine-merkle-tree.o \ - pma.o \ - machine.o \ - machine-config.o \ - interpret.o \ - uarch-machine.o \ - uarch-step.o \ - uarch-interpret.o + slog.o \ + $(LIBCARTESI_OBJS) CYCLE_PERIOD ?= 13 HASH_DIR = hashes/$(CYCLE_PERIOD) @@ -697,7 +653,7 @@ jsonrpc-remote-cartesi-machine: $(JSONRPC_REMOTE_CARTESI_MACHINE_OBJS) remote-cartesi-machine: CXXFLAGS := $(PROTOBUF_INC) $(GRPC_INC) $(CXXFLAGS) -tests/test-machine-c-api: $(TEST_MACHINE_C_API_OBJS) $(LIBCARTESI) $(LIBCARTESI_GRPC) +tests/test-machine-c-api: $(TEST_MACHINE_C_API_OBJS) $(CXX) $(LDFLAGS) $(CARTESI_EXECUTABLE_LDFLAGS) -o $@ $(TEST_MACHINE_C_API_OBJS) $(TEST_MACHINE_C_API_LIBS) .PRECIOUS: %.grpc.pb.cc %.grpc.pb.h %.pb.cc %.pb.h @@ -763,7 +719,7 @@ clean-objs: @rm -f *.o *.d clean-libcartesi: clean-objs - @rm -f *.so *.a cartesi/*.so cartesi/*.a + @rm -f *.so *.a cartesi/*.so clean-executables: @rm -f jsonrpc-remote-cartesi-machine remote-cartesi-machine merkle-tree-hash