Change the toolchain build to build and install the entire llvm projects

This commit is contained in:
Sameer Rahmani 2023-05-12 16:55:46 +01:00
parent 1a8122a803
commit 16869cf296
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
5 changed files with 81 additions and 29 deletions

View File

@ -45,7 +45,7 @@ ZLIB_VERSION="1.2.13"
ZSTD_VERSION="1.5.4"
KERNEL_VERSION="6.0"
MUSL_VERSION="1.2.3"
IWYU_VERSION="14e9b208914a84fcdf49bf9f5d08897a4b3dc4b8"
IWYU_VERSION="35fed15e53d92c8c540f0c00ac10077043126c4d"
BOEHMGC_VERSION="8.2.2"
DEV_HEROES="https://devheroes.codes"
@ -177,6 +177,9 @@ function build-stage2() { ## Build the stage2 compiler and sysroot
# final toolchain
function build-stage3() { ## Build the stage3 compiler and sysroot
_build iwyu 2
_build cmake 2
_build ninja 2
_build toolchain 2
_build boehmgc 2
_build stage3-bundle 2

View File

@ -35,3 +35,9 @@ class IWYU(ConanFile):
)
with chpath(self.package_folder):
g.checkout(self.version)
def package_info(self):
self.buildenv_info.define(
"IWYU_SOURCE_DIR",
self.package_folder,
)

View File

@ -40,6 +40,8 @@ class Stage3(ConanFile):
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"musl/{get_version('musl')}@{self.user}/{self.channel}")
self.requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
self.requires(f"ninja/{get_version('ninja')}@{self.user}/{self.channel}")
# self.requires(f"cmake-musl/{get_version('cmake')}@{self.user}/{self.channel}")
# self.requires(f"ninja-musl/{get_version('ninja')}@{self.user}/{self.channel}")
self.requires(f"boehmgc/{get_version('boehmgc')}@{self.user}/{self.channel}")
@ -47,13 +49,7 @@ class Stage3(ConanFile):
def build(self):
copy_dependency_tree(
self,
[
"toolchain",
"musl",
"zlib",
"zstd",
"boehmgc",
],
["toolchain", "musl", "zlib", "zstd", "boehmgc", "cmake", "ninja"],
self.package_folder,
)

View File

