Compare commits

...

6 Commits

19 changed files with 745 additions and 140 deletions

18
builder
View File

@ -47,6 +47,7 @@ KERNEL_VERSION="5.0"
MUSL_VERSION="1.2.3"
TARGET=x86_64-pc-linux-musl
BUILD_TARGET=x86_64-build-linux-musl
export LLVM_VERSION \
CMAKE_VERSION \
@ -56,7 +57,8 @@ export LLVM_VERSION \
KERNEL_VERSION \
LLVM_MAJOR_VERSION \
MUSL_VERSION \
TARGET
TARGET \
BUILD_TARGET
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
@ -66,7 +68,7 @@ source "$ME/scripts/utils.sh"
user="serene"
channel="stable"
function _conan() {
function _conan() { ## A conan wrapper
PYTHONPATH="$ME:$PYTHONPATH" conan "$@"
}
@ -84,6 +86,18 @@ function _build() {
}
function graph() { ## Generate the dependency graph
_push "packages/$1/"
_conan graph info \
--user "$user" --channel "$channel" -v \
--profile:host="../../profiles/stage$2" \
--profile:build="../../profiles/stage$2" \
conanfile.py \
"${@:3}"
_pop
}
function llvm-source() { ## Build the llvm source pkg
_push "packages/sources/llvm/"
_conan create --user "$user" --channel "$channel" \

0
conf/base/__init__.py Normal file
View File

Binary file not shown.

90
conf/base/zlib.py Normal file
View File

@ -0,0 +1,90 @@
# 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.utils import get_version, with_musl_toolchain
class ZlibBase(ConanFile):
version = get_version("zlib")
settings = "os", "arch", "build_type", "compiler"
exports = "*.cmake"
cmake_setup_file = "zlib_setup.cmake"
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(
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
# with_musl_toolchain(self, tc)
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}",
)
self.run("ninja zlibstatic")
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")

72
conf/base/zstd.py Normal file
View File

@ -0,0 +1,72 @@
# 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.utils import get_version
class ZstdBase(ConanFile):
version = get_version("zstd")
settings = "os", "arch", "build_type", "compiler"
exports = "*.cmake"
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(
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
# with_musl_toolchain(self, tc)
tc.generate()
deps = CMakeDeps(self)
deps.generate()
def build(self):
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_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

@ -80,9 +80,18 @@ def with_static_flags(cmake_vars):
return cmake_vars
def with_musl_toolchain(conanfile, tc):
if conanfile.options.libc == "musl":
target = os.environ["TARGET"]
def with_musl_toolchain(conanfile, tc, envname="TARGET"):
target = os.environ[envname]
tc.variables["CMAKE_C_COMPILER_TARGET"] = target
tc.variables["CMAKE_CXX_COMPILER_TARGET"] = target
tc.variables["CMAKE_C_COMPILER_TARGET"] = target
tc.variables["CMAKE_CXX_COMPILER_TARGET"] = target
def copy_template(conanfile, src, dest, varmap):
result = Path(src).read_text()
target_file = Path(dest)
for k, v in varmap.items():
result = result.replace(f"@{k}@", str(v))
target_file.write_text(result)

View File

@ -96,17 +96,25 @@ CMAKE_OPTIONS = {
class ClangBootstrap(ConanFile):
name = "clang-bootstrap"
settings = "os", "arch", "compiler", "build_type"
settings = "os", "arch", "build_type"
version = get_version("llvm")
gnu_triple = "x86_64-build-linux-gnu"
musl_triple = "x86_64-build-linux-musl"
musl_triple = os.environ["TARGET"]
def build_requirements(self):
self.requires(f"llvm-source/{self.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.requires(
f"zlib-bootstrap/{get_version('zlib')}@{self.user}/{self.channel}",
visible=False,
transitive_libs=False,
)
self.requires(
f"zstd-bootstrap/{get_version('zstd')}@{self.user}/{self.channel}",
visible=False,
transitive_libs=False,
)
self.tool_requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{get_version('ninja')}@{self.user}/{self.channel}")
@ -136,7 +144,7 @@ class ClangBootstrap(ConanFile):
# opts["LLVM_RUNTIME_DISTRIBUTION_COMPONENTS"] = "cxx-headers"
zlibdir = self.dependencies["zlib"]
zlibdir = self.dependencies["zlib-bootstrap"]
zlib_include = zlibdir.cpp_info.includedir
zlib_lib = zlibdir.cpp_info.libdir
opts["CMAKE_REQUIRED_INCLUDES"] = zlib_include
@ -256,6 +264,8 @@ class ClangBootstrap(ConanFile):
"PATH",
str(bindir),
)
self.buildenv_info.define("CLANG_BOOTSTRAP_PATH", self.package_folder)
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"))

View File

@ -25,7 +25,7 @@ from conf.utils import with_static_flags, get_version
class Cmake(ConanFile):
name = "cmake"
version = get_version("cmake")
settings = "os", "arch", "build_type", "compiler"
settings = "os", "arch", "build_type"
def source(self):
get(

View File

@ -0,0 +1,309 @@
# 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
TOOLCHAIN_TARGETS = [
"runtimes",
# lldb,
"compiler-rt",
]
PROJECTS = [
# "clang-tools-extra",
# "clang",
# "lld",
# "llvm",
# "mlir",
# "lldb"
]
RUNTIME_TARGETS = [
"compiler-rt",
"libcxx",
"libcxxabi",
"libunwind",
]
CMAKE_OPTIONS = {
"LLVM_USE_LINKER": "lld",
"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": "Plex",
"LLVM_ENABLE_PER_TARGET_RUNTIME_DIR": "ON",
"ENABLE_X86_RELAX_RELOCATIONS": "ON",
"BUILD_SHARED_LIBS": "OFF",
"CLANG_ENABLE_BOOTSTRAP": "ON",
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY": "ON",
"LIBCXXABI_ENABLE_SHARED": "OFF",
"LIBCXX_ABI_VERSION": "2",
"LLVM_CCACHE_BUILD": "ON",
"LLVM_ENABLE_LTO": "THIN",
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
"CLANG_DEFAULT_CXX_STDLIB": "libc++",
"CLANG_DEFAULT_LINKER": "lld",
"CLANG_DEFAULT_OBJCOPY": "llvm-objcopy",
"CLANG_DEFAULT_RTLIB": "compiler-rt",
"CLANG_VENDOR_UTI": "serene.stage0",
"LLVM_ENABLE_LIBCXX": "ON",
"LLVM_ENABLE_ZSTD": "OFF",
"LLVM_OPTIMIZED_TABLEGEN": "ON",
"LLVM_THINLTO_CACHE_PATH": "/tmp/llvm-build-lto",
"LLVM_ENABLE_PROJECTS": ";".join(PROJECTS),
"LLVM_CCACHE_BUILD": "ON",
"LIBCXX_HAS_MUSL_LIBC": "ON",
"LLVM_DEFAULT_TARGET_TRIPLE": os.environ["TARGET"],
"LIBCXX_CXX_ABI": "libcxxabi",
"LIBCXX_USE_COMPILER_RT": "ON",
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY": "ON",
"LIBCXX_ABI_UNSTABLE": "ON",
"LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY": "ON",
"LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY": "ON",
"LIBCXX_ABI_VERSION": "2",
"LIBCXX_HAS_MUSL_LIBC": "ON",
# musl doesn't have -latomic
"LIBCXX_HAS_ATOMIC_LIB": "OFF",
"LIBCXXABI_ENABLE_THREADS": "ON",
"LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL": "OFF",
"LIBCXXABI_USE_COMPILER_RT": "ON",
"LIBCXXABI_USE_LLVM_UNWINDER": "ON",
"LIBCXXABI_ENABLE_STATIC_UNWINDER": "ON",
"LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY": "ON",
"LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY": "ON",
"LIBCXXABI_ENABLE_SHARED": "OFF",
"CMAKE_C_COMPILER_TARGET": os.environ["TARGET"],
"CMAKE_CXX_COMPILER_TARGET": os.environ["TARGET"],
"CMAKE_ASM_COMPILER_TARGET": os.environ["TARGET"],
# Common
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
}
class LibCXX(ConanFile):
name = "libcxx"
settings = "os", "arch", "compiler", "build_type"
version = get_version("llvm")
def build_requirements(self):
self.requires(f"llvm-source/{self.version}@{self.user}/{self.channel}")
self.requires(
f"stage1-sysroot/{get_version('llvm')}@{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}")
@property
def buildenv(self):
return self.buildenv_info.vars(self, scope="build")
def add_compiler_options(self, opts):
tc_dir = Path(self.dependencies["stage1-sysroot"].package_folder)
opts["CMAKE_C_COMPILER"] = str(tc_dir / "bin" / "clang")
opts["CMAKE_CXX_COMPILER"] = str(tc_dir / "bin" / "clang++")
opts["LLVM_CONFIG_PATH"] = str(tc_dir / "bin" / "llvm-config")
target = os.environ["TARGET"]
opts["CMAKE_C_COMPILER_TARGET"] = target
opts["CMAKE_CXX_COMPILER_TARGET"] = target
opts["CMAKE_SYSROOT"] = str(tc_dir)
opts["CMAKE_EXE_LINKER_FLAGS"] = f"-Wl,-rpath,{str(tc_dir)}/lib/{target}"
opts["CMAKE_SHARED_LINKER_FLAGS"] = f"-Wl,-rpath,{str(tc_dir)}/lib/{target}"
# opts["CMAKE_C_FLAGS"] = "-v"
# opts["CMAKE_CXX_FLAGS"] = "-v"
def add_runtimes_and_builtins(self, opts):
builtin_targets = []
target = os.environ["TARGET"]
sysroot_path = Path(self.dependencies["stage1-sysroot"].package_folder)
target_builtin_opts = {
"CMAKE_SYSTEM_NAME": "Linux",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_SYSTEM_PROCESSOR": "X86_64",
"CMAKE_C_FLAGS": self.buildenv.get("CFLAGS", ""),
"CMAKE_CXX_FLAGS": self.buildenv.get("CXXFLAGS", ""),
"CMAKE_ASM_FLAGS": self.buildenv.get("ASFLAGS", ""),
"CMAKE_C_COMPILER_TARGET": target,
"CMAKE_CXX_COMPILER_TARGET": target,
"CMAKE_ASM_COMPILER_TARGET": target,
"CMAKE_TRY_COMPILE_TARGET_TYPE": "STATIC_LIBRARY",
"CMAKE_EXE_LINKER_FLAGS": f"--target={target} {self.buildenv.get('LDFLAGS', '')}",
"CMAKE_SHARED_LINKER_FLAGS": f"--target={target} {self.buildenv.get('LDFLAGS', '')}",
"CMAKE_SYSROOT": str(sysroot_path),
"CMAKE_INSTALL_RPATH": "\$ORIGIN/../lib",
"CMAKE_BUILD_WITH_INSTALL_RPATH": "ON",
"LLVM_USE_LINKER": "lld",
"COMPILER_RT_BAREMETAL_BUILD": "ON",
"COMPILER_RT_DEFAULT_TARGET_ONLY": "ON",
"LLVM_CCACHE_BUILD": opts["LLVM_CCACHE_BUILD"],
}
for k, v in target_builtin_opts.items():
opts[f"BUILTINS_{target}_{k}"] = v
target_runtime_opts = {
"CMAKE_SYSTEM_NAME": "Linux",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_C_FLAGS": self.buildenv.get("CFLAGS", ""),
"CMAKE_CXX_FLAGS": self.buildenv.get("CXXFLAGS", ""),
"CMAKE_ASM_FLAGS": self.buildenv.get("ASFLAGS", ""),
"CMAKE_C_COMPILER_TARGET": target,
"CMAKE_CXX_COMPILER_TARGET": target,
"CMAKE_ASM_COMPILER_TARGET": target,
"CMAKE_TRY_COMPILE_TARGET_TYPE": "STATIC_LIBRARY",
"CMAKE_EXE_LINKER_FLAGS": f"--target={target} {self.buildenv.get('LDFLAGS', '')}",
"CMAKE_SHARED_LINKER_FLAGS": f"--target={target} {self.buildenv.get('LDFLAGS', '')}",
"CMAKE_INSTALL_RPATH": "\$ORIGIN/../lib",
"CMAKE_BUILD_WITH_INSTALL_RPATH": "ON",
"CMAKE_SYSROOT": str(sysroot_path),
"CMAKE_VERBOSE_MAKEFILE": "ON",
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
"LLVM_USE_LINKER": "lld",
"LLVM_USE_LTO": "ON",
"LLVM_CCACHE_BUILD": opts["LLVM_CCACHE_BUILD"],
# TODO: Check for more sanitizers that work with musl
"COMPILER_RT_SANITIZERS_TO_BUILD": "asan;msan;tsan",
"COMPILER_RT_USE_BUILTINS_LIBRARY": "ON",
"COMPILER_RT_USE_LIBCXX": "ON",
"COMPILER_RT_BUILD_SANITIZERS": "ON",
# For some reason this flag is not correctly set if we don't
# manually set it and some strange gnu only LDFLAGS are injected.
"COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT": "OFF",
# X-Ray doesn't seem to compiler with musl
"COMPILER_RT_BUILD_XRAY": "OFF",
# Only build these if we enable sanitizers since they depend
# on the sanitizer common runtime
"COMPILER_RT_BUILD_MEMPROF": "ON",
"COMPILER_RT_BUILD_LIBFUZZER": "ON",
# ORC is the JIT component of LLVM - we don't need that.
"COMPILER_RT_BUILD_ORC": "OFF",
# Make sure we use libc++ from the tree instead from the system.
"SANITIZER_CXX_ABI": "libc++",
"SANITIZER_CXX_ABI_INTREE": "ON",
"LIBCXX_CXX_ABI": "libcxxabi",
"LIBCXX_USE_COMPILER_RT": "ON",
"LIBCXX_ENABLE_STATIC_ABI_LIBRARY": "ON",
"LIBCXX_ABI_UNSTABLE": "ON",
"LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY": "ON",
"LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY": "ON",
"LIBCXX_ABI_VERSION": "2",
"LIBCXX_HAS_MUSL_LIBC": "ON",
# musl doesn't have -latomic
"LIBCXX_HAS_ATOMIC_LIB": "OFF",
"LIBCXXABI_ENABLE_THREADS": "ON",
"LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL": "OFF",
"LIBCXXABI_USE_COMPILER_RT": "ON",
"LIBCXXABI_USE_LLVM_UNWINDER": "ON",
"LIBCXXABI_ENABLE_STATIC_UNWINDER": "ON",
"LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY": "ON",
"LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY": "ON",
"LIBCXXABI_ENABLE_SHARED": "OFF",
"LIBUNWIND_USE_COMPILER_RT": "ON",
}
for k, v in target_runtime_opts.items():
opts[f"RUNTIMES_{target}_{k}"] = v
opts["LLVM_RUNTIME_TARGETS"] = target
opts["LLVM_BUILTIN_TARGETS"] = target
opts["LLVM_ENABLE_RUNTIMES"] = ";".join(RUNTIME_TARGETS)
def generate(self):
tc = CMakeToolchain(self)
tc.preprocessor_definitions["_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE"] = ""
tc.preprocessor_definitions["_LIBCPP_HAS_MUSL_LIBC"] = "ON"
tc.generate()
deps = CMakeDeps(self)
deps.set_property("zlib", "cmake_find_mode", "both")
deps.generate()
def build(self):
opts = CMAKE_OPTIONS.copy()
sysroot = self.dependencies["stage1-sysroot"].package_folder
self.add_compiler_options(opts)
# zlib_dir = self.dependencies["zlib"].package_folder
opts["ZLIB_ROOT"] = sysroot
opts[
"CMAKE_REQUIRED_INCLUDES"
] = f"{sysroot}/lib/clang/17/include {sysroot}/include"
opts["CMAKE_REQUIRED_LIBRARIES"] = f"-L{sysroot}/lib -lz"
self.add_runtimes_and_builtins(opts)
for target in opts["LLVM_RUNTIME_TARGETS"].split(";"):
extra_target = None
bin_dir = Path(self.package_folder) / "bin"
bin_dir.mkdir(exist_ok=True, parents=True)
opts["LLVM_ENABLE_PROJECTS"] = ";".join(PROJECTS)
opts["LLVM_DISTRIBUTION_COMPONENTS"] = ";".join(TOOLCHAIN_TARGETS)
stage1 = Path(self.dependencies["stage1-sysroot"].package_folder)
opts["LLVM_TABLEGEN"] = str(stage1 / "bin" / "llvm-tblgen")
opts["CLANG_TABLEGEN"] = str(stage1 / "bin" / "clang-tblgen")
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(
opts,
build_script_folder=os.path.join(
llvm_dir["LLVM_SOURCE_DIR"], "runtimes"
),
)
cm.build(target="cxx")
cm.build(target="cxxabi")
cm.build(target="unwind")
cm.build(target="install-cxx")
cm.build(target="install-cxxabi")
cm.build(target="install-unwind")
# cm.build(target="install-distribution-stripped", args=["-v"])
def package_info(self):
# self.buildenv_info.PATH.append(os.path.join(self.package_folder, "bin"))
self.buildenv_info.prepend_path(
"LD_LIBRARY_PATH", os.path.join(self.package_folder, "lib")
)

View File

@ -24,7 +24,7 @@ from conf.utils import with_static_flags, get_version
class Ninja(ConanFile):
name = "ninja"
settings = "os", "arch", "build_type", "compiler"
settings = "os", "arch", "build_type"
version = get_version("ninja")
def requirements(self):

View File

@ -0,0 +1,125 @@
# 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.files import get
from conan.tools.cmake import CMakeToolchain
from conf.utils import get_version, copy_template, copy_tree
class Stage1(ConanFile):
name = "stage1-sysroot"
version = get_version("llvm")
settings = "os", "arch"
exports = ("*.cmake",)
def build_requirements(self):
self.requires(
f"clang-bootstrap/{get_version('llvm')}@{self.user}/{self.channel}"
)
self.requires(
f"zlib/{get_version('zlib')}@{self.user}/{self.channel}", visible=False
)
self.requires(
f"zstd/{get_version('zstd')}@{self.user}/{self.channel}", visible=False
)
self.requires(
f"musl/{get_version('musl')}@{self.user}/{self.channel}", visible=False
)
def build(self):
musl = self.dependencies["musl"]
clang = self.dependencies["clang-bootstrap"]
zlib = self.dependencies["zlib"]
zstd = self.dependencies["zstd"]
include_dir = Path(self.package_folder) / "include"
lib_dir = Path(self.package_folder) / "lib"
bin_dir = Path(self.package_folder) / "bin"
include_dir.mkdir(parents=True, exist_ok=True)
lib_dir.mkdir(parents=True, exist_ok=True)
bin_dir.mkdir(parents=True, exist_ok=True)
musl_include_dir = Path(musl.package_folder) / "include"
musl_lib_dir = Path(musl.package_folder) / "lib"
zstd_include_dir = Path(zstd.package_folder) / "include"
zstd_lib_dir = Path(zstd.package_folder) / "lib"
zlib_include_dir = Path(zlib.package_folder) / "include"
zlib_lib_dir = Path(zlib.package_folder) / "lib"
clang_include_dir = Path(clang.package_folder) / "include"
clang_lib_dir = Path(clang.package_folder) / "lib"
clang_bin_dir = Path(clang.package_folder) / "bin"
self.output.info(
f"Copying musl stuff: {musl_include_dir.name} -- {musl_lib_dir.name}"
)
copy_tree(musl_include_dir, include_dir)
copy_tree(musl_lib_dir, lib_dir)
copy_tree(zstd_include_dir, include_dir)
copy_tree(zstd_lib_dir, lib_dir)
copy_tree(zlib_include_dir, include_dir)
copy_tree(zlib_lib_dir, lib_dir)
self.output.info(
f"Copying clang stuff: {clang_include_dir.name} -- {clang_lib_dir.name}"
)
copy_tree(clang_include_dir, include_dir)
copy_tree(clang_lib_dir, lib_dir)
copy_tree(clang_bin_dir, bin_dir)
toolchain = f"{self.recipe_folder}/toolchain.cmake"
copy_template(
self,
toolchain,
f"{self.package_folder}/toolchain.cmake",
{"TRIPLE": os.environ["TARGET"]},
)
def package_info(self):
bindir = Path(self.package_folder) / "bin"
self.runenv_info.prepend_path(
"PATH",
str(bindir),
)
self.buildenv_info.append("sysroot", self.package_folder)
f = os.path.join(self.package_folder, "toolchain.cmake")
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 / "clang"))
self.buildenv_info.define("CXX", str(bindir / "clang++"))
self.buildenv_info.define("AR", str(bindir / "clang"))
self.buildenv_info.define("NM", str(bindir / "llvm-nm"))
self.buildenv_info.define("RANLIB", str(bindir / "llvm-ranlib"))
self.cpp_info.includedirs = [
f"{self.package_folder}/include/c++/v1",
f"{self.package_folder}/include/",
f"{self.package_folder}/lib/clang/{get_version('llvm_major')}/include",
]

View File

@ -0,0 +1,31 @@
# 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_SYSTEM_NAME Linux)
set(triple @TRIPLE@)
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_ASM_COMPILER "clang")
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 NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

