Default autotools CFLAGS are overriden in some cases

Bug #1791946 reported by Alfonso Sanchez-Beato
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
Expired
Undecided
Unassigned

Bug Description

snapcraft overrides CFLAGS in case the staged packages pull files under folders "include", "usr/include", etc. In that case CFLAGS is of the form:

CFLAGS= -I<part_dir>/install/usr/include -I<part_dir>/usr/include/x86_64-linux-gnu ...

But, that overrides autotools defaults, which are

CFLAGS=-g -O2

Therefore, inadvertently we disable all optimizations. Even more, things can go weird and in some cases one part is built with "-g -O2", while the others are not. For instance, with the modem-manager snap:

https://git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/modem-manager/tree/snapcraft.yaml

where libmbim is compiled with "-g -O2" while the other parts are not, as there are headers in "stage" folder.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

We should either keep default CFLAGS when adding our own or provide our own set of defaults applied to all projects

Tony Espy (awe)
Changed in snapcraft:
status: New → Incomplete
status: Incomplete → Confirmed
Revision history for this message
Jim Hodapp (jhodapp) wrote :

@sergio: I heard this is implemented already, should this be fix committed or even fix released?

Changed in snapcraft:
status: Confirmed → Fix Released
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

@sergiusens, so, what has been the solution for this?

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

I think the solution here would be to append the "-I <folder>" directives to CFLAGS instead of overriding it.

Changed in snapcraft:
status: Fix Released → Confirmed
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

This seems to be standard behavior, if we do this, we have no way to override the defaults, no matter what you set. I know snapcraft sets the CFLAGS for you, but we really do not know what the defaults are going to be for a project as those could be set per project.

Introducing this change now has the potential to cause unexpected side effects, I also believe that what you probably want is "dpkg-buildflags --get CFLAGS".

We can set that as a default for core24 if desired, which is still on grade devel.

If field is willing to accept the potential support burden on potentially having builds break, I am more than happy to set a fixed default for CFLAGS on older bases, such that the following could break:

"""
    If using the GNU C compiler, set shell variable GCC to ‘yes’. If output variable CFLAGS was not already set, set it to -g -O2 for the GNU C compiler (-O2 on systems where GCC does not accept -g), or -g for other compilers. If your package does not like this default, then it is acceptable to insert the line

    : ${CFLAGS=""}

    after AC_INIT and before AC_PROG_CC to select an empty default instead.
"""

Changed in snapcraft:
status: Confirmed → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for Snapcraft because there has been no activity for 60 days.]

Changed in snapcraft:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.