[Rpm-maint] [rpm-software-management/rpm] Clarify %_build*, %_host* and %_target* macros (Discussion #2889)
Fabian Vogt
notifications at github.com
Tue Feb 6 13:27:03 UTC 2024
I stumbled across an issue in relation to the %_host_* and %_target* macros which subtly broke some builds because of armv7l/armv7hl differences. This led me to dig into this a bit further and at this point I'm now unsure how those macros are actually meant to be used.
macros.in says:
```
#==============================================================================
# ---- config.guess platform macros.
# Macro(s) similar to the tokens used by configure.
#
%_build %{_host}
%_build_alias %{_host_alias}
%_build_cpu %{_host_cpu}
%_build_vendor %{_host_vendor}
%_build_os %{_host_os}
%_host @host@
%_host_alias @host_alias@%{nil}
%_host_cpu @host_cpu@
%_host_vendor @host_vendor@
%_host_os @host_os@
%_target %{_host}
%_target_alias %{_host_alias}
%_target_cpu %{_host_cpu}
%_target_vendor %{_host_vendor}
%_target_os %{_host_os}
```
The `@host*@` placeholders are set to whatever CMake runs on (e.g. `CMAKE_HOST_SYSTEM_PROCESSOR`), i.e. on what platform RPM was built on. I think this is already wrong. In the (currently unlikely) case that RPM was cross compiled, e.g. on an x86_64 machine to run on riscv64, @host_cpu@ and thus `%_host_cpu` would be x86_64. What machine RPM was built on should not have any effect on RPM though.
And then I'm confused about the role of build/host/target here. From my understanding, having all three of them implies the toolchain semantics:
build -> where the build happens
host -> where the built binary runs on
target -> what the built binary (e.g. compiler) targets
Question remains from which PoV this is. From RPM's PoV or the .spec file's PoV?
The rpmbuild `--target` option changes which architecture the built RPMs can be installed on and sets `%_target*` accordingly. This points to RPM's PoV. The `%configure` macro however uses `%{_configure} --host=%{_host} --build=%{_build}`, which means it's from the .spec file's PoV. This doesn't match. Example:
```
> cat test.spec
Name: test
Version: 0
Release: 0
License: WTFPL
Summary: Test
%description
%build
echo %_target
set +e
%configure
touch l
%files
%license l
> rpmbuild -bb --target=i686-unknown-linux test.spec
Building target platforms: i686-unknown-linux
Building for target i686-unknown-linux
Executing(%build): /usr/bin/bash -e /var/tmp/rpm-tmp.AGeJEj
[...]
+ echo i686-linux
i686-linux
+ set +e
+ CONFIG_SHELL=/usr/bin/bash
+ export CONFIG_SHELL
+ CFLAGS='-O2 -g -m32 -march=i686 -mtune=i686 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables'
+ export CFLAGS
[...]
+ ./configure --host=x86_64-suse-linux --build=x86_64-suse-linux --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info
/var/tmp/rpm-tmp.AGeJEj: line 46: ./configure: No such file or directory
+ touch l
+ RPM_EC=0
++ jobs -p
+ exit 0
Processing files: test-0-0.i686
[...]
Provides: test = 0-0 test(x86-32) = 0-0
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/fvogt/rpmbuild/BUILDROOT/test-0-0.i386
Wrote: /home/fvogt/rpmbuild/RPMS/i686/test-0-0.i686.rpm
[...]
```
As you can see, configure was invoked to create a binary to run on `x86_64-suse-linux` but it spat out an RPM for i686: `test-0-0.i686.rpm`.
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/discussions/2889
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/repo-discussions/2889 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20240206/14e4c233/attachment.html>
More information about the Rpm-maint
mailing list