commit 8c125a6b47dd7fd31e0e7b0867ef1526d4a17827 Author: Sameer Rahmani Date: Fri Mar 24 16:29:26 2023 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b7ab9f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# ---> Ansible +*.retry +env +*~ +.terraform +.terraform* + +tf/plan +tf/terraform.tfstate* + +build +.vagrant +.prod +#.# \ No newline at end of file diff --git a/README.org b/README.org new file mode 100644 index 0000000..52a01e6 --- /dev/null +++ b/README.org @@ -0,0 +1 @@ +* Toolchain builder diff --git a/builder b/builder new file mode 100755 index 0000000..735dee5 --- /dev/null +++ b/builder @@ -0,0 +1,103 @@ +#! /bin/bash +# Toolchain builder for the 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 . + +# ----------------------------------------------------------------------------- +# Commentary +# ----------------------------------------------------------------------------- +# This is the builder script for the Serene project. It makes it easier to +# interact with the CMake build scripts. +# +# In order to define a subcommand all you need to do is to define a function +# with the following syntax: +# +# function subcommand-name() { ## DESCRIPTION +# .. subcommand body .. +# } +# +# Make sure to provid one line of DESCRIPTION for the subcommand and use two "#" +# characters to start the description following by a space. Otherwise, your +# subcommand won't be registered +# +set -e + +command=$1 +VERSION="0.9.0" + +ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P) + +# shellcheck source=./scripts/utils.sh +source "$ME/scripts/utils.sh" + +user="serene" +channel="stable" + +function _conan() { + PYTHONPATH="$ME:$PYTHONPATH" conan "$@" +} + +function _create() { + _conan create --user "$user" --channel "$channel" \ + --profile:host="../../profiles/stage$1" \ + . "${@:2}" +} +function llvm-source() { ## Build the llvm source pkg + _push "packages/sources/llvm/" + _create "$@" + _pop +} + +function cmake() { ## Build the cmake package + _push "packages/cmake/" + _create "$@" + _pop +} + +function gcc() { ## Build the gcc package + _push "packages/gcc/" + _create "$@" + _pop +} + +function help() { ## Print out this help message + echo "Commands:" + grep -E '^function [a-zA-Z0-9_-]+\(\) \{ ## .*$$' "$0" | \ + sort | \ + sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1:\2/' | \ + awk 'BEGIN {FS=":"}; {printf "\033[36m%-30s\033[0m %s\n", $1, $2}' +} + +# ----------------------------------------------------------------------------- +# Main logic +# ----------------------------------------------------------------------------- +echo -e "\nSerene Builder Version $VERSION" +echo -e "\nCopyright (C) 2019-2023" +echo -e "Sameer Rahmani " +echo -e "Serene comes with ABSOLUTELY NO WARRANTY;" +echo -e "This is free software, and you are welcome" +echo -e "to redistribute it under certain conditions;" +echo -e "for details take a look at the LICENSE file.\n" + +# Find the subcommand in the functions and run we find it. +for fn in $(fn-names); do + if [[ $fn == "$command" ]]; then + eval "$fn ${*:2}" + exit $? + fi +done + +# If we couldn't find the command print out the help message +help diff --git a/conf/versions.py b/conf/versions.py new file mode 100644 index 0000000..6df9db0 --- /dev/null +++ b/conf/versions.py @@ -0,0 +1,17 @@ +# Toolchain builder for the 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 . + +LLVM_VERSION = "22b5fe74782a322e07855e20f83a14d7a426fcc9" diff --git a/packages/cmake/#conanfile.py# b/packages/cmake/#conanfile.py# new file mode 100644 index 0000000..8ce4460 --- /dev/null +++ b/packages/cmake/#conanfile.py# @@ -0,0 +1,59 @@ +# Toolchain builder for the 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 . + +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps +from conan.tools.files import get +from conan.tools.env import VirtualBuildEnv + +import os + + +class Cmake(ConanFile): + name = "cmake" + version = "3.26.0" + settings = "os", "arch", "build_type", "compiler" + + def requirements(self): + if self.settings.compiler == "gcc": + self.requires(f"gcc/latest@{self.user}/{self.channel}") + self.tool_requires(f"gcc/latest@{self.user}/{self.channel}") + + def source(self): + get( + self, + f"https://github.com/Kitware/CMake/archive/v{self.version}.tar.gz", + ) + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + deps = CMakeDeps(self) + deps.generate() + + def build(self): + cmake = CMake(self) + cmake.configure( + {"CMAKE_USE_OPENSSL": "OFF", "BUILD_TESTING": "OFF"}, + build_script_folder=f"CMake-{self.version}", + ) + cmake.build() + cmake.install() + + def package_info(self): + self.buildenv_info.prepend_path( + "PATH", os.path.join(self.package_folder, "bin") + ) diff --git a/packages/cmake/.#conanfile.py b/packages/cmake/.#conanfile.py new file mode 120000 index 0000000..d6ca560 --- /dev/null +++ b/packages/cmake/.#conanfile.py @@ -0,0 +1 @@ +lxsameer@majin.15395:1678886450 \ No newline at end of file diff --git a/packages/cmake/conanfile.py b/packages/cmake/conanfile.py new file mode 100644 index 0000000..156d36b --- /dev/null +++ b/packages/cmake/conanfile.py @@ -0,0 +1,59 @@ +# Toolchain builder for the 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 . + +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps +from conan.tools.files import get +from conan.tools.env import VirtualBuildEnv + +import os + + +class Cmake(ConanFile): + name = "cmake" + version = "3.26.0" + settings = "os", "arch", "build_type", "compiler" + + def requirements(self): + if self.settings.compiler == "gcc": + self.requires(f"gcc/latest@{self.user}/{self.channel}") + self.tool_requires(f"gcc/latest@{self.user}/{self.channel}") + + def source(self): + get( + self, + f"https://github.com/Kitware/CMake/archive/v{self.version}.tar.gz", + ) + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + deps = CMakeDeps(self) + deps.generate() + + def build(self): + cmake = CMake(self) + cmake.configure( + {"CMAKE_USE_OPENSSL": "OFF", "BUILD_TESTING": "OFF"}, + build_script_folder=f"CMake-{self.version}", + ) + cmake.build() + cmake.install() + + def package_info(self): + self.buildenv_info.prepend_path( + "PATH", os.path.join(self.package_folder, "bin") + ) diff --git a/packages/cmake/setup.cmake b/packages/cmake/setup.cmake new file mode 100644 index 0000000..481939a --- /dev/null +++ b/packages/cmake/setup.cmake @@ -0,0 +1,17 @@ +# Toolchain builder for the 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 . +set(CMAKE_USE_OPENSSL OFF CACHE BOOL "") +set(BUILD_TESTING OFF CACHE BOOL "") diff --git a/packages/gcc/conanfile.py b/packages/gcc/conanfile.py new file mode 100644 index 0000000..d4b13c1 --- /dev/null +++ b/packages/gcc/conanfile.py @@ -0,0 +1,75 @@ +# Toolchain builder for the 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 . +import shutil +from pathlib import Path + +from conan import ConanFile +from conan.tools.files import get, copy +from conan.tools.cmake import CMakeToolchain + +import os + + +class GCC(ConanFile): + name = "gcc" + version = "latest" + settings = "os", "arch" + tc_type = "cross" + exports = ("*.cmake",) + target = "x86_64-linux-musl" + + @property + def toolchain_vars(self): + return { + "CMAKE_C_COMPILER": "x86_64-linux-musl-gcc", + "CMAKE_CXX_COMPILER": "x86_64-linux-musl-g++", + "CMAKE_AS_COMPILER": "x86_64-linux-musl-gcc", + "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM": "NEVER", + "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY": "ONLY", + "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE": "ONLY", + "CMAKE_FIND_ROOT_PATH_MODE_PACKAGE": "ONLY", + } + + def build(self): + copy(self, "gcc-musl-toolchain.cmake", self.recipe_folder, self.package_folder) + get( + self, + f"http://musl.cc/{self.target}-{self.tc_type}.tgz", + destination=self.package_folder, + filename=f"{self.target}-{self.tc_type}.tgz", + keep_permissions=True, + strip_root=True, + ) + + def package_info(self): + bindir = Path(os.path.join(self.package_folder, "bin")) + self.runenv_info.prepend_path( + "PATH", + str(bindir), + ) + f = os.path.join(self.package_folder, "gcc-musl-toolchain.cmake") + + self.buildenv_info.append("sysroot", self.package_folder) + self.conf_info.prepend("tools.cmake.cmaketoolchain:user_toolchain", f) + + self.conf_info.define("tools.build:sysroot", self.package_folder) + self.buildenv_info.define_path("SYSROOT", self.package_folder) + + self.buildenv_info.define("CC", str(bindir / f"{self.target}-gcc")) + self.buildenv_info.define("CXX", str(bindir / f"{self.target}-g++")) + self.buildenv_info.define("AR", str(bindir / f"{self.target}-ar")) + self.buildenv_info.define("NM", str(bindir / f"{self.target}-nm")) + self.buildenv_info.define("RANLIB", str(bindir / f"{self.target}-ranlib")) diff --git a/packages/gcc/gcc-musl-toolchain.cmake b/packages/gcc/gcc-musl-toolchain.cmake new file mode 100644 index 0000000..83e288d --- /dev/null +++ b/packages/gcc/gcc-musl-toolchain.cmake @@ -0,0 +1,17 @@ +# Toolchain builder for the 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 . +set(CMAKE_C_COMPILER "x86_64-linux-musl-gcc") +set(CMAKE_CXX_COMPILER "x86_64-linux-musl-g++") diff --git a/packages/sources/llvm/conanfile.py b/packages/sources/llvm/conanfile.py new file mode 100644 index 0000000..d710b29 --- /dev/null +++ b/packages/sources/llvm/conanfile.py @@ -0,0 +1,37 @@ +# Toolchain builder for the 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 . + +from conan import ConanFile +from conan.tools.files import get + +from conf.versions import * + + +class LLVM(ConanFile): + name = "llvm-source" + version = LLVM_VERSION + settings = "os", "arch" + tc_type = "cross" + + def source(self): + get( + self, + f"https://github.com/llvm/llvm-project/archive/{self.version}.tar.gz", + strip_root=True, + ) + + def build(self): + pass diff --git a/profiles/conf b/profiles/conf new file mode 100644 index 0000000..c6e77d6 --- /dev/null +++ b/profiles/conf @@ -0,0 +1,3 @@ +[conf] +core.download:parallel=10 +tools.build:jobs=2 \ No newline at end of file diff --git a/profiles/stage0 b/profiles/stage0 new file mode 100644 index 0000000..bc806ab --- /dev/null +++ b/profiles/stage0 @@ -0,0 +1,22 @@ +include(conf) +{% set gcc_triple = "x86_64-linux-musl" %} + +[settings] +os=Linux +arch=x86_64 +build_type=Release + +compiler=gcc +compiler.version=11.2 +compiler.libcxx=libstdc++11 + +[tool_requires] +gcc/latest@serene/stable + +[buildenv] +CC={{ gcc_triple }}-gcc +CXX={{ gcc_triple }}-g++ +LD={{ gcc_triple }}-ld +CFLAGS=-static +CXXFLAGS=-static +LDFLAGS=-static \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4e7024a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +conan==2 +black diff --git a/scripts/utils.sh b/scripts/utils.sh new file mode 100644 index 0000000..b8f183b --- /dev/null +++ b/scripts/utils.sh @@ -0,0 +1,65 @@ +#! /bin/bash +# Toolchain builder for the 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 . + +set -e + +# ----------------------------------------------------------------------------- +# Helper functions +# ----------------------------------------------------------------------------- +function fn-names() { + grep -E '^function [0-9a-zA-Z_-]+\(\) \{ ## .*$$' "$0" | sed 's/^function \([a-zA-Z0-9_-]*\)() { ## \(.*\)/\1/' +} + +function info() { + if [ "$1" ] + then + echo -e "[\033[01;32mINFO\033[00m]: $*" + fi +} + +function error() { + if [ "$1" ] + then + echo -e "[\033[01;31mERR\033[00m]: $*" + fi +} + +function warn() { + if [ "$1" ] + then + echo -e "[\033[01;33mWARN\033[00m]: $*" + fi +} + +function yes_or_no { + while true; do + read -rp "$* [y/n]: " yn + case $yn in + [Yy]*) return 0 ;; + [Nn]*) echo "Aborted" ; return 1 ;; + esac + done +} + +function _push() { + pushd "$1" > /dev/null || return +} + + +function _pop() { + popd > /dev/null || return +}