Skip to content

Commit

Permalink
feat(scripts): set CC and CXX to clang while building the node
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Dec 9, 2024
1 parent 604d035 commit 1df50c6
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 5 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,24 @@ packages
from a testing branch. Or you could build the RocksDB from source manually:
```bash
# Install dependencies
sudo apt install libjemalloc-dev libgflags-dev libzstd-dev liblz4-dev
# Clone the repo
cd /path/to
git clone https://github.com/facebook/rocksdb.git
cd rocksdb
git checkout v8.10.0
git checkout v9.7.4
# Build the library
mkdir -p build && cd ./build
cmake -DWITH_LZ4=ON -DWITH_ZSTD=ON -DWITH_JEMALLOC=ON -DCMAKE_BUILD_TYPE=Release ..
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release \
-DWITH_LZ4=ON -DWITH_ZSTD=ON -DWITH_JEMALLOC=ON ..
make -j16 rocksdb
# Set env somewhere
export ROCKSDB_LIB_DIR=/path/to/rocksdb/build
```
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ local_network_dir := justfile_directory() / ".temp"
default:
@just --choose

# Installs the node.
install:
./scripts/install.sh

# Installs the required version of `rustfmt`.
install_fmt:
rustup component add rustfmt --toolchain nightly
Expand Down
3 changes: 3 additions & 0 deletions scripts/build-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -eE
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
root_dir=$(cd "${script_dir}/../" && pwd -P)

source "${script_dir}/common.sh"

if [ -z "${TYCHO_BUILD_PROFILE}" ]; then
profile_arg=""
profile="debug"
Expand All @@ -12,6 +14,7 @@ else
profile="${TYCHO_BUILD_PROFILE}"
fi

set_clang_env 19
cargo build --bin tycho $profile_arg

echo "${root_dir}/target/${profile}/tycho"
28 changes: 28 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,31 @@ function is_number {
return 1
fi
}

function set_clang_env {
local clang_version="$1"
if [ -z "$clang_version" ]; then
echo "ERROR: Expected clang versrion for 'set_clang_env'."
exit 1
fi

if [ -z "$2" ] || [ "$2" == "require" ]; then
local require="$2"
else
echo "ERROR: Expected optional 'require' flag for 'set_clang_env'."
exit 1
fi

local cc_path=$(command -v "clang-${clang_version}" 2>&1 || true)
local cxx_path=$(command -v "clang++-${clang_version}" 2>&1 || true)

if [ ! -z "$cc_path" ] && [ ! -z "$cxx_path" ]; then
export CC="$cc_path"
export CXX="$cxx_path"
elif [ -z "$require" ]; then
echo "WARN: Clang ${clang_version} not found, fallback to default build."
else
echo "ERROR: Clang ${clang_version} required but not found."
exit 1
fi
}
36 changes: 36 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -eE

script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
root_dir=$(cd "${script_dir}/../" && pwd -P)

source "${script_dir}/common.sh"

if ! command -v cargo 2>&1 >/dev/null
then
cat << EOF
ERROR: \`cargo\` could not be found. You need to install the Rust compiler first:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
And add its environment variables:
source ~/.cargo/env
EOF
exit 1
fi

set_clang_env 19
cargo install --path ./cli --locked

cat << EOF
Node installed successfully. Run the following to configure it:
tycho init --systemd --global-config https://testnet.tychoprotocol.com/global-config.json \\
--validator --stake 500000
Where
--global-config: file path or URL to the network global config
--stake: stake value per round
EOF

0 comments on commit 1df50c6

Please sign in to comment.