Skip to content

Commit 595c2a2

Browse files
committed
Invert symlink direction
This is an alternative to: https://src.fedoraproject.org/rpms/llvm/pull-request/439. Instead of undoing the prefix change completely, this instead inverts the direction of the symlinks: The non-compat package ships all the files in the default prefix, but has symlinks from the versioned prefix to the default prefix. The implementation approach is to install everything into the versioned prefix first (keeping things unified between compat and non-compat build initially) and to then move and symlink in post-processing. The llvm-config setup here stays the same as it currently is, with llvm-config executables being installed in the versioned prefix, while the one in the default prefix is managed by alternatives. This patch does not fix the issues with alternatives handling, we'd apply https://src.fedoraproject.org/rpms/llvm/pull-request/417 on top of this patch for that. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2365079.
1 parent 1301bd9 commit 595c2a2

File tree

2 files changed

+73
-49
lines changed

2 files changed

+73
-49
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Tweak this to centos-stream-9-x86_64 to build for CentOS
55
MOCK_CHROOT?=fedora-rawhide-x86_64
66
MOCK_OPTS?=
7-
MOCK_OPTS_RELEASE?=--no-clean --no-cleanup-after --without lto_build --define "debug_package %{nil}" $(MOCK_OPTS)
7+
MOCK_OPTS_RELEASE?=--no-clean --no-cleanup-after --without lto_build --without pgo --define "debug_package %{nil}" $(MOCK_OPTS)
88
MOCK_OPTS_SNAPSHOT?=$(MOCK_OPTS_RELEASE) --with snapshot_build $(MOCK_OPTS)
99
YYYYMMDD?=$(shell date +%Y%m%d)
1010
SOURCEDIR=$(shell pwd)

llvm.spec

Lines changed: 72 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
#region main package
317317
Name: %{pkg_name_llvm}
318318
Version: %{maj_ver}.%{min_ver}.%{patch_ver}%{?rc_ver:~rc%{rc_ver}}%{?llvm_snapshot_version_suffix:~%{llvm_snapshot_version_suffix}}
319-
Release: 7%{?dist}
319+
Release: 8%{?dist}
320320
Summary: The Low Level Virtual Machine
321321

322322
License: Apache-2.0 WITH LLVM-exception OR NCSA
@@ -1330,8 +1330,15 @@ popd
13301330
-DCLANG_INCLUDE_TESTS:BOOL=ON \\\
13311331
-DCLANG_PLUGIN_SUPPORT:BOOL=ON \\\
13321332
-DCLANG_REPOSITORY_STRING="%{?dist_vendor} %{version}-%{release}" \\\
1333-
-DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=../clang-tools-extra \\\
1333+
-DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=../clang-tools-extra
1334+
1335+
%if %{with compat_build}
1336+
%global cmake_config_args %{cmake_config_args} \\\
13341337
-DCLANG_RESOURCE_DIR=../../../lib/clang/%{maj_ver}
1338+
%else
1339+
%global cmake_config_args %{cmake_config_args} \\\
1340+
-DCLANG_RESOURCE_DIR=../lib/clang/%{maj_ver}
1341+
%endif
13351342
#endregion clang options
13361343

13371344
#region compiler-rt options
@@ -1938,8 +1945,12 @@ rm -Rvf %{buildroot}%{install_datadir}/clang-doc
19381945
# TODO: What are the Fedora guidelines for packaging bash autocomplete files?
19391946
rm -vf %{buildroot}%{install_datadir}/clang/bash-autocomplete.sh
19401947

1941-
# Create sub-directories in the clang resource directory that will be
1942-
# populated by other packages
1948+
%if %{without compat_build}
1949+
# Move clang resource directory to default prefix.
1950+
mkdir -p %{buildroot}%{_prefix}/lib/clang
1951+
mv %{buildroot}%{install_prefix}/lib/clang/%{maj_ver} %{buildroot}%{_prefix}/lib/clang/%{maj_ver}
1952+
%endif
1953+
# Create any missing sub-directories in the clang resource directory.
19431954
mkdir -p %{buildroot}%{_prefix}/lib/clang/%{maj_ver}/{bin,include,lib,share}/
19441955

