Skip to content

Commit 7b8ede4

Browse files
authored
Merge pull request #134 from AppLayerLabs/deps_rev
Automate project dependencies & General optimizations
2 parents 0b1d354 + f700212 commit 7b8ede4

File tree

189 files changed

+4762
-5083
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+4762
-5083
lines changed

.github/workflows/c-cpp.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ jobs:
2323
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
2424
steps:
2525
- name: Clone the repository
26-
run: git clone https://github.com/${{ github.repository }} ${{ env.TARGET_DIR}} || true
26+
run: git clone https://github.com/${{github.repository}} ${{env.TARGET_DIR}} || true
2727
- name: Sync with remote repository
2828
run: git -C ${{env.TARGET_DIR}} fetch
2929
- name: Checkout to current branch
3030
run: git -C ${{env.TARGET_DIR}} checkout ${{env.BRANCH_NAME}}
31+
- name: Set user.email
32+
run: git -C ${{env.TARGET_DIR}} config --global user.email "github-actions[bot]@users.noreply.github.com"
33+
- name: Set user.name
34+
run: git -C ${{env.TARGET_DIR}} config --global user.name "github-actions"
3135
- name: Update local repository
3236
run: git -C ${{env.TARGET_DIR}} pull
3337
- name: Build the container
@@ -36,7 +40,7 @@ jobs:
3640
run: ./scripts/auto.sh -s bdk stop
3741
- name: Restart the container
3842
run: ./scripts/auto.sh -s bdk up
39-
- name: Clean previos build (if any)
43+
- name: Clean previous build (if there is one)
4044
run: ./scripts/auto.sh -s bdk exec 'make -C build clean' || true
4145
- name: Configure MOLD linker
4246
run: ./scripts/auto.sh -s bdk exec 'cmake -S . -B build

CMakeLists.txt

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
1616
cmake_policy(SET CMP0135 NEW)
1717
endif()
1818

19+
# TODO: avoid FindBoost deprecation message in CMake 3.30+ (cmake --help-policy CMP0167)
20+
1921
# Project data
2022
project(bdk VERSION 0.2.0 DESCRIPTION "AppLayer Blockchain Development Kit")
2123
set(CMAKE_CXX_STANDARD 23)
@@ -59,8 +61,8 @@ set(BUILD_DISCOVERY ON CACHE BOOL "Build helper discovery node program")
5961
set(BUILD_TOOLS OFF CACHE BOOL "Build tools related to subnet")
6062
set(BUILD_TESTNET OFF CACHE BOOL "Build the project for testnet")
6163
set(BUILD_BENCHMARK OFF CACHE BOOL "Build with the benchmark tests")
62-
set(USE_LINT OFF CACHE BOOL "Run linter on compile (clang-tidy)")
6364
set(BUILD_VARIABLES_TESTS ON CACHE BOOL "Build tests for SafeVar (Contract variables)")
65+
set(USE_LINT OFF CACHE BOOL "Run linter on compile (clang-tidy)")
6466
if(USE_LINT)
6567
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-header-filter=.;-checks=-*,abseil-*,boost-*,bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,hicpp-*,misc-*,modernize-*,performance-*,portability-*,readability-*")
6668
endif()
@@ -79,6 +81,9 @@ message(STATUS "Find libs with suffix: ${CMAKE_FIND_LIBRARY_SUFFIXES}")
7981
message("Building tests: ${BUILD_TESTS}")
8082
message("Building Discovery Node: ${BUILD_DISCOVERY}")
8183
message("Building tools: ${BUILD_TOOLS}")
84+
message("Building testnet: ${BUILD_TESTNET}")
85+
message("Building benchmark tests: ${BUILD_BENCHMARK}")
86+
message("Building SafeVar tests: ${BUILD_VARIABLES_TESTS}")
8287
message("Using lint: ${USE_LINT}")
8388

8489
cable_add_buildinfo_library(PROJECT_NAME bdk)
@@ -89,21 +94,22 @@ set(OPENSSL_USE_STATIC_LIBS ON)
8994
set(Protobuf_USE_STATIC_LIBS ON)
9095

