Windows: Make implicit dllimport more selective

* Newly require `-link-defaultlib-shared` for implicit dllimport.
  E.g., this enables to compile druntime DLL with `-fvisibility=public`
  for pure exports and no (local) imports (such as builtin TypeInfos).
* `-link-defaultlib-shared` alone now only implicitly imports symbols
  from druntime/Phobos.
  This simplifies building complex DLLs linked against a bunch of
  static libs (dub only supports static lib dependencies!); the static
  libs don't need to be compiled with `-fvisibility=public` anymore
  (if the DLL itself isn't either), `-link-defaultlib-shared` is
  sufficient.
  This is mainly useful for existing DLLs with explicit exports, to make
  them link against *shared* druntime/Phobos and so end up with a single
  druntime/Phobos for the whole process.
This commit is contained in:
Martin Kinkelin 2021-06-14 15:27:34 +02:00
parent 2f0ece3274
commit 9865e459d1
15 changed files with 73 additions and 23 deletions

View file

@ -1090,10 +1090,10 @@ int cppmain() {
v == opts::SymbolVisibility::public_ ||
// default with -shared
(v == opts::SymbolVisibility::default_ && global.params.dll);
global.params.dllimport =
v == opts::SymbolVisibility::public_ ||
// enforced when linking against shared default libs
linkAgainstSharedDefaultLibs();
global.params.dllimport = !linkAgainstSharedDefaultLibs() ? DLLImport::none
: v == opts::SymbolVisibility::public_
? DLLImport::all
: DLLImport::defaultLibsOnly;
}
// allocate the target abi