@ -69,10 +69,18 @@ TOOLCHAIN_TARGETS = [
"builtins",
"llvm-libraries",
"mlir-libraries",
"mlir-headers",
"mlir-tblgen",
"mlir-opt",
"mlir-lsp-server",
"mlir-cmake-exports",
"mlir-reduce",
"mlir-translate",
"clang-headers",
"clang-cmake-exports",
"lld-cmake-exports",
"libclang",
"cmake-exports",
"llvm-jitlink",
"compiler-rt",
"runtimes",
@ -114,6 +122,7 @@ CMAKE_OPTIONS = {
"LIBCXXABI_ENABLE_SHARED": "OFF",
"LIBCXX_ABI_VERSION": "2",
"LLVM_CCACHE_BUILD": "ON",
"LLVM_EXTERNAL_PROJECTS": "iwyu",
# TODO: At this point lld crashes during linking clang itself
# cause of an issues in the `MachineDominator Tree Construction`
# pass that leads to an out of memory issue. Turn LTO on later
@ -131,6 +140,8 @@ CMAKE_OPTIONS = {
"LLVM_ENABLE_PROJECTS": ";".join(PROJECTS),
"LLVM_CCACHE_BUILD": "ON",
"LIBCXX_HAS_MUSL_LIBC": "ON",
"LIBCLANG_BUILD_STATIC": "ON",
"LLVM_ENABLE_PIC": "OFF",
# "LLVM_PARALLEL_COMPILE_JOBS": "32",
# "LLVM_PARALLEL_LINK_JOBS": "1",
"LLVM_DEFAULT_TARGET_TRIPLE": os.environ["TARGET"],
@ -146,6 +157,8 @@ class toolchain(ConanFile):
def build_requirements(self):
self.requires(f"llvm-source/{self.version}@{self.user}/{self.channel}")
self.requires(f"iwyu/{get_version('iwyu')}@{self.user}/{self.channel}")
self.requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
self.requires(
f"stage2-sysroot/{get_version('llvm')}@{self.user}/{self.channel}"
@ -163,7 +176,6 @@ class toolchain(ConanFile):
tc_dir = Path(self.dependencies["stage2-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"]
@ -177,8 +189,6 @@ class toolchain(ConanFile):
opts[
"CMAKE_SHARED_LINKER_FLAGS"
] = f"-Wl,-rpath,$ORIGIN/../lib/{target} -Wl,-rpath,$ORIGIN/../lib/"
# opts["CMAKE_C_FLAGS"] = "-static" -Wl,-rpath,{str(tc_dir)}/lib/{target}
# opts["CMAKE_CXX_FLAGS"] = "-static"
def add_runtimes_and_builtins(self, opts):
builtin_targets = []
@ -289,6 +299,15 @@ class toolchain(ConanFile):
def build(self):
opts = CMAKE_OPTIONS.copy()
sysroot = self.dependencies["stage2-sysroot"].package_folder
llvm_dir = self.dependencies["llvm-source"].buildenv_info.vars(
self, scope="build"
)
iwyu_dir = self.dependencies["iwyu"].buildenv_info.vars(self, scope="build")
cmake_dir = self.dependencies["cmake"].package_folder
cmake_version_parts = get_version("cmake").split(".")
cmake_version = f"{cmake_version_parts[0]}.{cmake_version_parts[1]}"
self.add_compiler_options(opts)
# zlib_dir = self.dependencies["zlib"].package_folder
@ -298,6 +317,7 @@ class toolchain(ConanFile):
] = f"{sysroot}/lib/clang/17/include {sysroot}/include"
opts["CMAKE_REQUIRED_LIBRARIES"] = f"-L{sysroot}/lib -lz"
opts["LLVM_EXTERNAL_IWYU_SOURCE_DIR"] = iwyu_dir["IWYU_SOURCE_DIR"]
# opts["LLVM_EXTERNALIZE_DEBUGINFO"] = "ON"
# opts["LLVM_DEBUGINFO_OUTPUT_DIR"] = f"{self.package_folder}/debug"
@ -310,31 +330,60 @@ class toolchain(ConanFile):
bin_dir.mkdir(exist_ok=True, parents=True)
opts["LLVM_ENABLE_PROJECTS"] = ";".join(PROJECTS)
opts["LLVM_DISTRIBUTION_COMPONENTS"] = ";".join(TOOLCHAIN_TARGETS)
# opts["LLVM_DISTRIBUTION_COMPONENTS"] = ";".join(TOOLCHAIN_TARGETS)
stage1 = Path(self.dependencies["stage2-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")
cm = CMake(self)
cm.configure(
opts,
build_script_folder=os.path.join(llvm_dir["LLVM_SOURCE_DIR"], "llvm"),
)
build_dir = os.path.join(self.build_folder, "build")
os.makedirs(build_dir)
cm.build(target="install-builtins")
cm.build(target="install-compiler-rt")
cm.build(target="install-runtimes")
# cm.build(target="install-distribution-stripped")
cm.build(target="tools/iwyu/install")
with current_dir(build_dir):
cm = CMake(self)
cm.configure(
opts,
build_script_folder=os.path.join(llvm_dir["LLVM_SOURCE_DIR"], "llvm"),
)
cm.build()
# cm.build(target="lldCOFF")
# cm.build(target="lldCommon")
# cm.build(target="lldELF")
# cm.build(target="lldMachO")
# cm.build(target="lldMinGW")
# cm.build(target="lldWasm")
cm.build(target="install-builtins")
cm.build(target="install-compiler-rt")
cm.build(target="install-runtimes")
# cm.build(target="install-toolchain-stripped")
cm.build(target="install-distribution-stripped")
# shutil.copy(
# f"{self.build_folder}/lib/liblldCOFF.a", f"{self.package_folder}/lib"
# )
# shutil.copy(
# f"{self.build_folder}/lib/liblldCommon.a", f"{self.package_folder}/lib"
# )
# shutil.copy(
# f"{self.build_folder}/lib/liblldELF.a", f"{self.package_folder}/lib"
# )
# shutil.copy(
# f"{self.build_folder}/lib/liblldMachO.a", f"{self.package_folder}/lib"
# )
# shutil.copy(
# f"{self.build_folder}/lib/liblldMinGW.a", f"{self.package_folder}/lib"
# )
# shutil.copy(
# f"{self.build_folder}/lib/liblldWasm.a", f"{self.package_folder}/lib"
# )
self.run(
f"cmake -DCMAKE_MODULE_PATH={cmake_dir}/share/cmake-{cmake_version}/Modules/ -DCMAKE_INSTALL_PREFIX={self.package_folder} -P cmake_install.cmake"
)
for binary in (Path(self.package_folder) / "bin").rglob("*"):
if binary.is_symlink():
continue
print(f"Stripping {binary}")
self.run(f"strip {binary}", ignore_errors=True)
def package_info(self):
bindir = Path(os.path.join(self.package_folder, "bin"))

View File

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