• Bug#1072332: dpkg-buildflags: CFLAGS_FOR_BUILD should match CFLAGS for

    From Guillem Jover@1:229/2 to Gioele Barabucci on Mon Jun 3 01:30:02 2024
    XPost: linux.debian.bugs.dist
    From: guillem@debian.org

    Hi!

    On Sat, 2024-06-01 at 10:13:04 +0200, Gioele Barabucci wrote:
    Package: dpkg-dev
    Version: 1.22.6

    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.

    In general given that those artifacts built using *_FOR_BUILD should
    never end up in a .deb, the set of build flags do not seem really
    important, as long as their omission would not cause build failures.

    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. 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. :/

    I guess this might be in the context of blhc?

    Thanks,
    Guillem

    --- SoupGate-Win32 v1.05
    * Origin: you cannot sedate... all the things you hate (1:229/2)
  • From Guillem Jover@1:229/2 to Gioele Barabucci on Tue Jun 4 12:00:01 2024
    XPost: linux.debian.bugs.dist
    From: guillem@debian.org

    Hi!

    On Tue, 2024-06-04 at 10:57:20 +0200, Gioele Barabucci wrote:
    On 03/06/24 01:24, Guillem Jover wrote:
    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?

    This could trigger build failures with the newly introduced -Werror
    flags for example. But…

    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

    …if these packages are already doing this (which is even worse and
    defeats the entire point of its introduction :), then there should
    be no new build failures at least.

    (My concern was to avoid throwing more wood into the time64
    transition fire. :/ )

    [1] https://codesearch.debian.net/search?q=_FOR_BUILD+path%3Adebian%2Frules&literal=1&perpkg=1

    Thanks, should have probably checked myself.

    I guess I'll be pushing something like the attached changed for the
    next release, which I'd like to do by the end of this week or so.

    Thanks,
    Guillem

    diff --git i/scripts/Dpkg/Vendor/Debian.pm w/scripts/Dpkg/Vendor/Debian.pm index b3be69e86..baa0afbe8 100644
    --- i/scripts/Dpkg/Vendor/Debian.pm
    +++ w/scripts/Dpkg/Vendor/Debian.pm
    @@ -449,9 +449,6 @@ sub add_build_flags {
    }

    $flags->append($_, $default_flags) foreach @compile_flags;
    - $flags->append($_ . '_FOR_BUILD', $default_flags) foreach @compile_flags; - $flags->append('DFLAGS', $default_d_flags);
    - $flags->append('DFLAGS_FOR_BUILD', $default_d_flags);

    ## Area: abi

    @@ -632,6 +629,23 @@ sub add_build_flags {
    $flags->append($_, $flag) foreach @compile_flags;
    }
    }
    +
    + # XXX: Handle *_FOR_BUILD flags here until we can properly initialize them.
    + require Dpkg::Arch;
    +
    + my $host_arch = Dpkg::Arch::get_host_arch();
    + my $build_arch = Dpkg::Arch::get_build_arch();
    +
    + if ($host_arch eq $build_arch) {
    + foreach my $flag ($flags->list()) {
    + my $value = $flags->get($flag);
    + $flags->append($flag . '_FOR_BUILD', $value);
    + }
    + } else {
    + $flags->append($_ . '_FOR_BUILD', $default_