On 03/06/24 01:24, Guillem Jover wrote:
during native builds, dpkg-buildflags returns an empty CFLAGS_FOR_BUILD. The
same happens for CPPFLAGS_FOR_BUILD, LDFLAGS_FOR_BUILD and other *_FOR_BUILD
variables.
Given that CFLAGS_FOR_BUILD is supposed to be used instead of CFLAGS (not
_in addition to_ it), dpkg-buildflags should set CFLAGS_FOR_BUILD to CFLAGS,
so that the same set of, say, hardening flags will be used.
This was covered in
<https://lists.debian.org/debian-dpkg/2023/11/msg00032.html>. The
important part is that we cannot unconditionally set *_FOR_BUILD flags
from the host ones or that would break with host specific ones.
Right. This is also what I experienced when I tried to do that in d/rules.
I guess we could special case the native build one and then copying
them over, although this could incur build failures at this point in
time. :/
Why should this lead to build failures?
Support for _FOR_BUILD in dpkg-dev is new (not yet shipped in a stable
release) and opt-in. In addition, there is only a handful of packages
that explicitly deal with _FOR_BUILD variables [1], and pretty much of
them use a variation of:
export CFLAGS_FOR_BUILD = $(shell dpkg-architecture -f
-a$(DEB_BUILD_ARCH) -c dpkg-buildflags --get CFLAGS)
or:
CFLAGS_FOR_BUILD="$(CFLAGS)" dh_auto_configure
As long as this bug is not fixed, maintainers will have to add to
d/rules something like (from [2]):
```
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -Wall
export CFLAGS CPPFLAGS LDFLAGS
ifeq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
# *_FOR_BUILD variables are not set for native builds, see #1072332.
export CFLAGS_FOR_BUILD = $(CFLAGS)
export CPPFLAGS_FOR_BUILD = $(CPPFLAGS)
export LDFLAGS_FOR_BUILD = $(LDFLAGS)
else
export CFLAGS_FOR_BUILD CPPFLAGS_FOR_BUILD LDFLAGS_FOR_BUILD
endif
```
This seems the kind of "knowledge" that is best dealt with in dpkg-dev.
I guess this might be in the context of blhc?
blhc was indeed what kick-started my research into _FOR_BUILD.
Regards,
[1]
https://codesearch.debian.net/search?q=_FOR_BUILD+path%3Adebian%2Frules&literal=1&perpkg=1
[2] https://salsa.debian.org/gioele/bash/-/commit/011ebd44
--
Gioele Barabucci