Initial commit

This commit is contained in:
Sameer Rahmani 2023-03-24 16:29:26 +00:00
commit 8c125a6b47
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
15 changed files with 492 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
# ---> Ansible
*.retry
env
*~
.terraform
.terraform*
tf/plan
tf/terraform.tfstate*
build
.vagrant
.prod
#.#

1
README.org Normal file
View File

@ -0,0 +1 @@
* Toolchain builder

103
builder Executable file
View File

@ -0,0 +1,103 @@
#! /bin/bash
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 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 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 <lxsameer@gnu.org>"
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

17
conf/versions.py Normal file
View File

@ -0,0 +1,17 @@
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 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/>.
LLVM_VERSION = "22b5fe74782a322e07855e20f83a14d7a426fcc9"

View File

@ -0,0 +1,59 @@
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 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/>.
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")
)

View File

@ -0,0 +1 @@
lxsameer@majin.15395:1678886450

View File

@ -0,0 +1,59 @@
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 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/>.
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")
)

View File

@ -0,0 +1,17 @@
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 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/>.
set(CMAKE_USE_OPENSSL OFF CACHE BOOL "")
set(BUILD_TESTING OFF CACHE BOOL "")

75
packages/gcc/conanfile.py Normal file
View File

@ -0,0 +1,75 @@
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 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/>.
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"))

View File

@ -0,0 +1,17 @@
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 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/>.
set(CMAKE_C_COMPILER "x86_64-linux-musl-gcc")
set(CMAKE_CXX_COMPILER "x86_64-linux-musl-g++")

View File

@ -0,0 +1,37 @@
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 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/>.
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

3
profiles/conf Normal file
View File

@ -0,0 +1,3 @@
[conf]
core.download:parallel=10
tools.build:jobs=2

22
profiles/stage0 Normal file
View File

@ -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

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
conan==2
black

65
scripts/utils.sh Normal file
View File

@ -0,0 +1,65 @@
#! /bin/bash
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 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/>.
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
}