Fix the clang bootstrap package to be built with correct args

This commit is contained in:
Sameer Rahmani 2023-04-07 11:09:22 +01:00
parent a25529ed05
commit f9976b7053
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
7 changed files with 231 additions and 34 deletions

18
builder
View File

@ -62,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
}
@ -84,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" | \

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

@ -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,7 +56,7 @@ class Ninja(ConanFile):
def build(self):
cmake = CMake(self)
cmake.configure(
{},
with_static_flags({}),
build_script_folder=f"ninja-{self.version}",
)
cmake.build()

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

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