9196
# Find system packages (built-in)
92-
find_package(Threads)
9397
find_package(Boost 1.83.0 REQUIRED COMPONENTS chrono filesystem program_options system thread nowide)
9498
find_package(OpenSSL 1.1.1 REQUIRED)
95-
find_package(ZLIB REQUIRED)
99+
find_package(Protobuf REQUIRED) # TODO: not used yet but will be, keep it for now
100+
find_package(Threads)
96101

97102
# Find system packages (custom)
103+
find_package(Cares REQUIRED) # TODO: not used yet but will be, keep it for now
98104
find_package(CryptoPP 8.2.0 REQUIRED)
105+
find_package(Ethash REQUIRED)
106+
find_package(Evmc REQUIRED)
107+
find_package(Evmone REQUIRED)
108+
find_package(GRPC REQUIRED) # TODO: not used yet but will be, keep it for now
109+
find_package(Keccak REQUIRED)
99110
find_package(Scrypt REQUIRED)
100-
101-
# Add external modules
102-
include(cmake/ProjectEthash.cmake) # Ethash
103-
include(cmake/ProjectSecp256k1.cmake) # Bitcoin core fast implementation
104-
include(cmake/ProjectSpeedb.cmake) # Speedb (Level/RocksDB drop-in replacement)
105-
include(cmake/ProjectEVMOne.cmake) # EVMOne (EVMOne + EVMC)
106-
111+
find_package(Secp256k1 REQUIRED)
112+
find_package(Speedb REQUIRED)
107113

108114
# Add catch2 as a library
109115
add_library(catch2
@@ -141,21 +147,21 @@ add_subdirectory(src/utils)
141147
add_subdirectory(tests)
142148

143149
add_library(bdk_lib STATIC
144-
${UTILS_HEADERS}
145-
${UTILS_SOURCES}
146-
${CONTRACT_HEADERS}
147-
${CONTRACT_SOURCES}
148-
${CORE_HEADERS}
149-
${CORE_SOURCES}
150-
${NET_HEADERS}
151-
${NET_SOURCES}
150+
${UTILS_HEADERS} ${UTILS_SOURCES} ${CONTRACT_HEADERS} ${CONTRACT_SOURCES}
151+
${CORE_HEADERS} ${CORE_SOURCES} ${NET_HEADERS} ${NET_SOURCES}
152152
)
153153

154-
target_include_directories(bdk_lib PRIVATE ${CMAKE_SOURCE_DIR}/include ${OPENSSL_INCLUDE_DIR})
154+
target_include_directories(bdk_lib PRIVATE
155+
${CMAKE_SOURCE_DIR}/include ${OPENSSL_INCLUDE_DIR} ${ETHASH_INCLUDE_DIR} ${KECCAK_INCLUDE_DIR}
156+
${EVMC_INCLUDE_DIR} ${EVMONE_INCLUDE_DIR} ${SPEEDB_INCLUDE_DIR} ${SECP256K1_INCLUDE_DIR}
157+
)
155158

156-
target_link_libraries(bdk_lib PRIVATE EvmcInstructions EvmcLoader EvmcTooling Evmone
157-
${CRYPTOPP_LIBRARIES} ${SCRYPT_LIBRARY} Secp256k1 Ethash ${ETHASH_BYPRODUCTS}
158-
Speedb ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES})
159+
target_link_libraries(bdk_lib PRIVATE
160+
${EVMC_INSTRUCTIONS_LIBRARY} ${EVMC_LOADER_LIBRARY} ${EVMONE_LIBRARY}
161+
${CRYPTOPP_LIBRARIES} ${SCRYPT_LIBRARY} ${SECP256K1_LIBRARY}
162+
${ETHASH_LIBRARY} ${KECCAK_LIBRARY} ${SPEEDB_LIBRARY}
163+
${Boost_LIBRARIES} ${OPENSSL_LIBRARIES}
164+
)
159165

