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

Fix homebrew build #149

Merged
merged 3 commits into from
Oct 26, 2023
Merged
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
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Changed stored machine configs from protobuf to JSON
- Build device tree automatically into machine's ROM, eliminating the need for a ROM image
- Enabled rollup by default
- Updated libboost version to 1.81
- Removed remote-cartesi-machine-proxy

## [0.15.2] - 2023-08-21
### Changed

- Made emulator patch version not impact machine root hash
- Enabled line buffering for machine stdout in non-interactive mode
- Changed stored machine configs from protobuf to JSON
- Build device tree automatically into machine's ROM, eliminating the need for a ROM image

## [0.15.1] - 2023-08-17
### Fixed
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ ARG SANITIZE=no
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 \
libreadline-dev libboost-coroutine-dev libboost-context-dev \
libboost-filesystem-dev libssl-dev libc-ares-dev zlib1g-dev \
libreadline-dev libboost-context1.81-dev \
libboost-filesystem1.81-dev libssl-dev libc-ares-dev zlib1g-dev \
ca-certificates automake libtool patchelf cmake pkg-config lua5.4 liblua5.4-dev \
libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \
luarocks libb64-dev libcrypto++-dev nlohmann-json3-dev && \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CHMOD_EXEC= chmod 0755
CHMOD_DATA= chmod 0644
STRIP_EXEC= strip -x

EMU_TO_BIN= jsonrpc-remote-cartesi-machine remote-cartesi-machine remote-cartesi-machine-proxy merkle-tree-hash
EMU_TO_BIN= jsonrpc-remote-cartesi-machine remote-cartesi-machine merkle-tree-hash
EMU_TO_LIB= $(LIBCARTESI_SO_$(UNAME)) $(LIBCARTESI_SO_GRPC_$(UNAME))
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
Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Docker targets:
- GRPC >= 1.45.0
- Lua >= 5.4.4
- b64 >= 1.2.1
- Boost >= 1.71
- Boost >= 1.81
- nlohmann JSON >= 3.10

Obs: Please note that Apple Clang Version number does not follow upstream LLVM/Clang.
Expand All @@ -34,8 +34,8 @@ Obs: Please note that Apple Clang Version number does not follow upstream LLVM/C

```
apt-get install build-essential wget git clang-tidy-15 clang-format-15 \
libreadline-dev libboost-coroutine-dev libboost-context-dev \
libboost-filesystem-dev libssl-dev libc-ares-dev zlib1g-dev \
libreadline-dev libboost-context1.81-dev \
libboost-filesystem1.81-dev libssl-dev libc-ares-dev zlib1g-dev \
ca-certificates automake libtool patchelf cmake pkg-config lua5.4 liblua5.4-dev \
libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \
luarocks libb64-dev libcrypto++-dev nlohmann-json3-dev
Expand All @@ -61,7 +61,7 @@ sudo luarocks install --lua-version=5.4 luaposix

##### Homebrew
```
brew install llvm@12 automake boost libomp wget cmake pkg-config grpc zlib openssl [email protected] libb64 nlohmann-json luarocks
brew install llvm@15 automake boost libomp wget cmake cryptopp pkg-config grpc zlib openssl [email protected] libb64 nlohmann-json luarocks
luarocks --lua-dir=$(brew --prefix)/opt/[email protected] install lpeg
luarocks --lua-dir=$(brew --prefix)/opt/[email protected] install dkjson
luarocks --lua-dir=$(brew --prefix)/opt/[email protected] install luasocket
Expand All @@ -71,10 +71,6 @@ luarocks --lua-dir=$(brew --prefix)/opt/[email protected] install luaposix

For emulator scripts to work it is expected that `lua5.4` binary is available in the system PATH. If operating system/package manager that you are using provides only `lua` or lua binary named in a different way (e.g. on `Homebrew`), please create symbolic link or alias `lua5.4`.

###### libcryptopp
Homebrew does not have a formula for this library on the official repository, at the time of this writing.
More information on how to obtain this library can be found on https://www.cryptopp.com

### Build

