From 4044d000ce08dcbfa85bd63afc5effca4182bdab Mon Sep 17 00:00:00 2001 From: Daniel Martinez Date: Sat, 16 Nov 2024 14:29:47 -0500 Subject: [PATCH] llvm19: bootstrap build, fix cmake and spirv translator. --- srcpkgs/llvm19/template | 120 ++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 73 deletions(-) diff --git a/srcpkgs/llvm19/template b/srcpkgs/llvm19/template index 774ef89d660..c140037362e 100644 --- a/srcpkgs/llvm19/template +++ b/srcpkgs/llvm19/template @@ -1,7 +1,7 @@ # Template file for 'llvm19' pkgname=llvm19 version=19.1.3 -revision=2 +revision=3 build_wrksrc=llvm build_style=cmake _llvm_prefix=lib/llvm/19 @@ -16,7 +16,6 @@ configure_args=" -DCMAKE_BUILD_TYPE=Release -Wno-dev -DCMAKE_INSTALL_PREFIX=/usr/${_llvm_prefix} -DENABLE_LINKER_BUILD_ID=YES - -DLLDB_USE_SYSTEM_SIX=YES -DLIBCXXABI_ENABLE_STATIC_UNWINDER=YES -DLIBCXXABI_USE_COMPILER_RT=YES -DLIBCXXABI_USE_LLVM_UNWINDER=YES @@ -43,45 +42,29 @@ configure_args=" -DLLDB_PYTHON_RELATIVE_PATH=lib/python${py3_ver}/site-packages -DLLDB_PYTHON_EXE_RELATIVE_PATH=bin/python${py3_ver} -DLLDB_PYTHON_EXT_SUFFIX=$_ext_suffix - -DLIBC_WNO_ERROR=YES - -DBASE_LLVM_VERSION=${version} - -DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=/usr -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=NO + -DLLVM_SPIRV=/usr/bin/llvm-spirv " hostmakedepends="perl python3 zlib-devel libffi-devel swig python3-Sphinx python3-recommonmark python3-sphinx-automodapi git python3-sphinx-markdown-tables python3-yaml pkg-config - python3-mdit-py-plugins python3-MyST-Parser python3-markdown-it SPIRV-Headers SPIRV-Tools-devel + python3-mdit-py-plugins python3-MyST-Parser python3-markdown-it patchelf $(vopt_if graphviz graphviz)" makedepends="python3-devel zlib-devel elfutils-devel libffi-devel libedit-devel - libxml2-devel binutils-devel z3-devel SPIRV-Headers SPIRV-Tools-devel" + libxml2-devel binutils-devel z3-devel" short_desc="LLVM Compiler Infrastructure Project - Version 19" maintainer="Daniel Martinez " license="Apache-2.0 AND NCSA AND custom:Apache-2.0-with-llvm-exception" homepage="https://www.llvm.org" -_spirv_version=v19.1.0 -distfiles="https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-${version}.tar.gz - https://github.com/KhronosGroup/SPIRV-LLVM-Translator/archive/refs/tags/${_spirv_version}.tar.gz" -checksum="e5106e2bef341b3f5e41340e4b6c6a58259f4021ad801acf14e88f1a84567b05 - 2e64231db8646d8c220d44136712549b5d4c4194c6ce0e57c4f5ab342beee9a2" -skip_extraction=${_spirv_version}.tar.gz +distfiles="https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-${version}.tar.gz" +checksum=e5106e2bef341b3f5e41340e4b6c6a58259f4021ad801acf14e88f1a84567b05 conflicts="llvm18>=0 llvm17>=0 llvm15>=0" lib32disabled=yes python_version=3 -CFLAGS="-Wno-unused-command-line-argument" -CXXFLAGS="-Wno-unused-command-line-argument" - -if [ "$XBPS_WORDSIZE" == "32" ]; then - nodebug=yes # 32bit memory exhasted -fi - build_options="clang clang_tools_extra lld mlir libclc polly lldb flang bolt - openmp libc libcxx libunwind offload llvm_spirv lto graphviz full_debug" + openmp libc libcxx libunwind offload lto graphviz full_debug" build_options_default="clang clang_tools_extra lld libclc polly lldb - libcxx libunwind" - -# mlir disabled to save space on builders -# build_options_default+=" mlir" + libcxx libunwind mlir" # fails to build with libquadmth on musl case "$XBPS_TARGET_MACHINE" in @@ -90,9 +73,7 @@ esac case "$XBPS_TARGET_MACHINE" in x86_64*|aarch64*|riscv64*) - build_options_default+=" bolt" - # flang disabled to save space on buildders - # build_options_default+=" flang" + build_options_default+=" bolt flang" if [ -z "$CROSS_BUILD" ]; then build_options_default+=" offload" fi @@ -105,7 +86,10 @@ case "$XBPS_TARGET_MACHINE" in esac if [ -z "$CROSS_BUILD" ]; then - build_options_default+=" llvm_spirv" + hostmakedepends+=" llvm19-bootstrap" + + # Needs lld on the target machine + configure_args+=" -DLLVM_USE_LINKER=lld" fi # build fails because compiler_rt generates armv7 instructions when target is armv6 @@ -169,7 +153,7 @@ configure_args+=" -DLLVM_ENABLE_RUNTIMES=${_enabled_runtimes}" configure_args+=" -DLLVM_ENABLE_PROJECTS=${_enabled_projects}" if [ "$CROSS_BUILD" ]; then - hostmakedepends+=" llvm19-cross-tools " + hostmakedepends+=" llvm19-cross-tools SPIRV-LLVM-Translator19" configure_args+=" -DLLVM_TOOLS_BINAIRY_DIR=/${_llvm_bindir}" configure_args+=" -DLLVM_NATIVE_TOOL_DIR=/${_llvm_bindir}" @@ -195,17 +179,11 @@ fi if [ -z "$CROSS_BUILD" ]; then subpackages="llvm19-cross-tools ${subpackages}" # OCaml cross build is broken - hostmakedepends+=" ocaml ocaml-findlib " + hostmakedepends+=" ocaml ocaml-findlib" # lldb cross build fails with lua makedepends+=" lua53-devel " fi -if [ ! "$build_option_full_debug" ]; then - # Vastly reduce size of debugging symbols: - CFLAGS=${CFLAGS/ -g/ -g1} - CXXFLAGS=${CXXFLAGS/ -g/ -g1} -fi - case "$XBPS_TARGET_MACHINE" in arm*-musl|i686-musl) # sanitizer code is broken since it duplicates some libc bits @@ -245,12 +223,6 @@ _vlink_libs() { done } -post_extract() { - if [ "$build_option_llvm_spirv" ]; then - vsrcextract -C llvm/projects/llvm-spirv ${_spirv_version}.tar.gz - fi -} - post_patch() { # need libssp_nonshared on some musl platforms (because of nodefaultlibs) case "$XBPS_TARGET_MACHINE" in @@ -266,35 +238,46 @@ post_patch() { } _setup_cross_cflags() { - CC="clang" - CXX="clang++" + CC="clang" + CXX="clang++" - CFLAGS+=" -Wno-gnu-include-next -Wno-unused-command-line-argument" - CXXFLAGS+=" -Wno-gnu-include-next -Wno-unused-command-line-argument" + CFLAGS+=" -Wno-gnu-include-next -Wno-unused-command-line-argument" + CXXFLAGS+=" -Wno-gnu-include-next -Wno-unused-command-line-argument" - local gcc_version=$(gcc -dumpversion) + local gcc_version=$(gcc -dumpversion) - CFLAGS+=" --target=${XBPS_CROSS_TRIPLET} --sysroot=${XBPS_CROSS_BASE}" - CFLAGS+=" --gcc-toolchain=/usr" - CFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include" + CFLAGS+=" --target=${XBPS_CROSS_TRIPLET} --sysroot=${XBPS_CROSS_BASE}" + CFLAGS+=" --gcc-toolchain=/usr" + CFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include" - CXXFLAGS+=" --target=${XBPS_CROSS_TRIPLET} --sysroot=${XBPS_CROSS_BASE}" - CXXFLAGS+=" --gcc-toolchain=/usr" - CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include/c++/${gcc_version%.*}" - CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include/c++/${gcc_version%.*}/${XBPS_CROSS_TRIPLET}" - CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include/c++/${gcc_version%.*}/backward" - CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include" + CXXFLAGS+=" --target=${XBPS_CROSS_TRIPLET} --sysroot=${XBPS_CROSS_BASE}" + CXXFLAGS+=" --gcc-toolchain=/usr" + CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include/c++/${gcc_version%.*}" + CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include/c++/${gcc_version%.*}/${XBPS_CROSS_TRIPLET}" + CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include/c++/${gcc_version%.*}/backward" + CXXFLAGS+=" -isystem ${XBPS_CROSS_BASE}/usr/include" +} + +_setup_debug() { + if [ ! "$build_option_full_debug" ]; then + # Vastly reduce size of debugging symbols: + CFLAGS=${CFLAGS/ -g/ -gline-tables-only} + CXXFLAGS=${CXXFLAGS/ -g/ -gline-tables-only} + fi } pre_configure() { + CC="clang" + CXX="clang++" if [ "$CROSS_BUILD" ]; then _setup_cross_cflags fi - if [ "$build_option_llvm_spirv" ]; then - configure_args+=" -DLLVM_SPIRV=${wrksrc}/llvm/build/bin/llvm-spirv" - else - configure_args+=" -DLLVM_SPIRV=/${_llvm_bindir}/llvm-spirv" - fi + + _setup_debug +} + +pre_build() { + _setup_debug } post_build() { @@ -567,8 +550,8 @@ clang19_package() { if [ "$build_option_polly" ]; then alternatives+=" - clang:/usr/lib/LLVMPolly.so:/${_llvm_libdir}/LLVMPolly.so - clang:/usr/share/man/man1/polly.1:/${_llvm_mandir}/man1/polly1.1 + clang:/usr/lib/LLVMPolly.so:/${_llvm_libdir}/LLVMPolly.so + clang:/usr/share/man/man1/polly.1:/${_llvm_mandir}/man1/polly1.1 " fi pkg_install() { @@ -1066,7 +1049,6 @@ llvm19-devel_package() { if [ "$build_option_clang" ]; then depends+=" clang19-devel>=${version}_${revision} " fi - alternatives+=" llvm-devel:/usr/lib/cmake/llvm:/usr/${_llvm_libdir}/cmake/llvm" pkg_install() { vmove ${_llvm_libdir}/libLLVM.so vmove ${_llvm_libdir}/libLTO.so @@ -1105,14 +1087,6 @@ llvm19-cross-tools_package() { if [ "$build_option_mlir" ]; then vcopy build/bin/mlir-src-sharder ${_llvm_bindir} fi - - if [ "$build_option_llvm_spirv" ]; then - patchelf --add-rpath '$ORIGIN/../lib' ${DESTDIR}/${_llvm_bindir}/llvm-spirv - vmove ${_llvm_bindir}/llvm-spirv - vmove ${_llvm_incdir}/LLVMSPIRVLib - vmove ${_llvm_libdir}/pkgconfig/LLVMSPIRVLib.pc - vmove "${_llvm_libdir}/libLLVMSPIRV*.a" - fi } }