From 8d0e979b5f5b83c4300c4539de26dffe96a6da5f Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Fri, 12 May 2023 18:41:06 +0100 Subject: [PATCH] builder: Add support for automatic toolchain setup --- builder | 31 ++++++++------- cmake/caches/debug.cmake | 29 ++++++++++++++ cmake/caches/release.cmake | 29 ++++++++++++++ cmake/toolchains/x86_64-linux-musl.cmake | 49 ++++++++++++++++++++++++ scripts/utils.sh | 2 +- 5 files changed, 125 insertions(+), 15 deletions(-) create mode 100644 cmake/caches/debug.cmake create mode 100644 cmake/caches/release.cmake create mode 100644 cmake/toolchains/x86_64-linux-musl.cmake diff --git a/builder b/builder index ff1db07..9bded27 100755 --- a/builder +++ b/builder @@ -138,7 +138,6 @@ function gen_precompile_header_index() { } > ./include/serene_precompiles.h } - function pushed_build() { mkdir -p "$BUILD_DIR" pushd "$BUILD_DIR" > /dev/null || return @@ -151,16 +150,20 @@ function popd_build() { function build-gen() { + local args + setup_toolchain + args=( + "-DSERENE_TOOLCHAIN_PATH=$SERENE_TOOLCHAIN_PATH" + "-DCMAKE_TOOLCHAIN_FILE=$ME/cmake/toolchains/x86_64-linux-musl.cmake" + "-C" + "$ME/cmake/caches/$1.cmake" + ) + pushed_build + info "Running: " - info "cmake -G Ninja" -C "$ME/cmake/caches/serene_$1.cmake" "$ME" "${@:2}" - cmake -G Ninja \ - -DSERENE_CONFIG_HOME="$SERENE_HOME_DIR" \ - -DLLVM_VERSION="$LLVM_VERSION" \ - -DBDWGC_VERSION="$BDWGC_VERSION" \ - -DMUSL_VERSION="$MUSL_VERSION" \ - -C "$ME/cmake/caches/serene_$1.cmake" \ - -DCMAKE_TOOLCHAIN_FILE="$ME/cmake/toolchains/x86_64-linux-musl.cmake" \ + info "cmake -G Ninja" "${args[@]}" "$ME" "${@:2}" + cmake -G Ninja "${args[@]}" \ "$ME" \ "${@:2}" popd_build @@ -180,7 +183,7 @@ function build() { ## Builds the project by regenerating the build scripts local cpus rm -rf "$BUILD_DIR" - build-gen "dev" "$@" + build-gen "debug" "$@" pushed_build cpus=$(nproc) @@ -191,7 +194,7 @@ function build() { ## Builds the project by regenerating the build scripts function build-20() { ## Builds the project using C++20 (will regenerate the build) rm -rf "$BUILD_DIR" pushed_build - build-gen "dev" -DCPP_20_SUPPORT=ON "$@" + build-gen "debug" -DCPP_20_SUPPORT=ON "$@" cmake --build . popd_build } @@ -203,7 +206,7 @@ function build-tidy() { ## Builds the project using clang-tidy (It takes longer function build-release() { ## Builds the project in "Release" mode rm -rf "$BUILD_DIR" pushed_build - build-gen "prod" "$@" + build-gen "release" "$@" cmake --build . --config Release popd_build } @@ -212,7 +215,7 @@ function build-docs() { ## Builds the documentation of Serene rm -rf "$BUILD_DIR" pip install -r "$ME/docs/requirements.txt" pushed_build - build-gen "dev" -DSERENE_ENABLE_DOCS=ON "$@" + build-gen "debug" -DSERENE_ENABLE_DOCS=ON "$@" cmake --build . --parallel popd_build } @@ -263,7 +266,7 @@ function tests() { ## Runs all the test cases function build-tests() { ## Generates and build the project including the test cases rm -rf "$BUILD_DIR" pushed_build - build-gen "dev" -DSERENE_BUILD_TESTING=ON "$@" + build-gen "debug" -DSERENE_BUILD_TESTING=ON "$@" cmake --build . --parallel popd_build } diff --git a/cmake/caches/debug.cmake b/cmake/caches/debug.cmake new file mode 100644 index 0000000..c2da50f --- /dev/null +++ b/cmake/caches/debug.cmake @@ -0,0 +1,29 @@ +# Serene Programming Language +# +# Copyright (c) 2019-2023 Sameer Rahmani +# +# 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 . + +# This file sets up a CMakeCache to build serene for development. In this +# cache file we assume that you are using the toolchain and musl that are +# built by the `builder` script. For example: `builder deps build llvm` +# You still can just build everything yourself but the builder script and +# this file make the process easier. + +# Where to find the packages. Packages can be built from source +# or downloaded via the builder script. +set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "") + +set(SERENE_CCACHE_DIR "$ENV{HOME}/.ccache" CACHE STRING "") + +set(CMAKE_BUILD_TYPE "Debug") diff --git a/cmake/caches/release.cmake b/cmake/caches/release.cmake new file mode 100644 index 0000000..7a1e158 --- /dev/null +++ b/cmake/caches/release.cmake @@ -0,0 +1,29 @@ +# Serene Programming Language +# +# Copyright (c) 2019-2023 Sameer Rahmani +# +# 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 . + +# This file sets up a CMakeCache to build serene for development. In this +# cache file we assume that you are using the toolchain and musl that are +# built by the `builder` script. For example: `builder deps build llvm` +# You still can just build everything yourself but the builder script and +# this file make the process easier. + +# Where to find the packages. Packages can be built from source +# or downloaded via the builder script. +set(CMAKE_EXPORT_COMPILE_COMMANDS OFF CACHE BOOL "") + +set(SERENE_CCACHE_DIR "$ENV{HOME}/.ccache" CACHE STRING "") + +set(CMAKE_BUILD_TYPE "Release") diff --git a/cmake/toolchains/x86_64-linux-musl.cmake b/cmake/toolchains/x86_64-linux-musl.cmake new file mode 100644 index 0000000..196f7e3 --- /dev/null +++ b/cmake/toolchains/x86_64-linux-musl.cmake @@ -0,0 +1,49 @@ +# Serene Programming Language +# +# Copyright (c) 2019-2023 Sameer Rahmani +# +# 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 . + +# This file sets up a CMakeCache to build serene for development. In this +# cache file we assume that you are using the toolchain and musl that are +# built by the `builder` script. For example: `builder deps build llvm` +# You still can just build everything yourself but the builder script and +# this file make the process easier. +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR x86_64) + +set(triple x86_64-pc-linux-musl) + +set(CMAKE_SYSROOT ${SERENE_TOOLCHAIN_PATH}) +set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) + +set(CMAKE_C_COMPILER "clang") +set(CMAKE_C_COMPILER_AR "llvm-ar") +set(CMAKE_C_COMPILER_RANLIB "llvm-ranlib") + +set(CMAKE_CXX_COMPILER "clang++") +set(CMAKE_CXX_COMPILER_AR "llvm-ar") +set(CMAKE_CXX_COMPILER_RANLIB "llvm-ranlib") + +set(CMAKE_ASM_COMPILER "clang") +set(CMAKE_ASM_COMPILER_AR "llvm-ar") +set(CMAKE_ASM_COMPILER_RANLIB "llvm-ranlib") + +set(CMAKE_C_COMPILER_TARGET ${triple}) +set(CMAKE_CXX_COMPILER_TARGET ${triple}) +set(CMAKE_ASM_COMPILER_TARGET ${triple}) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/scripts/utils.sh b/scripts/utils.sh index dc86d86..d9507e1 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -101,7 +101,7 @@ function http_pull() { pkg_name="$1" version="$2" output="$3" - url="$DEV_HEROES/api/packages/serene/generic/$pkg_name/$version/$pkg_name.$version.zstd" + url="$DEV_HEROES/api/packages/serene/generic/$pkg_name/$version/$pkg_name.$version.tar.zstd" info "Fetching '$url'..."