19451956
# Add versioned resource directory macro
@@ -2025,7 +2036,7 @@ rmdir %{buildroot}%{install_prefix}/%{_lib}/python%{python3_version}
20252036

20262037
# python: fix binary libraries location
20272038
liblldb=$(basename $(readlink -e %{buildroot}%{install_libdir}/liblldb.so))
2028-
ln -vsf "../../../llvm%{maj_ver}/lib/${liblldb}" %{buildroot}%{python3_sitearch}/lldb/_lldb.so
2039+
ln -vsf "../../../${liblldb}" %{buildroot}%{python3_sitearch}/lldb/_lldb.so
20292040
%py_byte_compile %{__python3} %{buildroot}%{python3_sitearch}/lldb
20302041
%endif
20312042
%endif
@@ -2066,62 +2077,69 @@ popd
20662077
rm -f %{buildroot}%{install_libdir}/libLLVMBOLT*.a
20672078
#endregion BOLT installation
20682079

2069-
# Create symlinks from the system install prefix to the llvm install prefix.
2080+
# Move files from src to dest and replace the old files in src with relative
2081+
# symlinks.
2082+
move_and_replace_with_symlinks() {
2083+
local src="$1"
2084+
local dest="$2"
2085+
mkdir -p "$dest"
2086+
2087+
# Change to source directory to simplify relative paths
2088+
(cd "$src" && \
2089+
find * -type d -exec mkdir -p "$dest/{}" \; && \
2090+
find * \( -type f -o -type l \) -exec mv "$src/{}" "$dest/{}" \; \
2091+
-exec ln -s --relative "$dest/{}" "$src/{}" \;)
2092+
}
2093+
2094+
%if %{without compat_build}
2095+
# Move files from the llvm prefix to the system prefix and replace them with
2096+
# symlinks. We do it this way around because symlinks between multilib packages
2097+
# would conflict otherwise.
2098+
move_and_replace_with_symlinks %{buildroot}%{install_bindir} %{buildroot}%{_bindir}
2099+
move_and_replace_with_symlinks %{buildroot}%{install_libdir} %{buildroot}%{_libdir}
2100+
move_and_replace_with_symlinks %{buildroot}%{install_libexecdir} %{buildroot}%{_libexecdir}
2101+
move_and_replace_with_symlinks %{buildroot}%{install_includedir} %{buildroot}%{_includedir}
2102+
move_and_replace_with_symlinks %{buildroot}%{install_datadir} %{buildroot}%{_datadir}
2103+
%endif
2104+
2105+
# Create versioned symlinks for binaries.
20702106
# Do this at the end so it includes any files added by preceding steps.
20712107
mkdir -p %{buildroot}%{_bindir}
20722108
for f in %{buildroot}%{install_bindir}/*; do
20732109
filename=`basename $f`
2074-
if [[ "$filename" == "clang-%{maj_ver}" ]]; then
2110+
if [[ "$filename" =~ ^(lit|ld|clang-%{maj_ver})$ ]]; then
20752111
continue
20762112
fi
2077-
# Add symlink for binaries with version suffix.
2078-
ln -s ../../%{install_bindir}/$filename %{buildroot}/%{_bindir}/$filename-%{maj_ver}
2079-
# For non-compat builds, also add a symlink without version suffix.
2080-
%if %{without compat_build}
2081-
ln -s ../../%{install_bindir}/$filename %{buildroot}/%{_bindir}/$filename
2113+
%if %{with compat_build}
2114+
ln -s ../../%{install_bindir}/$filename %{buildroot}/%{_bindir}/$filename-%{maj_ver}
2115+
%else
2116+
# clang-NN is already created by the build system.
2117+
if [[ "$filename" == "clang" ]]; then
2118+
continue
2119+
fi
2120+
ln -s $filename %{buildroot}/%{_bindir}/$filename-%{maj_ver}
20822121
%endif
20832122
done
20842123

2085-
# Move man pages to system install prefix.
20862124
mkdir -p %{buildroot}%{_mandir}/man1
20872125
for f in %{buildroot}%{install_mandir}/man1/*; do
20882126
filename=`basename $f`
20892127
filename=${filename%.1}
2090-
mv $f %{buildroot}%{_mandir}/man1/$filename-%{maj_ver}.1
2091-
%if %{without compat_build}
2092-
ln -s $filename-%{maj_ver}.1 %{buildroot}%{_mandir}/man1/$filename.1
2128+
%if %{with compat_build}
2129+
# Move man pages to system install prefix.
2130+
mv $f %{buildroot}%{_mandir}/man1/$filename-%{maj_ver}.1
2131+
%else
2132+
# Create suffixed symlink.
2133+
ln -s $filename.1 %{buildroot}%{_mandir}/man1/$filename-%{maj_ver}.1
20932134
%endif
20942135
done
2095-
rmdir %{buildroot}%{install_mandir}/man1
2096-
rmdir %{buildroot}%{install_mandir}
2136+
rm -rf %{buildroot}%{install_mandir}
20972137

2138+
# As an exception, always keep llvm-config in the versioned prefix.
2139+
# The llvm-config in the default prefix will be managed by alternatives.
20982140
%if %{without compat_build}
2099-
# We don't create directory symlinks, because RPM does not support
2100-
# switching between a directory and a symlink, causing upgrade/downgrade issues.
2101-
# Instead, recursively copy the directories while creating symlinks.
2102-
copy_with_relative_symlinks() {
2103-
local src="$1"
2104-
local dest="$2"
2105-
mkdir -p "$dest"
2106-
2107-
# Change to source directory to simplify relative paths
2108-
(cd "$src" && \
2109-
find * -type d -exec mkdir -p "$dest/{}" \; && \
2110-
find * \( -type f -o -type l \) -exec ln -s --relative "$src/{}" "$dest/{}" \;)
2111-
}
2112-
2113-
# Add symlinks for libraries.
2114-
copy_with_relative_symlinks %{buildroot}%{install_libdir} %{buildroot}%{_libdir}
2115-
copy_with_relative_symlinks %{buildroot}%{install_libexecdir} %{buildroot}%{_libexecdir}
2116-
copy_with_relative_symlinks %{buildroot}%{install_includedir} %{buildroot}%{_includedir}
2117-
copy_with_relative_symlinks %{buildroot}%{install_datadir} %{buildroot}%{_datadir}
2118-
2119-
%if %{maj_ver} >= 21 && %{with offload}
2120-
# Remove offload libaries since we only want to ship these in the configured
2121-
# install prefix.
2122-
rm -Rf %{buildroot}%{_libdir}/amdgcn-amd-amdhsa
2123-
rm -Rf %{buildroot}%{_libdir}/nvptx64-nvidia-cuda
2124-
%endif
2141+
rm %{buildroot}%{install_bindir}/llvm-config
2142+
mv %{buildroot}%{_bindir}/llvm-config %{buildroot}%{install_bindir}/llvm-config
21252143
%endif
21262144

21272145
# ghost presence for llvm-config, managed by alternatives.
@@ -3164,10 +3182,12 @@ fi
31643182
libomptarget-nvptx*.bc
31653183
}}
31663184
%else
3167-
%{install_libdir}/amdgcn-amd-amdhsa/libompdevice.a
3168-
%{install_libdir}/amdgcn-amd-amdhsa/libomptarget-amdgpu.bc
3169-
%{install_libdir}/nvptx64-nvidia-cuda/libompdevice.a
3170-
%{install_libdir}/nvptx64-nvidia-cuda/libomptarget-nvptx.bc
3185+
%{expand_libs %{expand:
3186+
amdgcn-amd-amdhsa/libompdevice.a
3187+
amdgcn-amd-amdhsa/libomptarget-amdgpu.bc
3188+
nvptx64-nvidia-cuda/libompdevice.a
3189+
nvptx64-nvidia-cuda/libomptarget-nvptx.bc
3190+
}}
31713191
%endif
31723192

31733193
%expand_includes offload
@@ -3403,6 +3423,10 @@ fi
34033423

34043424
#region changelog
34053425
%changelog
3426+
* Tue Jun 10 2025 Nikita Popov <[email protected]> - 20.1.6-8
3427+
- Invert symlink direction
3428+
- Fix i686 multilib installation (rhbz#2365079)
3429+
34063430
* Thu Jun 05 2025 Timm Bäder <[email protected]> - 20.1.6-7
34073431
- Backport patch to fix rhbz#2363895
34083432

0 commit comments

Comments
 (0)