Add compat_build option

Make it easier to fork the versioned lld compat packages, so this
work doesn't have to be redone for every release.
This commit is contained in:
Nikita Popov 2022-09-07 15:14:24 +02:00
parent d2d0adf744
commit 58046ac8bb

View File

@ -1,4 +1,5 @@
%bcond_without check
%bcond_with compat_build
#global rc_ver 1
%global lld_srcdir lld-%{maj_ver}.%{min_ver}.%{patch_ver}%{?rc_ver:rc%{rc_ver}}.src
@ -6,11 +7,23 @@
%global min_ver 0
%global patch_ver 5
%if %{with compat_build}
%global pkg_name lld%{maj_ver}
%global install_prefix %{_libdir}/llvm%{maj_ver}
%global install_includedir %{install_prefix}/include
%global install_libdir %{install_prefix}/lib
%else
%global pkg_name lld
%global install_prefix /usr
%global install_includedir %{_includedir}
%global install_libdir %{_libdir}
%endif
# Don't include unittests in automatic generation of provides or requires.
%global __provides_exclude_from ^%{_libdir}/lld/.*$
%global __requires_exclude ^libgtest.*$
Name: lld
Name: %{pkg_name}
Version: %{maj_ver}.%{min_ver}.%{patch_ver}%{?rc_ver:~rc%{rc_ver}}
Release: 4%{?dist}
Summary: The LLVM Linker
@ -20,8 +33,10 @@ URL: http://llvm.org
Source0: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{maj_ver}.%{min_ver}.%{patch_ver}%{?rc_ver:-rc%{rc_ver}}/%{lld_srcdir}.tar.xz
Source1: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{maj_ver}.%{min_ver}.%{patch_ver}%{?rc_ver:-rc%{rc_ver}}/%{lld_srcdir}.tar.xz.sig
Source2: tstellar-gpg-key.asc
%if %{without compat_build}
Source3: run-lit-tests
Source4: lit.lld-test.cfg.py
%endif
ExcludeArch: s390x
@ -37,15 +52,19 @@ BuildRequires: gcc
BuildRequires: gcc-c++
BuildRequires: cmake
BuildRequires: ninja-build
%if %{with compat_build}
BuildRequires: llvm%{maj_ver}-devel = %{version}
%else
BuildRequires: llvm-devel = %{version}
BuildRequires: llvm-test = %{version}
BuildRequires: llvm-googletest = %{version}
%endif
BuildRequires: ncurses-devel
BuildRequires: zlib-devel
# For make check:
BuildRequires: python3-rpm-macros
BuildRequires: python3-lit
BuildRequires: llvm-googletest = %{version}
# For gpg source verification
BuildRequires: gnupg2
@ -53,17 +72,19 @@ BuildRequires: gnupg2
Requires(post): %{_sbindir}/update-alternatives
Requires(preun): %{_sbindir}/update-alternatives
Requires: lld-libs = %{version}-%{release}
Requires: %{name}-libs = %{version}-%{release}
%description
The LLVM project linker.
%package devel
Summary: Libraries and header files for LLD
Requires: lld-libs%{?_isa} = %{version}-%{release}
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
%if %{without compat_build}
# lld tools are referenced in the cmake files, so we need to add lld as a
# dependency.
Requires: %{name}%{?_isa} = %{version}-%{release}
%endif
%description devel
This package contains library and header files needed to develop new native
@ -75,6 +96,7 @@ Summary: LLD shared libraries
%description libs
Shared libraries for LLD.
%if %{without compat_build}
%package test
Summary: LLD regression tests
Requires: %{name}%{?_isa} = %{version}-%{release}
@ -84,11 +106,20 @@ Requires: lld-libs = %{version}-%{release}
%description test
LLVM regression tests.
%endif
%prep
%{gpgverify} --keyring='%{SOURCE2}' --signature='%{SOURCE1}' --data='%{SOURCE0}'
%autosetup -n %{lld_srcdir} -p2
%if %{with compat_build}
# For compat builds, we don't want to build the actual lld binary. While there is an
# LLD_BUILD_TOOLS cmake option, it is incomplete in various ways (e.g. still leaves install
# targets and symlinks), so instead skip the tools/lld build entirely.
# We can't simply delete the binaries after the fact, because this would leave checks for
# their existence in the cmake exports.
sed 's/add_subdirectory(tools\/lld)//' -i CMakeLists.txt
%endif
%build
@ -98,28 +129,36 @@ LLVM regression tests.
%cmake \
-GNinja \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_INSTALL_PREFIX=%{install_prefix} \
-DLLVM_LINK_LLVM_DYLIB:BOOL=ON \
-DLLVM_DYLIB_COMPONENTS="all" \
-DCMAKE_SKIP_RPATH:BOOL=ON \
-DPYTHON_EXECUTABLE=%{__python3} \
%if %{with compat_build}
-DLLVM_INCLUDE_TESTS=OFF \
%else
-DLLVM_INCLUDE_TESTS=ON \
-DLLVM_MAIN_SRC_DIR=%{_datadir}/llvm/src \
-DLLVM_EXTERNAL_LIT=%{_bindir}/lit \
-DLLVM_LIT_ARGS="-sv \
--path %{_libdir}/llvm" \
%if 0%{?__isa_bits} == 64
-DLLVM_LIBDIR_SUFFIX=64
-DLLVM_LIBDIR_SUFFIX=64 \
%else
-DLLVM_LIBDIR_SUFFIX=
-DLLVM_LIBDIR_SUFFIX= \
%endif
%endif
-DLLVM_MAIN_SRC_DIR=%{_datadir}/llvm/src
%cmake_build
%if %{without compat_build}
# Build the unittests so we can install them.
%cmake_build --target lld-test-depends
%endif
%install
%if %{without compat_build}
%global lit_cfg test/%{_arch}.site.cfg.py
%global lit_unit_cfg test/Unit/%{_arch}.site.cfg.py
%global lit_lld_test_cfg_install_path %{_datadir}/lld/lit.lld-test.cfg.py
@ -154,13 +193,15 @@ rm -rf `find %{buildroot}%{_libdir}/lld/ -iname '*make*'`
# Install gtest libraries
cp %{__cmake_builddir}/%{_lib}/libgtest*so* %{buildroot}%{_libdir}/lld/
%endif
# Install libraries and binaries
%cmake_install
# This is generated by Patch1 during build and (probably) must be removed afterward
rm %{buildroot}%{_includedir}/mach-o/compact_unwind_encoding.h
rm %{buildroot}%{install_includedir}/mach-o/compact_unwind_encoding.h
%if %{without compat_build}
# Required when using update-alternatives:
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Alternatives/
touch %{buildroot}%{_bindir}/ld
@ -172,9 +213,11 @@ touch %{buildroot}%{_bindir}/ld
if [ $1 -eq 0 ] ; then
%{_sbindir}/update-alternatives --remove ld %{_bindir}/ld.lld
fi
%endif
%check
%if %{without compat_build}
# armv7lhl tests disabled because of arm issue, see https://koji.fedoraproject.org/koji/taskinfo?taskID=33660162
%ifnarch %{arm}
%if %{with check}
@ -183,7 +226,9 @@ fi
%endif
%ldconfig_scriptlets libs
%endif
%if %{without compat_build}
%files
%license LICENSE.TXT
%ghost %{_bindir}/ld
@ -191,15 +236,17 @@ fi
%{_bindir}/ld.lld
%{_bindir}/ld64.lld
%{_bindir}/wasm-ld
%endif
%files devel
%{_includedir}/lld
%{_libdir}/liblld*.so
%{_libdir}/cmake/lld/
%{install_includedir}/lld
%{install_libdir}/liblld*.so
%{install_libdir}/cmake/lld/
%files libs
%{_libdir}/liblld*.so.*
%{install_libdir}/liblld*.so.*
%if %{without compat_build}
%files test
%{_libexecdir}/tests/lld/
%{_libdir}/lld/
@ -207,6 +254,7 @@ fi
%{_datadir}/lld/src/%{_arch}.site.cfg.py
%{_datadir}/lld/src/%{_arch}.Unit.site.cfg.py
%{_datadir}/lld/lit.lld-test.cfg.py
%endif
%changelog
* Tue Aug 09 2022 Nikita Popov <npopov@redhat.com> - 14.0.5-4