160166
add_subdirectory(src/bins)
161167

Dockerfile

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,18 @@ FROM debian:trixie
88
# Update the system
99
RUN apt-get update && apt-get upgrade -y
1010

11-
# Install dependencies
12-
RUN apt-get install -y \
13-
build-essential \
14-
cmake \
15-
tmux \
16-
clang-tidy \
17-
autoconf \
18-
libtool \
19-
pkg-config \
20-
libabsl-dev \
21-
libboost-all-dev \
22-
libc-ares-dev \
23-
libcrypto++-dev \
24-
libgrpc-dev \
25-
libgrpc++-dev \
26-
librocksdb-dev \
27-
libscrypt-dev \
28-
libsnappy-dev \
29-
libssl-dev \
30-
zlib1g-dev \
31-
openssl \
32-
protobuf-compiler \
33-
protobuf-compiler-grpc \
34-
nano \
35-
vim \
36-
unison \
37-
git
38-
3911
# Set the working directory in the Docker container
4012
WORKDIR /bdk-cpp
4113

4214
# Copy the local folder to the container
4315
COPY . /bdk-cpp
4416

17+
# Install Docker-specific dependencies
18+
RUN apt-get -y install nano vim unison curl jq unzip gcovr
19+
20+
# Install dependencies
21+
RUN bash /bdk-cpp/scripts/deps.sh --install
22+
4523
# Create the synchronized directory
4624
RUN mkdir /bdk-volume
4725

README.md

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,40 @@ The project has a Dockerfile at the root of the repository that will build the p
3535
* Build the image locally with `docker build -t bdk-cpp-dev:latest .` (if using Linux or Mac, run as `sudo`)
3636
* This will build the image and tag it as `bdk-cpp-dev:latest` - you can change the tag to whatever you want, but remember to change it on the next step
3737
* Run the container (you will be logged in as root):
38-
* **For Linux/Mac**: `sudo docker run -it -v $(pwd):/bdk-volume -p 8080-8099:8080-8099 -p 8110-8111:8110-8111 bdk-cpp-dev:latest`
39-
* **For Windows**: `docker run -it -v %cd%:/bdk-volume -p 8080-8099:8080-8099 -p 8110-8111:8110-8111 bdk-cpp-dev:latest`
38+
* **For Linux/Mac**: `sudo docker run -it --name bdk-cpp -v $(pwd):/bdk-volume -p 8080-8099:8080-8099 -p 8110-8111:8110-8111 bdk-cpp-dev:latest`
39+
* **For Windows**: `docker run -it --name bdk-cpp -v %cd%:/bdk-volume -p 8080-8099:8080-8099 -p 8110-8111:8110-8111 bdk-cpp-dev:latest`
4040

4141
Remember that we are using our local repo as a volume, so every change in the local folder will be reflected to the container in real time, and vice-versa.
4242

4343
Also, you can integrate the container with your favorite IDE or editor, e.g. [VSCode + Docker extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker).
4444

4545
## Developing manually
4646

47-
Install the following dependencies on your system:
48-
49-
* **GCC** with support for **C++23** or higher
50-
* **CMake 3.19.0** or higher
51-
* **Boost 1.83** or higher (components: *chrono, filesystem, program-options, system, thread, nowide*)
52-
* **OpenSSL 1.1.1**
53-
* **CryptoPP 8.2.0** or higher
54-
* **libscrypt**
55-
* **zlib**
56-
* **libsnappy** for database compression
57-
* **tmux** (for deploying)
58-
* (optional) **clang-tidy** for linting
59-
* (optional) **mold** for faster/more efficient linking
47+
You will need the following dependencies installed locally on your system:
48+
49+
* *Toolchain binaries*:
50+
* **git**
51+
* **GCC** with support for **C++23** or higher
52+
* **Make**
53+
* **CMake 3.19.0** or higher
54+
* **Protobuf** (protoc + grpc_cpp_plugin)
55+
* **tmux** (for deploying)
56+
* (optional) **ninja** if you prefer it over make
57+
* (optional) **mold** if you prefer it over ld
58+
* (optional) **doxygen** for generating docs
59+
* (optional) **clang-tidy** for linting
60+
* *Libraries*:
61+
* **Boost 1.83** or higher (components: *chrono, filesystem, program-options, system, thread, nowide*)
62+
* **OpenSSL 1.1.1** / **libssl 1.1.1** or higher
63+
* **libzstd**
64+
* **CryptoPP 8.2.0** or higher
65+
* **libscrypt**
66+
* **libc-ares**
67+
* **gRPC** (libgrpc and libgrpc++)
68+
* **secp256k1**
69+
* **ethash** + **keccak**
70+
* **EVMOne** + **EVMC**
71+
* **Speedb**
6072

