Compare commits

...

6 Commits

13 changed files with 510 additions and 52 deletions

19
builder
View File

@ -52,6 +52,7 @@ function _conan() {
function _create() {
_conan create --user "$user" --channel "$channel" \
--profile:host="../../profiles/stage$1" \
--profile:build="../../profiles/stage$1" \
. "${@:2}"
}
@ -61,9 +62,13 @@ function _build() {
_pop
}
function llvm-source() { ## Build the llvm source pkg
_push "packages/sources/llvm/"
_create "$@"
_conan create --user "$user" --channel "$channel" \
--profile:host="../../../profiles/stage$1" \
--profile:build="../../../profiles/stage$1" \
. "${@:2}"
_pop
}
@ -83,6 +88,18 @@ function ninja() { ## Build the gcc package
_build ninja "$@"
}
function zlib() { ## Build the zlib package
_build zlib "$@"
}
function zstd() { ## Build the zstd package
_build zstd "$@"
}
function clang-bootstrap() { ## Build the gcc package
_build clang-bootstrap "$@"
}
function help() { ## Print out this help message
echo "Commands:"
grep -E '^function [a-zA-Z0-9_-]+\(\) \{ ## .*$$' "$0" | \

40
conf/utils.py Normal file
View File

@ -0,0 +1,40 @@
# 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
class current_dir:
def __init__(self, path):
self.current = os.getcwd()
self.target = path
def __enter__(self):
print(f"Entering dir: {self.target} from: {self.current}")
os.chdir(self.target)
return self
def __exit__(self, exc_type, exc_value, exc_traceback):
print(f"Exiting dir: {self.target}")
os.chdir(self.current)
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', '')}"
cmake_vars[
"CMAKE_EXE_LINKER_FLAGS_INIT"
] = f"-static {cmake_vars.get('CMAKE_EXE_LINKER_FLAGS_INIT', '')}"
return cmake_vars

View File

@ -14,4 +14,8 @@
# 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"
LLVM_VERSION = "0e0db0a4d7fd606ee58595f997142f7f2476cbe6"
CMAKE_VERSION = "3.26.0"
NINJA_VERSION = "1.11.1"
ZLIB_VERSION = "1.2.13"
ZSTD_VERSION = "1.5.4"

View File

@ -0,0 +1,177 @@
# 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.versions import *
from conf.utils import with_static_flags, current_dir
PROJECTS = [
"clang",
"lld",
]
TOOLCHAIN_TARGETS = [
"clang-resource-headers",
"clang",
"lld",
"llvm-ar",
"llvm-config",
"llvm-nm",
"llvm-objcopy",
"llvm-profdata",
"llvm-ranlib",
"llvm-strip",
"llvm-tblgen",
"llvm-strip",
"llvm-readelf",
"llvm-windres",
"LTO",
"llvm-lipo",
]
RUNTIME_TARGETS = [
"compiler-rt",
"libcxx",
"libcxxabi",
"libunwind",
]
CMAKE_OPTIONS = {
"CLANG_DEFAULT_CXX_STDLIB": "libc++",
"CLANG_DEFAULT_OBJCOPY": "llvm-objcopy",
"CLANG_DEFAULT_RTLIB": "compiler-rt",
"CLANG_DEFAULT_UNWINDLIB": "libunwind",
"CLANG_DEFAULT_LINKER": "lld",
"LLVM_USE_LINKER": "lld",
"CLANG_VENDOR_UTI": "serene.stage0",
"LLVM_ENABLE_NEW_PASS_MANAGER": "ON",
"LLVM_BUILD_TESTS": "OFF",
"LLVM_ENABLE_ASSERTIONS": "OFF",
"LLVM_ENABLE_LIBXML2": "OFF",
"LLVM_ENABLE_TERMINFO": "OFF",
"LLVM_ENABLE_ZLIB": "FORCE_ON",
"LLVM_INCLUDE_BENCHMARKS": "OFF",
"LLVM_INCLUDE_EXAMPLES": "OFF",
"LLVM_INCLUDE_TESTS": "OFF",
"LLVM_INCLUDE_GO_TESTS": "OFF",
"LLVM_ENABLE_BINDINGS": "OFF",
"LLVM_TARGETS_TO_BUILD": "X86",
"LLVM_STATIC_LINK_CXX_STDLIB": "ON",
"PACKAGE_VENDOR": "serene.stage0",
"LLVM_ENABLE_PER_TARGET_RUNTIME_DIR": "OFF",
"ENABLE_X86_RELAX_RELOCATIONS": "ON",
"BUILD_SHARED_LIBS": "OFF",
"CLANG_ENABLE_BOOTSTRAP": "ON",
# "LLVM_DEFAULT_TARGET_TRIPLE": "x86_64-pc-linux-musl",
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY": "ON",
"LIBCXXABI_ENABLE_SHARED": "OFF",
"LIBCXX_ABI_VERSION": "2",
"LLVM_CCACHE_BUILD": "ON",
"LLVM_ENABLE_LTO": "OFF",
# Common
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
}
class ClangBootstrap(ConanFile):
name = "clang-bootstrap"
settings = "os", "arch", "compiler", "build_type"
version = LLVM_VERSION
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}")
def build_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"ninja/{NINJA_VERSION}@{self.user}/{self.channel}")
def generate(self):
tc = CMakeToolchain(self)
tc.generate()
deps = CMakeDeps(self)
deps.set_property("zlib", "cmake_find_mode", "both")
deps.generate()
def build(self):
opts = CMAKE_OPTIONS
# opts["CMAKE_C_COMPILER"] = self.settings.compiler
# opts["CMAKE_CXX_COMPILER"] = self.settings.compiler
opts["LLVM_ENABLE_PROJECTS"] = ";".join(PROJECTS)
opts["LLVM_ENABLE_RUNTIMES"] = ";".join(RUNTIME_TARGETS)
opts["LLVM_DISTRIBUTION_COMPONENTS"] = ";".join(TOOLCHAIN_TARGETS)
# opts["LLVM_RUNTIME_DISTRIBUTION_COMPONENTS"] = "cxx-headers"
zlibdir = self.dependencies["zlib"]
zlib_include = zlibdir.cpp_info.includedir
zlib_lib = zlibdir.cpp_info.libdir
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"
llvm_dir = self.dependencies["llvm-source"].buildenv_info.vars(
self, scope="build"
)
build_dir = os.path.join(self.build_folder, "build")
os.makedirs(build_dir)
with current_dir(build_dir):
cm = CMake(self)
cm.configure(
# We do not want `-static` with llvm eventhough we want to build
# clan statically. That flag will ruin some of the shared libs that
# has to be built for clang
opts,
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")
shutil.copy(
f"{self.build_folder}/bin/clang-tblgen",
os.path.join(self.package_folder, "bin"),
)
shutil.rmtree("build")

View File

@ -13,24 +13,21 @@
#
# 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
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get
import os
from conf.versions import *
from conf.utils import with_static_flags
class Cmake(ConanFile):
name = "cmake"
version = "3.26.0"
version = CMAKE_VERSION
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,
@ -46,7 +43,12 @@ class Cmake(ConanFile):
def build(self):
cmake = CMake(self)
cmake.configure(
{"CMAKE_USE_OPENSSL": "OFF", "BUILD_TESTING": "OFF"},
with_static_flags(
{
"CMAKE_USE_OPENSSL": "OFF",
"BUILD_TESTING": "OFF",
}
),
build_script_folder=f"CMake-{self.version}",
)
cmake.build()

View File

@ -1,17 +0,0 @@
# 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 "")

View File

@ -13,25 +13,26 @@
#
# 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
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get
import os
from conf.versions import *
from conf.utils import with_static_flags
class Ninja(ConanFile):
name = "ninja"
version = "1.11.1"
version = NINJA_VERSION
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}")
# if self.settings.compiler == "gcc":
# self.tool_requires(f"gcc/latest@{self.user}/{self.channel}")
self.tool_requires(f"cmake/3.26.0@{self.user}/{self.channel}")
self.tool_requires(f"cmake/{CMAKE_VERSION}@{self.user}/{self.channel}")
def source(self):
get(
@ -55,8 +56,8 @@ class Ninja(ConanFile):
def build(self):
cmake = CMake(self)
cmake.configure(
{},
build_script_folder=f"Ninja-{self.version}",
with_static_flags({}),
build_script_folder=f"ninja-{self.version}",
)
cmake.build()
cmake.install()

View File

@ -24,14 +24,18 @@ class LLVM(ConanFile):
name = "llvm-source"
version = LLVM_VERSION
settings = "os", "arch"
tc_type = "cross"
def source(self):
def build(self):
get(
self,
f"https://github.com/llvm/llvm-project/archive/{self.version}.tar.gz",
destination=self.package_folder,
strip_root=True,
filename=f"llvm.tar.gz",
)
def build(self):
pass
def package_info(self):
self.buildenv_info.define(
"LLVM_SOURCE_DIR",
self.package_folder,
)

View File

@ -0,0 +1,69 @@
# 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
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get
from conf.versions import *
class Zlib(ConanFile):
name = "zlib"
version = ZLIB_VERSION
settings = "os", "arch", "build_type", "compiler"
def requirements(self):
if self.settings.compiler == "clang":
self.requires(f"clang-bootstrap/{LLVM_VERSION}@{self.user}/{self.channel}")
elif self.settings.compiler == "gcc":
self.requires(f"gcc/latest@{self.user}/{self.channel}")
self.tool_requires(f"gcc/latest@{self.user}/{self.channel}")
self.requires(f"cmake/{CMAKE_VERSION}@{self.user}/{self.channel}")
self.requires(f"ninja/{NINJA_VERSION}@{self.user}/{self.channel}")
def source(self):
get(
self,
f"https://github.com/zlib-ng/zlib-ng/archive/{self.version}.tar.gz",
)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = False
tc.generate()
deps = CMakeDeps(self)
deps.generate()
def build(self):
cmake = CMake(self)
cmake.configure(
{"BUILD_SHARED_LIBS": False, "ZLIB_COMPAT": True},
build_script_folder=f"zlib-ng-{self.version}",
)
cmake.build()
cmake.install()
def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "ZLIB")
self.cpp_info.set_property("cmake_target_name", "ZLIB::ZLIB")
self.cpp_info.set_property("pkg_config_name", "zlib")
self.cpp_info.libs = ["z"]
self.cpp_info.set_property("cmake_find_package", "ZLIB")
self.cpp_info.set_property("cmake_find_package_multi", "ZLIB")

