mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 21:00:13 -05:00
build: select a working C++20 compiler for RPM builds
A compiler activated while installing dependencies does not survive in the caller's shell, so make rpm could fall back to one that can't compile mergerfs. Route the RPM build through buildtools/run-rpmbuild, which keeps an explicit compiler and otherwise activates an installed GCC Toolset when the default can't handle C++20. RPMBUILD and RPMBUILD_FLAGS override the rpmbuild command. Rocky 8's toolsets lack the annobin plugin the distribution's RPM flags load. Test the effective compiler with the RPM flags and pass --undefine _annotated_build only when that fails, instead of guessing from the compiler's path in build-mergerfs. Native and container builds use the same check.
This commit is contained in:
parent
11e759101d
commit
d83e01b40a
4 changed files with 106 additions and 16 deletions
3
Makefile
3
Makefile
|
|
@ -351,7 +351,8 @@ rpm: tarball
|
|||
$(SED) 's/__VERSION__/$(VERSION)/g' mergerfs.spec > \
|
||||
rpmbuild/SOURCES/mergerfs.spec
|
||||
cp -ar mergerfs-$(VERSION).tar.gz rpmbuild/SOURCES
|
||||
$(RPMBUILD) $(RPMBUILD_FLAGS) -ba rpmbuild/SOURCES/mergerfs.spec \
|
||||
./buildtools/run-rpmbuild $(RPMBUILD) $(RPMBUILD_FLAGS) \
|
||||
-ba rpmbuild/SOURCES/mergerfs.spec \
|
||||
--define "_topdir $(CURDIR)/rpmbuild"
|
||||
|
||||
.PHONY: install-build-pkgs
|
||||
|
|
|
|||
|
|
@ -8,15 +8,6 @@ if [ -e "$BUILD_ENV" ]; then
|
|||
. "$BUILD_ENV"
|
||||
fi
|
||||
|
||||
rpmbuild_flags()
|
||||
{
|
||||
case "$(command -v "${CXX:-g++}")" in
|
||||
/opt/rh/*)
|
||||
printf '%s' '--undefine _annotated_build'
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "usage: $0 <branch> <git_repo>"
|
||||
echo "argv: $@"
|
||||
|
|
@ -44,9 +35,9 @@ mkdir "/build"
|
|||
if [ -e /usr/bin/apt-get ]; then
|
||||
make deb
|
||||
elif [ -e /usr/bin/dnf ]; then
|
||||
make RPMBUILD_FLAGS="$(rpmbuild_flags)" rpm
|
||||
make rpm
|
||||
elif [ -e /usr/bin/yum ]; then
|
||||
make RPMBUILD_FLAGS="$(rpmbuild_flags)" rpm
|
||||
make rpm
|
||||
elif [ -e /sbin/apk ]; then
|
||||
echo "NOT YET SUPPORTED"
|
||||
exit 1
|
||||
|
|
|
|||
85
buildtools/run-rpmbuild
Executable file
85
buildtools/run-rpmbuild
Executable file
|
|
@ -0,0 +1,85 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# usage: run-rpmbuild <rpmbuild> [args...]
|
||||
#
|
||||
# Run rpmbuild with a C++20 capable compiler.
|
||||
#
|
||||
# If CXX is unset and the default g++ can't build C++20 (ex: EL8's g++
|
||||
# 8) the newest installed GCC Toolset / devtoolset is activated.
|
||||
#
|
||||
# redhat-rpm-config's %{optflags} load the annobin GCC plugin which
|
||||
# toolset compilers often don't have ("inaccessible plugin file
|
||||
# plugin/annobin.so"). If the selected compiler fails with %{optflags}
|
||||
# but works with annotation disabled `--undefine _annotated_build` is
|
||||
# passed to rpmbuild.
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "usage: $0 <rpmbuild> [args...]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cxx20_ok()
|
||||
{
|
||||
printf 'int main(){return 0;}\n' | \
|
||||
"${CXX:-g++}" -std=c++20 -x c++ -fsyntax-only - >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Print "<version> <path>" for each toolset activation script.
|
||||
toolset_scripts()
|
||||
{
|
||||
for f in \
|
||||
/usr/lib/gcc-toolset/*-env.source \
|
||||
/opt/rh/gcc-toolset-*/enable \
|
||||
/opt/rh/devtoolset-*/enable
|
||||
do
|
||||
[ -f "$f" ] || continue
|
||||
v="$(printf '%s\n' "$f" | sed -n \
|
||||
-e 's,^/usr/lib/gcc-toolset/\([0-9][0-9]*\)-env\.source$,\1,p' \
|
||||
-e 's,^/opt/rh/gcc-toolset-\([0-9][0-9]*\)/enable$,\1,p' \
|
||||
-e 's,^/opt/rh/devtoolset-\([0-9][0-9]*\)/enable$,\1,p')"
|
||||
[ -n "$v" ] && printf '%s %s\n' "$v" "$f"
|
||||
done
|
||||
}
|
||||
|
||||
activate_toolset()
|
||||
{
|
||||
for f in $(toolset_scripts | sort -k1,1nr | cut -d' ' -f2); do
|
||||
if (. "$f" || :; cxx20_ok); then
|
||||
echo "run-rpmbuild: activating $f" >&2
|
||||
. "$f" || :
|
||||
export CC=gcc
|
||||
export CXX=g++
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
optflags_ok()
|
||||
{
|
||||
flags="$(rpm "$@" --eval '%{optflags}')" || return 1
|
||||
printf 'int main(){return 0;}\n' | \
|
||||
"${CXX:-g++}" $flags -x c++ -c -o /dev/null - >/dev/null 2>&1
|
||||
}
|
||||
|
||||
if [ -z "${CXX}" ] && ! cxx20_ok; then
|
||||
if ! activate_toolset; then
|
||||
echo "run-rpmbuild: warning: g++ lacks C++20 support and no" \
|
||||
"usable GCC Toolset was found (see buildtools/install-build-pkgs)" >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
extra_flags=
|
||||
if command -v rpm >/dev/null 2>&1 && \
|
||||
! optflags_ok && \
|
||||
optflags_ok --undefine _annotated_build
|
||||
then
|
||||
echo "run-rpmbuild: ${CXX:-g++} can't use annobin; disabling _annotated_build" >&2
|
||||
extra_flags="--undefine _annotated_build"
|
||||
fi
|
||||
|
||||
rpmbuild="$1"
|
||||
shift
|
||||
exec "$rpmbuild" $extra_flags "$@"
|
||||
|
|
@ -45,10 +45,23 @@ Distributions that enforce RPM signature checking reject the unsigned
|
|||
local build. When installing a locally built RPM that you built and
|
||||
trust, pass `--nosignature` to `rpm`.
|
||||
|
||||
Rocky Linux container builds activate newer GCC Toolsets when available.
|
||||
Both the Rocky 10 `/usr/lib/gcc-toolset/<version>-env.source` activation
|
||||
script and the older `/opt/rh/gcc-toolset-<version>/enable` layout are
|
||||
supported.
|
||||
mergerfs requires a C++20 compiler and the system `g++` on RHEL /
|
||||
Rocky 8 is too old. On RHEL / Rocky `install-build-pkgs` installs the
|
||||
newest GCC Toolset when it is newer than the system compiler, and the
|
||||
Rocky Linux container builds use it. When `CXX` is unset and the
|
||||
default `g++` can't build C++20, `make rpm` activates the newest
|
||||
installed GCC Toolset automatically. If the selected compiler lacks
|
||||
the annobin plugin that the RPM build flags load, `make rpm` also
|
||||
disables RPM's annobin annotations (`--undefine _annotated_build`).
|
||||
Both the Rocky 10 `/usr/lib/gcc-toolset/<version>-env.source`
|
||||
activation script and the older `/opt/rh/gcc-toolset-<version>/enable`
|
||||
layout are supported. To build outside of `make rpm` on such systems
|
||||
(for example `make` or `make install`) activate the toolset first:
|
||||
|
||||
```
|
||||
# . /opt/rh/gcc-toolset-<version>/enable
|
||||
# make
|
||||
```
|
||||
|
||||
## Container packages
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue