This problem is related to the current (dpkg) policy where flags target
the current default compiler and version for the specific vendor, but
some of the flags emitted are toolchain specific and can break when
used with another toolchain (say gcc vs clang for example).
I guess the options are either introducing a global toolchain setting,
for example a new CLI option and say global DEB_BUILD_TOOLCHAIN or
similar, or one per flag type, for example DEB_CFLAGS_TOOLCHAIN or DEB_FCFLAGS_FOR_BUILD_TOOLCHAIN. But this would need to contain a
generic term such as «gcc» or «clang», instead of a specific command
to use such as «g++-13», or «clang-17».
The problem with a global selector is that maintainers (or tooling
such as debhelper) might need to call dpkg-buildflags multiple times
in case the build system uses different toolchains, or each different
flag might in fact use a different toolchain by default already. So
I'm inclined to go with a per flag selector.
This also ties with the variables for the actual toolchain and specific compiler tools being used (such as CC or CXX), where there is currently
only partial support for this in the dpkg Makefile fragments, but not
in dpkg-buildpackage or dpkg-buildflags proper. Ideally these would be
set by dpkg-buildpackage so the tools and flags would be coherent, and
as a side effect its arch detection from the toolchain would then be
also consistent with the arch specified (#644664), but this cannot be
done as debian/rules is still the supported entry point for builds.
Setting this by dpkg-buildflags would be an option, and it is heavily
related to its purpose, but it's a bit off relative to its name, but
oh well. So I'm pondering to add support for setting compiler variables
too (such as CC or CXX) in dpkg-buildflags, although that would only
fix one aspect of the overall tool vs flags coherence.
[ See <https://lists.debian.org/debian-dpkg/2023/11/msg00031.html>. ]
This problem is related to the *_FOR_BUILD support (to specify flags for
the build instead of host system during cross-building), which got
recently partially improved (in dpkg 1.22.1), but there are still things
not covered.
These are at least two of the sub-problems that need to be tackled:
* Need to make features per-arch in output (such as --query), but that
might break users not expecting repeated entries. I guess the options
here might be to either:
a) try to look for users of the interfaces and make them cope (but
that would miss internal/private usage),
[ If starting from scratch I'd rather do this, but it has now
the potential for breakage. ]
b) version the interface via a CLI option,
[ This would be a general solution that would allow extensions in
the future, but complicates the interface. ]
c) add an explicit --for-build mode which would turn the output into
the *_FOR_BUILD features,
[ This is a targeted straightforward change, and a clear interface,
but it involves running the tool twice to get all the info. ]
d) or use different field keys for the paragraphs.
[ This is rather meh. ]
None of which seem ideal (although some seem less desirable) TBH.
* Need to honor build features, either from DEB_BUILD_OPTIONS or a
new envvar (and finding a non-confusing name!), but probably only for
a few of the features where it might really make sense (such as abi,
qa, hardening.pie) and which might affect the buildability or
runability of the artifacts, as anything else seems unnecessary.
I'm not certain about the envvar part, I think the last part is in
theory straightforward, the code just needs to duplicate the checks
per the various arches, and keep track of the various features per arch
internally, which might require breaking changes in the interfaces,
but I think the perl modules are not public interfaces anyway.
I'm not sure whether per-setting toolchain actually is that useful in
the end. I would expect most users of this to want to change them all at once. For instance, changing CC to clang without also updating
CFLAGS accordingly is doomed to failure. The global setting very much
makes sense to me.
Can we eventually challenge debian/rules being a supported entry point? Practically, nobody does this.
This comes with another wrinkle. What do you set CC to when your
toolchain is clang and your host architecture differs from your build architecture? I think the only correct way is to include the -target
option in the CC variable and that's going to trip up a lot of uses.
Until clang provides <triplet>-clang symlinks (which clang already
interprets correctly as far as I know), I don't class clang as a supportable toolchain given our interface.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 55:39:09 |
Calls: | 6,712 |
Files: | 12,243 |
Messages: | 5,355,397 |