View File

@ -0,0 +1,92 @@
# 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
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy
from conf.versions import *
class Zlib(ConanFile):
name = "zlib"
version = ZLIB_VERSION
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 source(self):
get(
self,
f"https://github.com/madler/zlib/archive/v{self.version}.tar.gz",
)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = False
tc.generate()
deps = CMakeDeps(self)
deps.generate()
def build(self):
cmake = CMake(self)
cmake.configure(
{
"BUILD_SHARED_LIBS": False,
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
},
build_script_folder=f"zlib-{self.version}",
)
# cmake.build()
self.run("ninja zlibstatic")
# cmake.install()
def package(self):
copy(self, "*.a", self.build_folder, os.path.join(self.package_folder, "lib"))
copy(self, self.cmake_setup_file, self.recipe_folder, self.package_folder)
copy(
self,
"zconf.h",
self.build_folder,
os.path.join(self.package_folder, "include"),
)
copy(
self,
"zlib.h",
os.path.join(self.build_folder, f"zlib-{self.version}"),
os.path.join(self.package_folder, "include"),
)
copy(
self,
"zlib.pc",
self.build_folder,
os.path.join(self.package_folder, "share", "pkgconfig"),
)
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", "ZLIB")
self.cpp_info.set_property("cmake_target_name", "ZLIB::ZLIB")
self.cpp_info.set_property("pkg_config_name", "zlib")
self.cpp_info.libs = ["z"]
self.cpp_info.set_property("cmake_find_package", "ZLIB")
self.cpp_info.set_property("cmake_find_package_multi", "ZLIB")