View File

@ -0,0 +1,25 @@
# 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.tools.cmake import CMakeToolchain, CMakeDeps
from conf.utils import get_version
from conf.base.zlib import ZlibBase
class ZlibBootstrap(ZlibBase):
name = "zlib-bootstrap"

View File

@ -0,0 +1 @@
set_target_properties(ZLIB::ZLIB PROPERTIES LOCATION ${zlib_LIB_DIRS_RELEASE}/libz.a)

View File

@ -15,90 +15,28 @@
# 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 conan.tools.cmake import CMakeToolchain, CMakeDeps
from conf.base.zlib import ZlibBase
from conf.utils import get_version, with_musl_toolchain
class Zlib(ConanFile):
class Zlib(ZlibBase):
name = "zlib"
version = get_version("zlib")
settings = "os", "arch", "build_type", "compiler"
exports = "*.cmake"
cmake_setup_file = "zlib_setup.cmake"
options = {
"libc": ["gnu", "musl"],
}
default_options = {"libc": "gnu"}
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}")
if self.options.libc == "musl":
self.tool_requires(
f"clang-bootstrap/{get_version('llvm')}@{self.user}/{self.channel}"
)
self.requires(f"musl/{get_version('musl')}@{self.user}/{self.channel}")
def source(self):
get(
self,
f"https://github.com/madler/zlib/archive/v{self.version}.tar.gz",
super().build_requirements()
self.tool_requires(
f"clang-bootstrap/{get_version('llvm')}@{self.user}/{self.channel}",
visible=False,
)
self.requires(f"musl/{get_version('musl')}@{self.user}/{self.channel}")
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = False
with_musl_toolchain(self, tc)
with_musl_toolchain(self, tc, "BUILD_TARGET")
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}",
)
self.run("ninja zlibstatic")
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,26 @@
# 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.base.zstd import ZstdBase
class ZstdBootstrap(ZstdBase):
name = "zstd-bootstrap"

