Add the deps.sh file to manage the build process of dependencies

This commit is contained in:
Sameer Rahmani 2023-02-01 23:50:38 +00:00
parent 998444e945
commit 19d19a0c12
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
4 changed files with 194 additions and 25 deletions

View File

@ -175,8 +175,7 @@ function serve-docs() { ## Serve the docs directory from build dir
}
function clean() { ## Cleans up the source dir and removes the build
rm -rf "$BUILD_DIR"
rm -rf "$(find . -iname '*~')"
git clean -dxf
}
function run() { ## Runs `serenec` and passes all the given aruguments to it

32
config
View File

@ -22,24 +22,8 @@
#
# Modify the `CONFIG VARS` the way you see fit or just use the default.
# -----------------------------------------------------------------------------
# Helper functions
# -----------------------------------------------------------------------------
function _push() {
pushd "$1" > /dev/null || return
}
function _pop() {
popd > /dev/null || return
}
function get_version() {
_push "$1"
git describe
_pop
}
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
source "$ME/scripts/utils.sh"
# -----------------------------------------------------------------------------
# CONFIG VARS
@ -58,26 +42,28 @@ TARGET_ARCHS="X86;AArch64;AMDGPU;ARM;RISCV;WebAssembly"
# The repository to push/pull packages to/from.
DEV_HEROES="https://beta.devheroes.codes"
BUILD_DIR_NAME="build"
DEPS_BUILD_DIR_NAME=".env"
# -----------------------------------------------------------------------------
# INTERNAL VARS
# -----------------------------------------------------------------------------
# You don't have any business in this section. Don't change any thing here
# unless you really know what you're doing
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
BUILD_DIR="$ME/$BUILD_DIR_NAME"
DEPS_BUILD_DIR="$ME/$DEPS_BUILD_DIR_NAME"
LLVM_DIR_NAME="llvm"
LLVM_DIR="$ME/deps/llvm-project"
LLVM_SOURCE_DIR="$LLVM_DIR/$LLVM_DIR_NAME"
LLVM_BUILD_DIR="$BUILD_DIR/${LLVM_DIR_NAME}_build"
LLVM_INSTALL_DIR="$BUILD_DIR/$LLVM_DIR_NAME.$(get_version $LLVM_DIR)"
LLVM_BUILD_DIR="$DEPS_BUILD_DIR/${LLVM_DIR_NAME}_build"
LLVM_INSTALL_DIR="$DEPS_BUILD_DIR/$LLVM_DIR_NAME.$(get_version $LLVM_DIR)"
BDWGC_DIR_NAME="bdwgc"
BDWGC_SOURCE_DIR="$ME/deps/$BDWGC_DIR_NAME"
BDWGC_BUILD_DIR="$BUILD_DIR/${BDWGC_DIR_NAME}_build"
BDWGC_INSTALL_DIR="$BUILD_DIR/$BDWGC_DIR_NAME.$(get_version $BDWGC_SOURCE_DIR)"
BDWGC_BUILD_DIR="$DEPS_BUILD_DIR/${BDWGC_DIR_NAME}_build"
BDWGC_INSTALL_DIR="$DEPS_BUILD_DIR/$BDWGC_DIR_NAME.$(get_version $BDWGC_SOURCE_DIR)"
# This is a variable that cmake expects
BDWgc_DIR="$BDWGC_INSTALL_DIR/lib64/cmake/bdwgc"

169
scripts/deps.sh Normal file
View File

@ -0,0 +1,169 @@
#! /bin/bash
# Serene Programming Language
#
# Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
# Commentary
# -----------------------------------------------------------------------------
# This file contains some functions to build, pack and distribute the
# dependencies
source ./utils.sh
function build_toolchain() { ## Build LLVM and the toolchain
local version
version=$(get_version "$LLVM_DIR")
info "Building the toolchain version '$version'..."
if [[ -d "$LLVM_BUILD_DIR.$version" ]]; then
warn "A build dir for 'llvm' already exists at '$LLVM_BUILD_DIR.$version'"
warn "Skipping..."
return
fi
mkdir -p "$LLVM_BUILD_DIR.$version"
mkdir -p "$LLVM_INSTALL_DIR"
_push "$LLVM_BUILD_DIR.$version"
cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX="$LLVM_INSTALL_DIR" \
-DLLVM_PARALLEL_COMPILE_JOBS="$(nproc)" \
-DLLVM_PARALLEL_LINK_JOBS="$(nproc)" \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_TARGETS_TO_BUILD="$TARGET_ARCHS" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_EXTERNAL_PROJECTS=iwyu \
-DLLVM_EXTERNAL_IWYU_SOURCE_DIR="$IWYU_DIR" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_CCACHE_BUILD=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DLLVM_ENABLE_PROJECTS='clang;lldb;lld;mlir;clang-tools-extra' \
-DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind' \
-DCMAKE_C_COMPILER="$CC" \
-DCMAKE_CXX_COMPILER="$CXX" \
-DLLVM_ENABLE_LLD=ON \
"$LLVM_SOURCE_DIR"
cmake --build . --parallel
cmake -DCMAKE_INSTALL_PREFIX="$LLVM_INSTALL_DIR" -P cmake_install.cmake
_pop
}
function package_toolchain() { ## Packages the built toolchain
local version
version=$(get_version "$LLVM_DIR")
if [ ! -d "$LLVM_INSTALL_DIR" ]; then
error "No installation directory is found at: '$LLVM_INSTALL_DIR'"
exit 1
fi
info "Packaging the toolchain version '$version'..."
time tar -I "$ZSTD_CLI" -C "$DEPS_BUILD_DIR" -cf "$LLVM_INSTALL_DIR.zstd" "$LLVM_INSTALL_DIR"
}
function push_toolchain() { ## Push the toolchain to the package repository
local version
version=$(get_version "$LLVM_DIR")
if [ ! -f "$LLVM_INSTALL_DIR.zstd" ]; then
error "No package is found at: '$LLVM_INSTALL_DIR.zstd'"
exit 1
fi
info "Pushing the toolchain version '$version'..."
_push "$DEPS_BUILD_DIR"
http "$LLVM_DIR_NAME" "$version"
info "Done"
_pop
}
function build_bdwgc() { ## Builds the BDW GC
local version
version=$(get_version "$BDWGC_SOURCE_DIR")
info "Building the BDWGC version '$version'..."
if [[ -d "$BDWGC_BUILD_DIR.$version" ]]; then
warn "A build dir for 'BDWGC' already exists at '$BDWGC_BUILD_DIR.$version'"
warn "Skipping..."
return
fi
mkdir -p "$BDWGC_BUILD_DIR.$version"
mkdir -p "$BDWGC_INSTALL_DIR"
_push "$BDWGC_BUILD_DIR.$version"
cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX="$BDWGC_INSTALL_DIR" \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-Dbuild_cord=ON \
-Denable_atomic_uncollectable=ON \
-Denable_cplusplus=OFF \
-Denable_disclaim=ON \
-Denable_docs=ON \
-Denable_dynamic_loading=ON \
-Denable_gc_assertions=ON \
-Denable_handle_fork=ON \
-Denable_java_finalization=OFF \
-Denable_munmap=ON \
-Denable_parallel_mark=ON \
-Denable_register_main_static_da=ON \
-Denable_thread_local_alloc=ON \
-Denable_threads=ON \
-Denable_threads_discovery=ON \
-Denable_throw_bad_alloc_library=ON \
-Dinstall_headers=ON \
-DCMAKE_C_COMPILER="$CC" \
-DCMAKE_CXX_COMPILER="$CXX" \
"$BDWGC_SOURCE_DIR"
cmake --build . --parallel
cmake -DCMAKE_INSTALL_PREFIX="$BDWGC_INSTALL_DIR" -P cmake_install.cmake
_pop
}
function package_bdwgc() { ## Packages the built toolchain
local version
version=$(get_version "$BDWGC_SOURCE_DIR")
if [ ! -d "$BDWGC_INSTALL_DIR" ]; then
error "No installation directory is found at: '$BDWGC_INSTALL_DIR'"
exit 1
fi
info "Packaging the BDWGC version '$version'..."
time tar -I "$ZSTD_CLI" -C "$DEPS_BUILD_DIR" -cf "$BDWGC_INSTALL_DIR.zstd" "$BDWGC_INSTALL_DIR"
}
function push_bdwgc() { ## Push the BDWGC package to the package repository
local version
version=$(get_version "$BDWGC_SOURCE_DIR")
if [ ! -f "$BDWGC_INSTALL_DIR.zstd" ]; then
error "No package is found at: '$BDWGC_INSTALL_DIR.zstd'"
exit 1
fi
info "Pushing the BDWGC package version '$version'..."
_push "$DEPS_BUILD_DIR"
http "$BDWGC_DIR_NAME" "$version"
info "Done"
_pop
}

View File

@ -54,3 +54,18 @@ function yes_or_no {
esac
done
}
function _push() {
pushd "$1" > /dev/null || return
}
function _pop() {
popd > /dev/null || return
}
function get_version() {
_push "$1"
git describe
_pop
}