6173
The versions of those dependencies should suffice out-of-the-box for at least the following distros (or greater, including their derivatives):
6274

@@ -66,21 +78,23 @@ The versions of those dependencies should suffice out-of-the-box for at least th
6678
* **Fedora 40**
6779
* Any rolling release distro from around **May 2024** onwards (check their repos to be sure)
6880

69-
For older distros, you may need to compile some dependencies from source (specifically CMake, Boost and/or GCC). Make sure to either uninstall them from the system first to prevent any version conflicts, or use a workaround like e.g. Debian's `update-alternatives` or similar.
81+
There is a script called `scripts/deps.sh` which you can use to check if you have those dependencies installed (`deps.sh --check`), and install them in case you don't (`deps.sh --install`). The script expects dependencies to be installed either on `/usr` or `/usr/local`, giving preference to the latter if it finds anything there (so you can use a higher version of a dependency while still keeping your distro's default one).
7082

71-
Specifically for GCC, make sure to also export the right paths for compilation in your environment in case you're using a self-compiled build. For example, in a Linux system, put something like this in your `~/.bashrc` file, changing the version accordingly to whichever one you have installed:
83+
**Please note that installing most dependencies through the script only works on APT-based distros** (Debian, Ubuntu and derivatives) - you can still check the dependencies on any distro and install the few ones labeled as "external" (those are fetched through `git`), but if you're on a distro with another package manager and/or a distro older than one of the minimum ones listed above, you're on your own.
7284

73-
```bash
74-
PATH=/usr/local/gcc-14.1.0/bin:$PATH
75-
LD_LIBRARY_PATH=/usr/local/gcc-14.1.0/lib64:$LD_LIBRARY_PATH
76-
```
85+
### GCC-specific tips
7786

78-
#### One-liners
87+
For Debian specifically, you can (and should) use `update-alternatives` to register and set your GCC version to a more up-to-date build if required.
7988

80-
* For APT-based distros:
89+
If you're using a self-compiled GCC build out of the system path (e.g. `--prefix=/usr/local/gcc-X.Y.Z` instead of `--prefix=/usr/local`), don't forget to export its installation paths in your `PATH` and `LD_LIBRARY_PATH` env vars (to prevent e.g. "version `GLIBCXX_...'/`CXXABI_...` not found" errors). Put something like this in your `~/.bashrc` file for example, changing the version accordingly to whichever one you have installed:
8190

8291
```bash
83-
sudo apt install build-essential cmake tmux clang-tidy autoconf libtool pkg-config libabsl-dev libboost-all-dev libc-ares-dev libcrypto++-dev libgrpc-dev libgrpc++-dev librocksdb-dev libscrypt-dev libsnappy-dev libssl-dev zlib1g-dev openssl protobuf-compiler protobuf-compiler-grpc unison git
92+
# For GCC in /usr/local
93+
export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
94+
95+
# For self-contained GCC outside /usr/local
96+
export PATH=/usr/local/gcc-14.2.0/bin:$PATH
97+
export LD_LIBRARY_PATH=/usr/local/gcc-14.2.0/lib64:$LD_LIBRARY_PATH
8498
```
8599

86100
## Documentation

0 commit comments

Comments
 (0)