This is an archive of the discontinued LLVM Phabricator instance.

[clang] [MinGW] Improve detection of libstdc++ headers on Fedora
ClosedPublic

Authored by mstorsjo on Nov 25 2022, 1:15 AM.

Details

Summary

There's some variation in where different toolchain distributions
(and linux distributions) package the mingw sysroots - this is
so far handled by adding specific known subdirectory paths
to the include and lib directory lists.

There are multiple degrees of combinatorics involved here though;
the distros may use different locations such as
/usr/x86_64-w64-mingw32/include or
/usr/x86_64-w64-mingw32/sys-root/mingw/include.

So far, this setup has been treated as base=/usr, subdir=x86_64-w64-mingw32,
and the driver tries to add further subdirectories such as
<base>/<subdir>/include, <base>/<subdir>/sys-root/mingw/include.

When it comes to libstdc++ (and libc++), each of these come with
a large number of potential subdirectories. Instead of further
exploding the combinatorics another step by adding all combinations
of all paths, check whether <base>/<subdir>/sys-root/mingw/include
exists, and if it does, append that subpath into the subdir variable.

This allows finding libstdc++ headers in e.g.
/usr/x86_64-w64-mingw32/sys-root/mingw/include/c++/x86_64-w64-mingw32
on Fedora.

The same logic (where everything belonging to this target fits
under one expanded <subdir> path, with just /include and /lib
under it) doesn't seem to apply on Gentoo, where the includes
are found in <base>/<subdir>/usr/include while the libraries
are in <base>/<subdir>/mingw/lib (see
8e218026f8d5eabfdef9141ae5e26aa91d1933e6). But apparently
the libstdc++ headers aren't installed under
<base>/<subdir>/usr/include, so that path hierarchy quirk doesn't
need to be taken into account in AddClangCXXStdlibIncludeArgs.

Diff Detail

Event Timeline

mstorsjo created this revision.Nov 25 2022, 1:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 25 2022, 1:15 AM
Herald added a subscriber: pengfei. · View Herald Transcript
mstorsjo requested review of this revision.Nov 25 2022, 1:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 25 2022, 1:15 AM
Herald added a subscriber: MaskRay. · View Herald Transcript
mati865 accepted this revision.Nov 25 2022, 3:58 PM

LGTM

This revision is now accepted and ready to land.Nov 25 2022, 3:58 PM
This revision was landed with ongoing or failed builds.Nov 29 2022, 1:17 PM
This revision was automatically updated to reflect the committed changes.