```bash
Expand Down
86 changes: 41 additions & 45 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,36 @@ export MACOSX_DEPLOYMENT_TARGET := $(shell sw_vers -productVersion | sed -r "s/
endif
SOLDFLAGS_Darwin+=-Wl,-rpath,$(BUILDDIR)/lib -Wl,-rpath,$(CURDIR)
# Homebrew installation
ifneq (,$(wildcard /usr/local/opt/boost/lib))
BOOST_LIB_DIR_Darwin=-L/usr/local/opt/boost/lib
BOOST_INC_Darwin=-I/usr/local/opt/boost/include
CRYPTOPP_LIB_Darwin:=-L/usr/local/opt/cryptopp/lib -lcryptopp
CRYPTOPP_INC_Darwin:=-I/usr/local/opt/cryptopp/include
NLOHMANN_JSON_INC_Darwin:=-I/usr/local/opt/nlohmann-json/include
B64_LIB_Darwin:=-L/usr/local/opt/libb64/lib -lb64
B64_INC_Darwin:=-I/usr/local/opt/libb64/include
GRPC_INC_Darwin=-I/usr/local/opt/gprc/include
GRPC_LIB_Darwin=-L/usr/local/opt/grpc/lib -lgrpc++ -lgrpc -lgpr -lprotobuf -lpthread -labsl_synchronization
PROTOBUF_LIB_Darwin:=-L/usr/local/opt/protobuf/lib -lprotobuf -lpthread
else # Macports installation
BOOST_LIB_DIR_Darwin=-L/opt/local/lib
BOOST_INC_Darwin=-I/opt/local/include
CRYPTOPP_LIB_Darwin:=-L/opt/local/lib -lcryptopp
CRYPTOPP_INC_Darwin:=-I/opt/local/include
B64_LIB_Darwin:=-L/opt/local/lib -lb64
B64_INC_Darwin:=-I/opt/local/include
GRPC_INC_Darwin=-I/opt/local/include
GRPC_LIB_Darwin=-L/opt/local/lib -lgrpc++ -lgrpc -lgpr -lprotobuf -lpthread -labsl_synchronization
PROTOBUF_LIB_Darwin:=-L/opt/local/lib -lprotobuf -lpthread
ifneq (,$(shell which brew))
BREW_PREFIX := $(shell brew --prefix)
BOOST_LIB_DIR_Darwin=-L$(BREW_PREFIX)/lib
BOOST_INC_Darwin=-I$(BREW_PREFIX)/include
CRYPTOPP_LIB_Darwin:=-L$(BREW_PREFIX)/lib -lcryptopp
CRYPTOPP_INC_Darwin:=-I$(BREW_PREFIX)/include
NLOHMANN_JSON_INC_Darwin:=-I$(BREW_PREFIX)/include
B64_LIB_Darwin:=-L$(BREW_PREFIX)/lib -lb64
B64_INC_Darwin:=-I$(BREW_PREFIX)/include
GRPC_INC_Darwin:=$(shell pkg-config --cflags-only-I grpc++)
GRPC_LIB_Darwin:=$(shell pkg-config --libs grpc++)
PROTOBUF_INC_Darwin:=$(shell pkg-config --cflags-only-I protobuf)
PROTOBUF_LIB_Darwin:=$(shell pkg-config --libs protobuf)
else ifneq (,$(shell which port)) # Macports installation
PORT_PREFIX := /opt/local
BOOST_LIB_DIR_Darwin=-L$(PORT_PREFIX)/libexec/boost/1.81/lib
BOOST_INC_Darwin=-I$(PORT_PREFIX)/libexec/boost/1.81/include
CRYPTOPP_LIB_Darwin:=-L$(PORT_PREFIX)/lib -lcryptopp
CRYPTOPP_INC_Darwin:=-I$(PORT_PREFIX)/include
B64_LIB_Darwin:=-L$(PORT_PREFIX)/lib -lb64
B64_INC_Darwin:=-I$(PORT_PREFIX)/include
GRPC_INC_Darwin:=-I$(PORT_PREFIX)/include
GRPC_LIB_Darwin=-L$(PORT_PREFIX)/lib -lgrpc++ -lgrpc -lgpr -lprotobuf -lpthread -labsl_synchronization
PROTOBUF_INC_Darwin:=-I$(PORT_PREFIX)/include
PROTOBUF_LIB_Darwin:=-L$(PORT_PREFIX)/lib -lprotobuf -lpthread
else
$(error Neither Homebrew nor MacPorts is installed)
endif
endif

BOOST_CORO_LIB_Darwin:=$(BOOST_LIB_DIR_Darwin) -lboost_coroutine-mt -lboost_context-mt
BOOST_FILESYSTEM_LIB_Darwin:=$(BOOST_LIB_DIR_Darwin) -lboost_system-mt -lboost_filesystem-mt
BOOST_PROCESS_LIB_Darwin:=-lpthread
LIBCARTESI_Darwin=libcartesi-$(EMULATOR_VERSION_MAJOR).$(EMULATOR_VERSION_MINOR).dylib
Expand All @@ -106,17 +111,17 @@ CC_Linux=gcc
CXX_Linux=g++
INCS_Linux=
FS_LIB_Linux=-lstdc++fs
BOOST_CORO_LIB_Linux:=-lboost_coroutine -lboost_context
BOOST_FILESYSTEM_LIB_Linux:=-lboost_system -lboost_filesystem
BOOST_PROCESS_LIB_Linux:=-lpthread
BOOST_INC_Linux=
B64_LIB_Linux:=-lb64
B64_INC_Linux:=
CRYPTOPP_LIB_Linux:=-lcryptopp
CRYPTOPP_INC_Linux:=
GRPC_INC_Linux:=
GRPC_LIB_Linux:=-lgrpc++ -lgrpc -lgpr -lprotobuf -lpthread -labsl_synchronization
PROTOBUF_LIB_Linux:=-lprotobuf -lpthread
GRPC_INC_Linux:=$(shell pkg-config --cflags-only-I grpc++)
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/..'
Expand All @@ -126,13 +131,12 @@ LIBCARTESI_GRPC_TESTS_LDFLAGS_Linux=-Wl,-rpath,'$$ORIGIN/..'
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/' -Wl,--copy-dt-needed-entries
CARTESI_EXECUTABLE_LDFLAGS_Linux=-Wl,-rpath,'$$ORIGIN/'
PROFILE_DATA_Linux=

CC=$(CC_$(UNAME))
CXX=$(CXX_$(UNAME))
SOLDFLAGS:=$(SOLDFLAGS_$(UNAME)) $(GCLDFLAGS)
BOOST_CORO_LIB=$(BOOST_CORO_LIB_$(UNAME))
BOOST_PROCESS_LIB=$(BOOST_PROCESS_LIB_$(UNAME))
BOOST_FILESYSTEM_LIB=$(BOOST_FILESYSTEM_LIB_$(UNAME))
BOOST_INC=$(BOOST_INC_$(UNAME))
Expand All @@ -142,9 +146,10 @@ CRYPTOPP_LIB=$(CRYPTOPP_LIB_$(UNAME))
CRYPTOPP_INC=$(CRYPTOPP_INC_$(UNAME))
NLOHMANN_JSON_INC=$(NLOHMANN_JSON_INC_$(UNAME))
MONGOOSE_INC=-I$(BUILDDIR)/include
GRPC_LIB=$(GRPC_LIB_$(UNAME))
GRPC_INC=$(GRPC_INC_$(UNAME))
PROTOBUF_LIB=$(PROTOBUF_LIB_$(UNAME))
GRPC_INC:=$(GRPC_INC_$(UNAME))
GRPC_LIB:=$(GRPC_LIB_$(UNAME))
PROTOBUF_INC:=$(PROTOBUF_INC_$(UNAME))
PROTOBUF_LIB:=$(PROTOBUF_LIB_$(UNAME))
LIBCARTESI=$(LIBCARTESI_$(UNAME))
LIBCARTESI_LDFLAGS=$(LIBCARTESI_LDFLAGS_$(UNAME))
LIBCARTESI_TESTS_LDFLAGS=$(LIBCARTESI_TESTS_LDFLAGS_$(UNAME))
Expand All @@ -163,7 +168,6 @@ LUACARTESI_GRPC_LIBS:=$(LIBCARTESI_LIB) $(CRYPTOPP_LIB) $(LIBCARTESI_GRPC_LIB)
LUACARTESI_JSONRPC_LIBS:=$(LIBCARTESI_LIB) $(CRYPTOPP_LIB) $(B64_LIB)
REMOTE_CARTESI_MACHINE_LIBS:=$(CRYPTOPP_LIB) $(GRPC_LIB) $(PROTOBUF_LIB) $(B64_LIB)
JSONRPC_REMOTE_CARTESI_MACHINE_LIBS:=$(CRYPTOPP_LIB) $(B64_LIB)
REMOTE_CARTESI_MACHINE_PROXY_LIBS:=$(CRYPTOPP_LIB) $(GRPC_LIB) $(PROTOBUF_LIB) $(BOOST_CORO_LIB) -ldl
TEST_MACHINE_C_API_LIBS:=$(LIBCARTESI_LIB) $(CRYPTOPP_LIB) $(LIBCARTESI_GRPC_LIB) $(BOOST_PROCESS_LIB) $(BOOST_FILESYSTEM_LIB) $(B64_LIB)
HASH_LIBS:=$(CRYPTOPP_LIB)

Expand All @@ -173,7 +177,7 @@ WARNS=-W -Wall -pedantic

# Place our include directories before the system's
INCS=-I../lib/machine-emulator-defines -I../third-party/llvm-flang-uint128 \
$(LUA_INC) $(CRYPTOPP_INC) $(NLOHMANN_JSON_INC) $(MONGOOSE_INC) $(B64_INC) $(BOOST_INC) $(GRPC_INC) $(INCS_$(UNAME))
$(LUA_INC) $(CRYPTOPP_INC) $(NLOHMANN_JSON_INC) $(MONGOOSE_INC) $(B64_INC) $(BOOST_INC) $(PROTOBUF_INC) $(GRPC_INC) $(INCS_$(UNAME))

ifeq ($(dump),yes)
#DEFS+=-DDUMP_ILLEGAL_INSN_EXCEPTIONS
Expand Down Expand Up @@ -523,7 +527,7 @@ luacartesi-pgo:
$(MAKE) --no-print-directory use
$(MAKE) clean-profile

grpc: cartesi/jsonrpc.so cartesi/grpc.so remote-cartesi-machine remote-cartesi-machine-proxy
grpc: cartesi/jsonrpc.so cartesi/grpc.so remote-cartesi-machine

jsonrpc: cartesi/jsonrpc.so jsonrpc-remote-cartesi-machine

Expand Down Expand Up @@ -556,11 +560,6 @@ $(PROTO_OBJS): CXXFLAGS += -Wno-zero-length-array -Wno-unused-parameter -Wno-de

PROTO_SOURCES:=$(PROTO_OBJS:.o=.cc)

REMOTE_CARTESI_MACHINE_PROXY_OBJS:= \
$(GRPC_GEN_OBJS) \
$(PROTOBUF_GEN_OBJS) \
remote-machine-proxy.o

REMOTE_CARTESI_MACHINE_OBJS:= \
$(GRPC_GEN_OBJS) \
$(PROTOBUF_GEN_OBJS) \
Expand Down Expand Up @@ -699,10 +698,7 @@ $(BUILDDIR)/lib/mongoose.o: CFLAGS := $(patsubst %-std=c99,%,$(CFLAGS))
jsonrpc-remote-cartesi-machine: $(JSONRPC_REMOTE_CARTESI_MACHINE_OBJS)
$(CXX) $(LDFLAGS) $(CARTESI_EXECUTABLE_LDFLAGS) -o $@ $(JSONRPC_REMOTE_CARTESI_MACHINE_OBJS) $(JSONRPC_REMOTE_CARTESI_MACHINE_LIBS)

remote-cartesi-machine-proxy: $(REMOTE_CARTESI_MACHINE_PROXY_OBJS)
$(CXX) $(LDFLAGS) $(CARTESI_EXECUTABLE_LDFLAGS) -o $@ $(REMOTE_CARTESI_MACHINE_PROXY_OBJS) $(REMOTE_CARTESI_MACHINE_PROXY_LIBS)

remote-cartesi-machine remote-cartesi-machine-proxy: CXXFLAGS := $(GRPC_INC) $(CXXFLAGS)
remote-cartesi-machine: CXXFLAGS := $(PROTOBUF_INC) $(GRPC_INC) $(CXXFLAGS)

tests/test-machine-c-api: $(TEST_MACHINE_C_API_OBJS) $(LIBCARTESI) $(LIBCARTESI_GRPC)
$(CXX) $(LDFLAGS) $(CARTESI_EXECUTABLE_LDFLAGS) -o $@ $(TEST_MACHINE_C_API_OBJS) $(TEST_MACHINE_C_API_LIBS)
Expand All @@ -717,7 +713,7 @@ tests/test-machine-c-api: $(TEST_MACHINE_C_API_OBJS) $(LIBCARTESI) $(LIBCARTESI_

protobuf-util.o: $(PROTOBUF_GEN_OBJS)

grpc-virtual-machine.o grpc-machine-c-api.o remote-machine.o proxy.o: $(GRPC_GEN_OBJS) $(PROTOBUF_GEN_OBJS)
grpc-virtual-machine.o grpc-machine-c-api.o remote-machine.o: $(GRPC_GEN_OBJS) $(PROTOBUF_GEN_OBJS)

machine-c-version.h: ../tools/template/machine-c-version.h.template
sed "s|EMULATOR_MARCHID|$(EMULATOR_MARCHID)|g;s|EMULATOR_VERSION_MAJOR|$(EMULATOR_VERSION_MAJOR)|g;s|EMULATOR_VERSION_MINOR|$(EMULATOR_VERSION_MINOR)|g;s|EMULATOR_VERSION_PATCH|$(EMULATOR_VERSION_PATCH)|g;s|EMULATOR_VERSION_LABEL|$(EMULATOR_VERSION_LABEL)|g" $< > $@
Expand Down Expand Up @@ -767,7 +763,7 @@ clean-libcartesi: clean-objs
@rm -f $(LIBCARTESI) $(LIBCARTESI_GRPC) cartesi.so cartesi/grpc.so cartesi/jsonrpc.so

clean-executables:
@rm -f jsonrpc-remote-cartesi-machine remote-cartesi-machine remote-cartesi-machine-proxy merkle-tree-hash
@rm -f jsonrpc-remote-cartesi-machine remote-cartesi-machine merkle-tree-hash

clean-tests:
@rm -f tests/test-merkle-tree-hash tests/test-machine-c-api
Expand Down
Loading