Compare commits

...

4 Commits

13 changed files with 335 additions and 59 deletions

26
builder
View File

@ -37,6 +37,27 @@ set -e
command=$1
VERSION="0.9.0"
LLVM_VERSION="0e0db0a4d7fd606ee58595f997142f7f2476cbe6"
LLVM_MAJOR_VERSION="17"
CMAKE_VERSION="3.26.0"
NINJA_VERSION="1.11.1"
ZLIB_VERSION="1.2.13"
ZSTD_VERSION="1.5.4"
KERNEL_VERSION="5.0"
MUSL_VERSION="1.2.3"
TARGET=x86_64-pc-linux-musl
export LLVM_VERSION \
CMAKE_VERSION \
NINJA_VERSION \
ZLIB_VERSION \
ZSTD_VERSION \
KERNEL_VERSION \
LLVM_MAJOR_VERSION \
MUSL_VERSION \
TARGET
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
# shellcheck source=./scripts/utils.sh
@ -119,6 +140,11 @@ 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"
if [[ -d "$ME/packages/$command" ]]; then
_build "$command" "${@:2}"
exit $?
fi
# Find the subcommand in the functions and run we find it.
for fn in $(fn-names); do
if [[ $fn == "$command" ]]; then

View File

@ -31,6 +31,17 @@ class current_dir:
os.chdir(self.current)
def get_version(pkg_name):
env = os.environ.get(f"{pkg_name.upper()}_VERSION")
if not env:
raise ValueError(
f"""Can't find the version for {pkg_name}!
Did you forget to define the '{pkg_name.upper()}_VERSION' in the builder?"""
)
return env
def with_static_flags(cmake_vars):
cmake_vars["CMAKE_C_FLAGS"] = f"-static {cmake_vars.get('CMAKE_C_FLAGS', '')}"
cmake_vars["CMAKE_CXX_FLAGS"] = f"-static {cmake_vars.get('CMAKE_CXX_FLAGS', '')}"

View File

@ -14,8 +14,10 @@
# 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 = "0e0db0a4d7fd606ee58595f997142f7f2476cbe6"
CMAKE_VERSION = "3.26.0"
NINJA_VERSION = "1.11.1"
ZLIB_VERSION = "1.2.13"
ZSTD_VERSION = "1.5.4"
import os
LLVM_VERSION = os.environ["LLVM_VERSION"]
CMAKE_VERSION = os.environ["CMAKE_VERSION"]
NINJA_VERSION = os.environ["NINJA_VERSION"]
ZLIB_VERSION = os.environ["ZLIB_VERSION"]
ZSTD_VERSION = os.environ["ZSTD_VERSION"]

View File

