[libcxx] Omit dllimport in public headers in MinGW mode
authorMartin Storsjö <martin@martin.st>
Sat, 9 Apr 2022 21:32:03 +0000 (00:32 +0300)
committerMartin Storsjö <martin@martin.st>
Mon, 6 Jun 2022 20:19:22 +0000 (23:19 +0300)
commitdfa88927ae1411ccc3b248b7e624f2acf623d947
tree622533a26dee0b14193c2f4f92b1167f5a6722e5
parent4940caaebbe04af55c0bd36d2ad291fa75932260
[libcxx] Omit dllimport in public headers in MinGW mode

In MinGW environments, thanks to slightly different code generation
and linker tricks, it's possible to link against a DLL C++ standard
library without dllimport attributes.

This allows using one single set of headers for linking against
either the DLL or a static library, leaving the decision entirely
up to the linking stage (where it can be switched with options like
-static-libstdc++).

This matches how libstdc++ headers work; there's no dllimport attributes
by default (unless the user has defined _GLIBCXX_DLL when including
headers).

This allows using one single set of headers while linking against
either a DLL or a static library, just like on Unix platforms.

This matches how libc++ has been used in MinGW configurations for
years (by first building the DLL, then configuring a static-only
build and installing on top, overwriting the libc++ config file
with one for static linking) by multiple MinGW toolchains, making
the dllimport-less use the de-facto tested configuration in the wild.

This also allows building all of libc++ in one single CMake
configuration, instead of having to do two separate builds on top of
each other.

(Linking against a DLL without dllimport can break if e.g. templates
use inconsistent visibility attributes - in cases where it still
works when using explicit dllimport; such a case was fixed in
948dd664c3ed30dd853df03cb931436f280bad4a / D99932. With this as the
default configuration, we can catch such issues in CI.)

Differential Revision: https://reviews.llvm.org/D125924
libcxx/include/__config