View File

@ -0,0 +1,2 @@
message(STATUS "AAAA ${zlib_INCLUDE_DIRS_RELEASE} -- ${CMAKE_FIND_LIBRARY_SUFFIXES}")
set_target_properties(ZLIB::ZLIB PROPERTIES LOCATION ${zlib_LIB_DIRS_RELEASE}/libz.a)

View File

@ -0,0 +1,74 @@
# 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
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy
from conf.versions import *
class Zstd(ConanFile):
name = "zstd"
version = ZSTD_VERSION
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 source(self):
get(
self,
f"https://github.com/facebook/zstd/archive/v{self.version}.tar.gz",
)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = False
tc.generate()
deps = CMakeDeps(self)
deps.generate()
def build(self):
print("AAAA ", self.settings.compiler)
cmake = CMake(self)
cmake.configure(
{
"CMAKE_C_COMPILER": self.settings.compiler,
"CMAKE_CXX_COMPILER": self.settings.compiler,
"BUILD_SHARED_LIBS": False,
"ZSTD_BUILD_STATIC": True,
"ZSTD_BUILD_SHARED": False,
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
},
build_script_folder=f"zstd-{self.version}/build/cmake/",
)
cmake.build()
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")
self.cpp_info.set_property("pkg_config_name", "zstd")
self.cpp_info.libs = ["zstd"]
self.cpp_info.set_property("cmake_find_package", "zstd::libzstd_static")
self.cpp_info.set_property("cmake_find_package_multi", "zstd::libzstd_static")

View File

@ -1,21 +1,14 @@
{% 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
compiler.version=12.2
compiler.libcxx=libstdc++
[buildenv]
CC={{ gcc_triple }}-gcc
CXX={{ gcc_triple }}-g++
LD={{ gcc_triple }}-ld
CFLAGS=-static
CXXFLAGS=-static
LDFLAGS=-static
LD=lld
[conf]
tools.cmake.cmaketoolchain:generator=Ninja