Skip to content

Commit

Permalink
Refactor build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dr8co committed Jun 5, 2024
1 parent 733953e commit 6ef7b80
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 67 deletions.
63 changes: 63 additions & 0 deletions scripts/build-functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

set -e

# This script is used to build the project on the Ubuntu Jammy (22.04) distribution.
# It is not intended to be used on other distributions, and must be run from the project root.

PARALLELISM_LEVEL=4

function check_root() {
# Root access is required to install the dependencies.
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
abort
fi
}

function check_dependencies() {
for cmd in wget add-apt-repository; do
if ! command -v $cmd &>/dev/null; then
echo "$cmd could not be found"
exit
fi
done
}

function install_dependencies() {
# wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
# add-apt-repository -y "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main"
# add-apt-repository -y ppa:ubuntu-toolchain-r/ppa
apt update
export NEEDRESTART_SUSPEND=1
apt install -y unzip gcc-14 g++-14 clang-18 lldb-18 lld-18 libc++-18-dev libc++abi-18-dev libllvmlibc-18-dev clang-tools-18 libgcrypt20-dev openssl libreadline8 libreadline-dev libsodium23 libsodium-dev

# Install CMake 3.29.3
if dpkg -s "cmake" >/dev/null 2>&1; then
apt remove -y --purge --auto-remove cmake
fi

wget -qO- "https://github.com/Kitware/CMake/releases/download/v3.29.3/cmake-3.29.3-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local

# Install Ninja 1.12
if dpkg -s "ninja-build" >/dev/null 2>&1; then
apt remove -y --purge --auto-remove ninja-build
fi

wget -q "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip"
unzip ninja-linux.zip -d /usr/local/bin
}

function build_blake3() {
./install-blake3.sh clang-18
}

function configure_cmake() {
cmake -B build -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_BUILD_TYPE=Debug -G Ninja
}

function build_project() {
cmake --build build --config Debug -j "$PARALLELISM_LEVEL"
}

trap "echo 'An unexpected error occurred. Program aborted.'" ERR
86 changes: 19 additions & 67 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,76 +1,28 @@
#!/bin/env bash
#!/usr/bin/env bash

set -e
# Run from this directory
cd "${0%/*}" || abort

# This script is used to build the project on the Ubuntu Jammy (22.04) distribution.
# It is not intended to be used on other distributions, and must be run from the project root.
# Include the build functions
. ./build-functions.sh

PARALLELISM_LEVEL=4
# Root access is required to install the dependencies.
check_root

function check_root() {
# Root access is required to install the dependencies.
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
abort
fi
}
# Check for required commands
check_dependencies

function check_dependencies() {
for cmd in wget add-apt-repository; do
if ! command -v $cmd &>/dev/null; then
echo "$cmd could not be found"
exit
fi
done
}
# Install dependencies
install_dependencies

function install_dependencies() {
# wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
# add-apt-repository -y "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main"
# add-apt-repository -y ppa:ubuntu-toolchain-r/ppa
apt update
export NEEDRESTART_SUSPEND=1
apt install -y unzip gcc-14 g++-14 clang-18 lldb-18 lld-18 libc++-18-dev libc++abi-18-dev libllvmlibc-18-dev clang-tools-18 libgcrypt20-dev openssl libreadline8 libreadline-dev libsodium23 libsodium-dev
echo "Ninja: $(ninja --version), CMake: $(cmake --version)"

# Install CMake 3.29.3
if dpkg -s "cmake" >/dev/null 2>&1; then
apt remove -y --purge --auto-remove cmake
fi
# Build and install BLAKE3
build_blake3

wget -qO- "https://github.com/Kitware/CMake/releases/download/v3.29.3/cmake-3.29.3-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local
# Configure CMake
cd .. || abort
configure_cmake

# Install Ninja 1.12
if dpkg -s "ninja-build" >/dev/null 2>&1; then
apt remove -y --purge --auto-remove ninja-build
fi

wget -q "https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip"
unzip ninja-linux.zip -d /usr/local/bin
}

function build_blake3() {
./install-blake3.sh clang-18
}

function configure_cmake() {
cmake -B build -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_BUILD_TYPE=Debug -G Ninja
}

function build_project() {
cmake --build build --config Debug -j "$PARALLELISM_LEVEL"
}

main() {
trap "echo 'An unexpected error occurred. Program aborted.'" ERR
check_root
check_dependencies
cd "${0%/*}" || abort
install_dependencies
echo "Ninja: $(ninja --version), CMake: $(cmake --version)"
build_blake3
cd .. || abort
configure_cmake
build_project
}

main
# Build the project
build_project

0 comments on commit 6ef7b80

Please sign in to comment.