View File

@ -19,61 +19,26 @@ from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy
from conf.base.zstd import ZstdBase
from conf.utils import get_version, with_musl_toolchain
class Zstd(ConanFile):
class Zstd(ZstdBase):
name = "zstd"
version = get_version("zstd")
settings = "os", "arch", "build_type", "compiler"
exports = "*.cmake"
options = {
"libc": ["gnu", "musl"],
}
default_options = {"libc": "gnu"}
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(
self,
f"https://github.com/facebook/zstd/archive/v{self.version}.tar.gz",
super().build_requirements()
self.tool_requires(
f"clang-bootstrap/{get_version('llvm')}@{self.user}/{self.channel}",
visible=False,
)
self.requires(f"musl/{get_version('musl')}@{self.user}/{self.channel}")
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = False
with_musl_toolchain(self, tc)
with_musl_toolchain(self, tc, "BUILD_TARGET")
tc.generate()
deps = CMakeDeps(self)
deps.generate()
def build(self):
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_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

@ -9,9 +9,6 @@ compiler=gcc
compiler.version=12.2
compiler.libcxx=libstdc++
[options]
*/*:libc = gnu
[buildenv]
LD=lld

View File

@ -13,13 +13,6 @@ clang-bootstrap/*:compiler=gcc
clang-bootstrap/*:compiler.version=12.2
clang-bootstrap/*:compiler.libcxx=libstdc++
[options]
zlib/*:libc = musl
# [tool_requires]
# musl/*:clang-bootstrap/{{ LLVM_VERSION }}@serene/stable
# zlib/*:clang-bootstrap/{{ LLVM_VERSION }}@serene/stable
[buildenv]
CC=clang
CXX=clang++