From 4df0918f8e0bcac75f91729872c3bf3bc329ee81 Mon Sep 17 00:00:00 2001 From: Ravin Perera <33562092+ravinsp@users.noreply.github.com> Date: Sat, 26 Sep 2020 18:20:07 +0530 Subject: [PATCH] Boost reference removal and dev setup script. (#127) * Removed unneeded boost library links. * Replaced boost string split with util function. * Added dev setup script. * Updated readme. --- CMakeLists.txt | 2 - README.md | 102 ++++++---------------------------------- dev-setup.sh | 116 ++++++++++++++++++++++++++++++++++++++++++++++ src/conf.cpp | 6 +-- src/pchheader.hpp | 1 - src/util.cpp | 12 +++++ src/util.hpp | 2 + 7 files changed, 147 insertions(+), 94 deletions(-) create mode 100755 dev-setup.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index e8edcfa5..639c988d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,8 +56,6 @@ target_link_libraries(hpcore libsodium.a pthread libblake3.so - libboost_system.a - libboost_thread.a libboost_stacktrace_backtrace.a backtrace ${CMAKE_DL_LIBS} # Needed for stacktrace support diff --git a/README.md b/README.md index b9194117..36e48e65 100644 --- a/README.md +++ b/README.md @@ -5,110 +5,36 @@ A C++ version of hotpocket designed for production envrionments, original prototype here: https://github.com/codetsunami/hotpocket - - ## Libraries * Crypto - Libsodium https://github.com/jedisct1/libsodium * Websockets - Server: [Websocketd (forked)](https://github.com/codetsunami/websocketd) | Client: [Websocat](https://github.com/vi/websocat) | Pipe: [netcat (OpenBSD)](https://man.openbsd.org/nc.1) * jsoncons (for JSON and BSON) - https://github.com/danielaparker/jsoncons * P2P Protocol - https://google.github.io/flatbuffers * Fuse filesystem - https://github.com/libfuse/libfuse -* Boost - https://www.boost.org * Reader Writer Queue - https://github.com/cameron314/readerwriterqueue * Concurrent Queue - https://github.com/cameron314/concurrentqueue +* Boost Stacktrace) - https://www.boost.org -## Steps to setup Hot Pocket (For Ubuntu/Debian) - -#### Install CMAKE 3.16 -1. Download and extract [cmake-3.16.0-rc3-Linux-x86_64.tar.gz](https://github.com/Kitware/CMake/releases/download/v3.16.0-rc3/cmake-3.16.0-rc3-Linux-x86_64.tar.gz) -2. Navigate into the extracted directory in a terminal. -3. Run `sudo cp -r bin/* /usr/local/bin/` -4. Run `sudo cp -r share/* /usr/local/share/` - -#### Install Libsodium -Instructions are based on [this](https://libsodium.gitbook.io/doc/installation). - -1. Download and extract Libsodium 1.0.18 from [here](https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz). -2. Navigate to the extracted libsodium directory in a terminal. -3. Run `./configure && make && make check` -4. Run `sudo make install` - -#### Install blake3 -1. Clone [blake3 library](https://github.com/BLAKE3-team/BLAKE3) repository -2. Navigate into the directory in a terminal. -3. `cd c` to navigate to the C implementation folder -4. `gcc -shared -fPIC -O3 -o libblake3.so blake3.c blake3_dispatch.c blake3_portable.c blake3_sse2_x86-64_unix.S blake3_sse41_x86-64_unix.S blake3_avx2_x86-64_unix.S blake3_avx512_x86-64_unix.S` -5. `sudo cp blake3.h /usr/local/include/` -6. `sudo cp libblake3.so /usr/local/lib/` - -#### Install Boost -Following Instructions are based on Boost [getting started](https://www.boost.org/doc/libs/1_71_0/more/getting_started/unix-variants.html#prepare-to-use-a-boost-library-binary) - -1. Download and extract boost 1.71 package from [here](https://www.boost.org/users/history/version_1_71_0.html). -2. Navigate to the extracted boost directory in a terminal. -3. Run `./bootstrap.sh` -4. Run `sudo ./b2 install` (This will compile and install boost libraries into your `/usr/local/lib`) - -#### Install jsoncons -1. Download and extract jsoncons v0.153.3 source from [here](https://github.com/danielaparker/jsoncons/archive/v0.153.3.zip). -2. Navigate to the extracted directory. -3. Run `sudo cp -r include/jsoncons /usr/local/include/` -4. Run `sudo mkdir -p /usr/local/include/jsoncons_ext/ && sudo cp -r include/jsoncons_ext/bson /usr/local/include/jsoncons_ext/` - -#### Install FlatBuffers -Instructions are based on [this](https://google.github.io/flatbuffers/). - -1. Clone the git respository into a new directory from [here](https://github.com/google/flatbuffers). -2. Build with CMake +## Setting up Hot Pocket development environment +Run the setup script located at the repo root (tested on Ubuntu 18.04). ``` -git clone https://github.com/google/flatbuffers.git -cd flatbuffers -cmake -G "Unix Makefiles" -make +./dev-setup.sh ``` -3. Run `sudo cp -r include/flatbuffers /usr/local/include/` -4. Run `sudo snap install flatbuffers --edge` -##### Compiling FlatBuffers message definitions +## Build Hot Pocket +1. Run `cmake .` (You only have to do this once) +1. Run `make` (Hot Pocket binary will be created as `./build/hpcore`) +1. Refer to the Wiki for instructions on running Hot Pocket. + +## FlatBuffers message definitions +If you update flatbuffers message definitions, you need to run the flatbuffers code generator to update the stubs. You need to have flatbuffers cli tool installed for this. + +`sudo snap install flatbuffers --edge` + Example: When you make a change to `p2pmsg_content_.fbc` defnition file, you need to run this: `flatc -o src/msg/fbuf/ --gen-mutable --cpp src/msg/fbuf/p2pmsg_content.fbs` -#### Install libfuse -1. `sudo apt-get install -y meson ninja-build pkg-config` -2. Download [libfuse 3.8](https://github.com/libfuse/libfuse/releases/download/fuse-3.8.0/fuse-3.8.0.tar.xz) and extract. -3. `mkdir build; cd build` -4. `meson .. && ninja` -6. `sudo ninja install` - -#### Install reader-writer queue -1. Download [readerwritequeue 1.0.3](https://github.com/cameron314/readerwriterqueue/archive/v1.0.3.zip) and extract. -2. `mkdir build; cd build` -3. `cmake ..` -4. `sudo make install` - -#### Install concurrent queue -1. Download [concurrentqueue 1.0.2](https://github.com/cameron314/concurrentqueue/archive/1.0.2.zip) and extract. -2. Run `sudo cp concurrentqueue.h /usr/local/include/` - -#### Install plog -1. Download and extract [plog1.1.5](https://github.com/SergiusTheBest/plog/archive/1.1.5.zip) -2. Navigate into the extracted directory in a terminal. -3. Run `sudo cp -r include/plog /usr/local/include/` - -#### Run ldconfig -`sudo ldconfig` - -This will update your linker library cache and avoid potential issues when running your compiled C++ program which links to newly installed libraries. - -#### Build and run Hot Pocket -1. Navigate to hotpocket repo root. -1. Run `cmake .` (You only have to do this once) -1. Run `make` (Hot Pocket binary will be created as `./build/hpcore`) -1. Refer to [Running Hot Pocket](https://github.com/HotPocketDev/core/wiki/Running-Hot-Pocket) in the Wiki. - -Refer to [Hot Pocket Wiki](https://github.com/HotPocketDev/core/wiki) for more info. - ## Code structure Code is divided into subsystems via namespaces. diff --git a/dev-setup.sh b/dev-setup.sh new file mode 100755 index 00000000..e064811b --- /dev/null +++ b/dev-setup.sh @@ -0,0 +1,116 @@ +#!/bin/bash +# Usage ./dev-setup.sh +# Hot Pocket build environment setup script. + +set -e # exit on error + +sudo apt-get update +sudo apt-get install -y build-essential + +workdir=~/hpcore-setup + +mkdir $workdir +pushd $workdir > /dev/null 2>&1 + +# CMAKE +cmake=cmake-3.16.0-rc3-Linux-x86_64 +wget https://github.com/Kitware/CMake/releases/download/v3.16.0-rc3/$cmake.tar.gz +tar -zxvf $cmake.tar.gz +sudo cp -r $cmake/bin/* /usr/local/bin/ +sudo cp -r $cmake/share/* /usr/local/share/ +rm $cmake.tar.gz && rm -r $cmake + +# Libsodium +wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz +tar -zxvf libsodium-1.0.18-stable.tar.gz +pushd libsodium-stable > /dev/null 2>&1 +./configure && make +sudo make install +popd > /dev/null 2>&1 +rm libsodium-1.0.18-stable.tar.gz && rm -r libsodium-stable + +# Blake3 +git clone https://github.com/BLAKE3-team/BLAKE3.git +pushd BLAKE3/c > /dev/null 2>&1 +gcc -shared -fPIC -O3 -o libblake3.so blake3.c blake3_dispatch.c blake3_portable.c \ + blake3_sse2_x86-64_unix.S blake3_sse41_x86-64_unix.S blake3_avx2_x86-64_unix.S \ + blake3_avx512_x86-64_unix.S +sudo cp blake3.h /usr/local/include/ +sudo cp libblake3.so /usr/local/lib/ +popd > /dev/null 2>&1 +sudo rm -r BLAKE3 + +# jsoncons +wget https://github.com/danielaparker/jsoncons/archive/v0.153.3.tar.gz +tar -zxvf v0.153.3.tar.gz +pushd jsoncons-0.153.3 > /dev/null 2>&1 +sudo cp -r include/jsoncons /usr/local/include/ +sudo mkdir -p /usr/local/include/jsoncons_ext/ +sudo cp -r include/jsoncons_ext/bson /usr/local/include/jsoncons_ext/ +popd > /dev/null 2>&1 +rm v0.153.3.tar.gz && rm -r jsoncons-0.153.3 + +# Flatbuffers +wget https://github.com/google/flatbuffers/archive/v1.12.0.tar.gz +tar -zxvf v1.12.0.tar.gz +pushd flatbuffers-1.12.0 > /dev/null 2>&1 +cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release +make +sudo cp -r include/flatbuffers /usr/local/include/ +popd > /dev/null 2>&1 +rm v1.12.0.tar.gz && rm -r flatbuffers-1.12.0 + +# libfuse +sudo apt-get install -y meson ninja-build pkg-config +wget https://github.com/libfuse/libfuse/archive/fuse-3.8.0.tar.gz +tar -zxvf fuse-3.8.0.tar.gz +pushd libfuse-fuse-3.8.0 > /dev/null 2>&1 +mkdir build +pushd build > /dev/null 2>&1 +meson .. && ninja +sudo ninja install +popd > /dev/null 2>&1 +popd > /dev/null 2>&1 +rm fuse-3.8.0.tar.gz && rm -r libfuse-fuse-3.8.0 + +# Reader-Writer queue +wget https://github.com/cameron314/readerwriterqueue/archive/v1.0.3.tar.gz +tar -zxvf v1.0.3.tar.gz +pushd readerwriterqueue-1.0.3 > /dev/null 2>&1 +mkdir build +pushd build > /dev/null 2>&1 +cmake .. +sudo make install +popd > /dev/null 2>&1 +popd > /dev/null 2>&1 +rm v1.0.3.tar.gz && rm -r readerwriterqueue-1.0.3 + +# Concurrent queue +wget https://github.com/cameron314/concurrentqueue/archive/1.0.2.tar.gz +tar -zxvf 1.0.2.tar.gz +pushd concurrentqueue-1.0.2 > /dev/null 2>&1 +sudo cp concurrentqueue.h /usr/local/include/ +popd > /dev/null 2>&1 +rm 1.0.2.tar.gz && rm -r concurrentqueue-1.0.2 + +# Plog +wget https://github.com/SergiusTheBest/plog/archive/1.1.5.tar.gz +tar -zxvf 1.1.5.tar.gz +pushd plog-1.1.5 > /dev/null 2>&1 +sudo cp -r include/plog /usr/local/include/ +popd > /dev/null 2>&1 +rm 1.1.5.tar.gz && rm -r plog-1.1.5 + +# Boost stacktrace +sudo apt-get install -y libboost-stacktrace-dev + +# Update linker library cache. +sudo ldconfig + +# Pop workdir +popd > /dev/null 2>&1 +rm -r $workdir + +# Build Hot Pocket +cmake . +make \ No newline at end of file diff --git a/src/conf.cpp b/src/conf.cpp index 03e841ba..ad97fd48 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -223,12 +223,12 @@ namespace conf // Populate runtime contract execution args. if (!cfg.binargs.empty()) - boost::split(cfg.runtime_binexec_args, cfg.binargs, boost::is_any_of(" ")); + util::split_string(cfg.runtime_binexec_args, cfg.binargs, " "); cfg.runtime_binexec_args.insert(cfg.runtime_binexec_args.begin(), (cfg.binary[0] == '/' ? cfg.binary : util::realpath(ctx.contract_dir + "/bin/" + cfg.binary))); // Populate runtime app bill args. if (!cfg.appbillargs.empty()) - boost::split(cfg.runtime_appbill_args, cfg.appbillargs, boost::is_any_of(" ")); + util::split_string(cfg.runtime_appbill_args, cfg.appbillargs, " "); cfg.runtime_appbill_args.insert(cfg.runtime_appbill_args.begin(), (cfg.appbill[0] == '/' ? cfg.appbill : util::realpath(ctx.contract_dir + "/bin/" + cfg.appbill))); @@ -246,7 +246,7 @@ namespace conf { const char *ipport_concat = v.as(); // Split the address:port text into two - boost::split(splitted_peers, ipport_concat, boost::is_any_of(":")); + util::split_string(splitted_peers, ipport_concat, ":"); if (splitted_peers.size() == 2) { // Push the peer address and the port to peers set diff --git a/src/pchheader.hpp b/src/pchheader.hpp index 1cc89610..49b4fcde 100644 --- a/src/pchheader.hpp +++ b/src/pchheader.hpp @@ -4,7 +4,6 @@ // Enable boost strack trace. #define BOOST_STACKTRACE_USE_BACKTRACE -#include #include #include #include diff --git a/src/util.cpp b/src/util.cpp index f28f63c3..e6eb64fa 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -363,4 +363,16 @@ namespace util return remove(path.data()); } + void split_string(std::vector &collection, std::string_view str, std::string_view delimeter) + { + size_t start = 0U; + size_t end = str.find(delimeter); + while (end != std::string::npos) + { + collection.push_back(std::string(str.substr(start, end - start))); + start = end + delimeter.length(); + end = str.find(delimeter, start); + } + } + } // namespace util diff --git a/src/util.hpp b/src/util.hpp index e9236ac7..00ee11bb 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -108,6 +108,8 @@ namespace util int remove_file(std::string_view path); + void split_string(std::vector &collection, std::string_view str, std::string_view delimeter); + } // namespace util #endif