@ -22,8 +22,7 @@ from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get
from conf.versions import *
from conf.utils import with_static_flags, current_dir
from conf.utils import with_static_flags, current_dir, get_version
PROJECTS = [
"clang",
@ -47,6 +46,8 @@ TOOLCHAIN_TARGETS = [
"llvm-windres",
"LTO",
"llvm-lipo",
"runtimes",
"builtins",
]
RUNTIME_TARGETS = [
@ -96,22 +97,18 @@ CMAKE_OPTIONS = {
class ClangBootstrap(ConanFile):
name = "clang-bootstrap"
settings = "os", "arch", "compiler", "build_type"
version = LLVM_VERSION
version = get_version("llvm")
def requirements(self):
# if self.settings.compiler == "gcc":
# self.requires(f"gcc/latest@{self.user}/{self.channel}")
self.requires(f"llvm-source/{self.version}@{self.user}/{self.channel}")
self.requires(f"zlib/{ZLIB_VERSION}@{self.user}/{self.channel}")
self.requires(f"zstd/{ZSTD_VERSION}@{self.user}/{self.channel}")
gnu_triple = "x86_64-build-linux-gnu"
musl_triple = "x86_64-build-linux-musl"
def build_requirements(self):
# if self.settings.compiler == "gcc":
# self.tool_requires(f"gcc/latest@{self.user}/{self.channel}")
self.requires(f"llvm-source/{self.version}@{self.user}/{self.channel}")
self.tool_requires(f"cmake/{CMAKE_VERSION}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{NINJA_VERSION}@{self.user}/{self.channel}")
self.requires(f"zlib/{get_version('zlib')}@{self.user}/{self.channel}")
self.requires(f"zstd/{get_version('zstd')}@{self.user}/{self.channel}")
self.tool_requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{get_version('ninja')}@{self.user}/{self.channel}")
def generate(self):
tc = CMakeToolchain(self)
@ -122,13 +119,21 @@ class ClangBootstrap(ConanFile):
deps.generate()
def build(self):
opts = CMAKE_OPTIONS
# opts["CMAKE_C_COMPILER"] = self.settings.compiler
# opts["CMAKE_CXX_COMPILER"] = self.settings.compiler
envs = self.buildenv_info.vars(self, scope="build")
cflags = envs.get("CFLAGS", "")
cxxflags = envs.get("CXXFLAGS", "")
ldflags = envs.get("LDFLAGS", "")
asflags = envs.get("ASFLAGS", "")
targets = [self.musl_triple, self.gnu_triple]
opts = CMAKE_OPTIONS
opts["LLVM_ENABLE_PROJECTS"] = ";".join(PROJECTS)
opts["LLVM_ENABLE_RUNTIMES"] = ";".join(RUNTIME_TARGETS)
opts["LLVM_BUILTIN_TARGETS"] = ";".join(targets)
opts["LLVM_RUNTIME_TARGETS"] = ";".join(targets)
opts["LLVM_DISTRIBUTION_COMPONENTS"] = ";".join(TOOLCHAIN_TARGETS)
# opts["LLVM_RUNTIME_DISTRIBUTION_COMPONENTS"] = "cxx-headers"
zlibdir = self.dependencies["zlib"]
@ -137,22 +142,83 @@ class ClangBootstrap(ConanFile):
opts["CMAKE_REQUIRED_INCLUDES"] = zlib_include
opts["CMAKE_REQUIRED_LIBRARIES"] = f"-L{zlib_lib} -lz"
envs = self.buildenv_info.vars(self, scope="build")
opts[
"CMAKE_CXX_FLAGS"
] = f"{envs.get('CXXFLAGS', '')} -g -g3 -Wl,-fuse-ld=lld -Wl,-v -Wl,-L/usr/lib/gcc/x86_64-pc-linux-gnu/12/"
opts[
"CMAKE_C_FLAGS"
] = f"{envs.get('CFLAGS', '')} -g -g3 -Wl,-fuse-ld=lld -Wl,-v -Wl,-L/usr/lib/gcc/x86_64-pc-linux-gnu/12/"
opts["CMAKE_EXE_LINKER_FLAGS"] = f"{envs.get('LDFLAGS', '')} -static-libgcc"
# opts[
# "CMAKE_SHARED_LINKER_FLAGS"
# ] = f"{envs.get('LDFLAGS', '')} -L{zlib_lib} -Bstatic -lz"
for target in targets:
opts[f"BUILTINS_{target}_CMAKE_SYSTEM_NAME"] = "Linux"
opts[f"BUILTINS_{target}_CMAKE_BUILD_TYPE"] = "Release"
opts[f"BUILTINS_{target}_CMAKE_SYSTEM_PROCESSOR"] = "x86_64"
opts[f"BUILTINS_{target}_CMAKE_C_FLAGS"] = cflags
opts[f"BUILTINS_{target}_CMAKE_CXX_FLAGS"] = cxxflags
opts[f"BUILTINS_{target}_CMAKE_ASM_FLAGS"] = asflags
opts[f"BUILTINS_{target}_CMAKE_C_COMPILER_TARGET"] = target
opts[f"BUILTINS_{target}_CMAKE_CXX_COMPILER_TARGET"] = target
opts[f"BUILTINS_{target}_CMAKE_ASM_COMPILER_TARGET"] = target
opts[f"BUILTINS_{target}_CMAKE_TRY_COMPILE_TARGET_TYPE"] = "STATIC_LIBRARY"
opts[
f"BUILTINS_{target}_CMAKE_EXE_LINKER_FLAGS"
] = f"--target={target} {ldflags}"
opts[
f"BUILTINS_{target}_CMAKE_SHARED_LINKER_FLAGS"
] = f"--target={target} {ldflags}"
opts[f"BUILTINS_{target}_LLVM_USE_LINKER"] = "lld"
opts[f"BUILTINS_{target}_COMPILER_RT_BAREMETAL_BUILD"] = "ON"
opts[f"BUILTINS_{target}_COMPILER_RT_DEFAULT_TARGET_ONLY"] = "ON"
# May be we need to build the builtins with the host compiler
# "CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN": str(gcc_toolchain_path),
# "CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN": str(gcc_toolchain_path),
# "CMAKE_SYSROOT": str(sysroot_path),
opts[f"RUNTIMES_{target}_CMAKE_SYSTEM_NAME"] = "Linux"
opts[f"RUNTIMES_{target}_CMAKE_BUILD_TYPE"] = "Release"
opts[f"RUNTIMES_{target}_CMAKE_C_FLAGS"] = f"--target={target}"
opts[f"RUNTIMES_{target}_CMAKE_CXX_FLAGS"] = f"--target={target}"
opts[f"RUNTIMES_{target}_CMAKE_ASM_FLAGS"] = f"--target={target}"
opts[f"RUNTIMES_{target}_CMAKE_TRY_COMPILE_TARGET_TYPE"] = "STATIC_LIBRARY"
opts[f"RUNTIMES_{target}_CMAKE_VERBOSE_MAKEFILE"] = "ON"
opts[f"RUNTIMES_{target}_CMAKE_POSITION_INDEPENDENT_CODE"] = "ON"
opts[f"RUNTIMES_{target}_LLVM_USE_LINKER"] = "lld"
opts[f"RUNTIMES_{target}_COMPILER_RT_BUILD_SANITIZERS"] = "OFF"
opts[f"RUNTIMES_{target}_COMPILER_RT_BUILD_XRAY"] = "OFF"
opts[f"RUNTIMES_{target}_COMPILER_RT_BUILD_LIBFUZZER"] = "OFF"
opts[f"RUNTIMES_{target}_COMPILER_RT_BUILD_MEMPROF"] = "OFF"
opts[f"RUNTIMES_{target}_COMPILER_RT_BUILD_ORC"] = "OFF"
opts[f"RUNTIMES_{target}_COMPILER_RT_BUILD_GWP_ASAN"] = "OFF"
opts[f"RUNTIMES_{target}_COMPILER_RT_BUILD_PROFILE"] = "ON"
opts[f"RUNTIMES_{target}_COMPILER_RT_USE_BUILTINS_LIBRARY"] = "ON"
opts[f"RUNTIMES_{target}_LIBCXX_CXX_ABI"] = "libcxxabi"
opts[f"RUNTIMES_{target}_LIBCXX_USE_COMPILER_RT"] = "ON"
opts[f"RUNTIMES_{target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY"] = "ON"
opts[f"RUNTIMES_{target}_LIBCXX_ABI_UNSTABLE"] = "ON"
opts[
f"RUNTIMES_{target}_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY"
] = "ON"
opts[
f"RUNTIMES_{target}_LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY"
] = "ON"
opts[f"RUNTIMES_{target}_LIBCXXABI_ENABLE_THREADS"] = "ON"
opts[f"RUNTIMES_{target}_LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL"] = "OFF"
opts[f"RUNTIMES_{target}_LIBCXXABI_USE_COMPILER_RT"] = "ON"
opts[f"RUNTIMES_{target}_LIBCXXABI_USE_LLVM_UNWINDER"] = "ON"
opts[f"RUNTIMES_{target}_LIBCXXABI_ENABLE_STATIC_UNWINDER"] = "ON"
opts[f"RUNTIMES_{target}_LIBUNWIND_USE_COMPILER_RT"] = "ON"
opts[f"RUNTIMES_{target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY"] = "ON"
opts[f"RUNTIMES_{target}_LIBCXXABI_ENABLE_SHARED"] = "OFF"
opts[f"RUNTIMES_{target}_LIBCXX_ABI_VERSION"] = "2"
# opts[f"RUNTIMES_{target}_CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN"] = gcc_toolchain_path
# opts[f"RUNTIMES_{target}_CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN"] = gcc_toolchain_path
llvm_dir = self.dependencies["llvm-source"].buildenv_info.vars(
self, scope="build"
)
# opts["CMAKE_CXX_FLAGS"] = f"{envs.get('CXXFLAGS', '')} -g -g3 -Wl,-fuse-ld=lld"
# opts["CMAKE_C_FLAGS"] = f"{envs.get('CFLAGS', '')} -g -g3 -Wl,-fuse-ld=lld"
# opts["CMAKE_EXE_LINKER_FLAGS"] = f"{envs.get('LDFLAGS', '')} -static-libgcc"
# opts[
# "CMAKE_SHARED_LINKER_FLAGS"
# ] = f"{envs.get('LDFLAGS', '')} -L{zlib_lib} -Bstatic -lz"
build_dir = os.path.join(self.build_folder, "build")
os.makedirs(build_dir)
@ -166,12 +232,40 @@ class ClangBootstrap(ConanFile):
build_script_folder=os.path.join(llvm_dir["LLVM_SOURCE_DIR"], "llvm"),
)
# cm.build(target="install-distribution-stripped")
cm.build(target="install-distribution")
# cm.build(target="install-compiler-rt")
cm.build(target="install-distribution-stripped")
# cm.build(target="install-runtimes-stripped")
# cm.build(target="install-compiler-rt-stripped")
# cm.build(target="install-cxx-stripped")
# cm.build(target="install-cxxabi-stripped")
shutil.copy(
f"{self.build_folder}/bin/clang-tblgen",
os.path.join(self.package_folder, "bin"),
)
shutil.rmtree("build")
def package_info(self):
bindir = Path(os.path.join(self.package_folder, "bin"))
clang_lib_dir = Path(
os.path.join(
self.package_folder, "lib", "clang", get_version("llvm_major"), "lib"
)
)
self.runenv_info.prepend_path(
"PATH",
str(bindir),
)
self.buildenv_info.define("LIBCC_GNU", str(clang_lib_dir / self.gnu_triple))
self.buildenv_info.define("LIBCC_MUSL", str(clang_lib_dir / self.musl_triple))
self.buildenv_info.define("CC", str(bindir / "clang"))
self.buildenv_info.define("CXX", str(bindir / "clang++"))
self.buildenv_info.define("AR", str(bindir / "llvm-ar"))
self.buildenv_info.define("NM", str(bindir / "llvm-nm"))
self.buildenv_info.define("RANLIB", str(bindir / "llvm-ranlib"))
self.buildenv_info.define("BOOTSTRAP_GNU_BUILD_TRIPLE", self.gnu_triple)
self.runenv_info.define("BOOTSTRAP_GNU_BUILD_TRIPLE", self.gnu_triple)
self.buildenv_info.define("BOOTSTRAP_MUSL_BUILD_TRIPLE", self.musl_triple)
self.runenv_info.define("BOOTSTRAP_MUSL_BUILD_TRIPLE", self.musl_triple)

View File

@ -19,13 +19,12 @@ from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get
from conf.versions import *
from conf.utils import with_static_flags
from conf.utils import with_static_flags, get_version
class Cmake(ConanFile):
name = "cmake"
version = CMAKE_VERSION
version = get_version("cmake")
settings = "os", "arch", "build_type", "compiler"
def source(self):

View File

@ -0,0 +1,41 @@
# 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 os
import shutil
from pathlib import Path
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get
from conf.utils import with_static_flags, current_dir, get_version
class KernelHeaders(ConanFile):
name = "kernel-headers"
settings = "os", "arch"
version = get_version("kernel")
def source(self):
get(
self,
f"https://github.com/torvalds/linux/archive/v{self.version}.tar.gz",
)
def build(self):
with current_dir(f"linux-{self.version}"):
self.run(f"make headers_install INSTALL_HDR_PATH={self.package_folder}")

View File

@ -0,0 +1,81 @@
# 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 os
import shutil
from pathlib import Path
from conan import ConanFile
from conan.tools.gnu import AutotoolsToolchain, Autotools
from conan.tools.files import get
from conf.utils import current_dir, get_version
class Musl(ConanFile):
name = "musl"
settings = "os", "arch", "build_type"
version = get_version("musl")
def build_requirements(self):
self.requires(
f"kernel-headers/{get_version('kernel')}@{self.user}/{self.channel}"
)
self.tool_requires(
f"clang-bootstrap/{get_version('llvm')}@{self.user}/{self.channel}"
)
@property
def target(self):
return os.environ["TARGET"]
def source(self):
get(
self,
f"https://git.musl-libc.org/cgit/musl/snapshot/musl-{self.version}.tar.gz",
)
def generate(self):
tc = AutotoolsToolchain(self, prefix=f"{self.package_folder}/")
env = tc.environment()
buildenv = self.dependencies.build["clang-bootstrap"].buildenv_info.vars(self)
tc.update_configure_args(
{
"--enable-shared": "",
"--enable-static": "",
"--disable-wrapper": "",
"--enable-optimize": "",
}
)
libcc_dir = Path(buildenv["LIBCC_GNU"])
if "musl" in self.target:
libcc_dir = Path(buildenv["LIBCC_MUSL"])
env.define("LIBCC", str(libcc_dir / "libclang_rt.builtins.a"))
# We will strip the debug data later
tc.extra_cflags = ["-g", f"--target={self.target}"]
tc.generate(env)
def build(self):
autotools = Autotools(self)
autotools.configure(
build_script_folder=f"{self.source_folder}/musl-{self.version}/"
)
autotools.make()
autotools.make(target="install")

View File

@ -19,20 +19,16 @@ from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get
from conf.versions import *
from conf.utils import with_static_flags
from conf.utils import with_static_flags, get_version
class Ninja(ConanFile):
name = "ninja"
version = NINJA_VERSION
settings = "os", "arch", "build_type", "compiler"
version = get_version("ninja")
def requirements(self):
# if self.settings.compiler == "gcc":
# self.tool_requires(f"gcc/latest@{self.user}/{self.channel}")
self.tool_requires(f"cmake/{CMAKE_VERSION}@{self.user}/{self.channel}")
self.tool_requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
def source(self):
get(

View File

@ -19,19 +19,19 @@ from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy
from conf.versions import *
from conf.utils import get_version
class Zlib(ConanFile):
name = "zlib"
version = ZLIB_VERSION
version = get_version("zlib")
settings = "os", "arch", "build_type", "compiler"
exports = "*.cmake"
cmake_setup_file = "zlib_setup.cmake"
def requirements(self):
self.tool_requires(f"cmake/{CMAKE_VERSION}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{NINJA_VERSION}@{self.user}/{self.channel}")
def build_requirements(self):
self.tool_requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{get_version('ninja')}@{self.user}/{self.channel}")
def source(self):
get(

View File

@ -19,19 +19,18 @@ from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy
from conf.versions import *
from conf.utils import get_version
class Zstd(ConanFile):
name = "zstd"
version = ZSTD_VERSION
version = get_version("zstd")
settings = "os", "arch", "build_type", "compiler"
exports = "*.cmake"
cmake_setup_file = "zlib_setup.cmake"
def requirements(self):
self.tool_requires(f"cmake/{CMAKE_VERSION}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{NINJA_VERSION}@{self.user}/{self.channel}")
def build_requirements(self):
self.tool_requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{get_version('ninja')}@{self.user}/{self.channel}")
def source(self):
get(
@ -47,7 +46,6 @@ class Zstd(ConanFile):
deps.generate()
def build(self):
print("AAAA ", self.settings.compiler)
cmake = CMake(self)
cmake.configure(
{
@ -64,7 +62,6 @@ class Zstd(ConanFile):
cmake.install()
def package_info(self):
# self.cpp_info.set_property("cmake_build_modules", [self.cmake_setup_file])
self.cpp_info.set_property("cmake_find_mode", "module")
self.cpp_info.set_property("cmake_file_name", "zstd::libzstd_static")
self.cpp_info.set_property("cmake_target_name", "zstd::libzstd_static")

1
profiles/common Normal file
View File

@ -0,0 +1 @@
{% set LLVM_VERSION = os.getenv("LLVM_VERSION") %}

View File

@ -1,3 +1,5 @@
include(common)
[settings]
os=Linux
arch=x86_64

26
profiles/stage1 Normal file
View File

@ -0,0 +1,26 @@
{% set LLVM_VERSION = os.getenv("LLVM_VERSION") %}
[settings]
os=Linux
arch=x86_64
build_type=Release
compiler=clang
compiler.version=17
compiler.libcxx=libc++
clang-bootstrap/*:compiler=gcc
clang-bootstrap/*:compiler.version=12.2
clang-bootstrap/*:compiler.libcxx=libstdc++
# [tool_requires]
# musl/*:clang-bootstrap/{{ LLVM_VERSION }}@serene/stable
[buildenv]
LD=lld
[runenv]
STAGE="1"
[conf]
tools.cmake.cmaketoolchain:generator=Ninja