@@ -97,7 +97,32 @@ class BuildGenerator : ProjectGenerator {
97
97
const copyDynamicLibDepsLinkerFiles = rootTT == TargetType.dynamicLibrary || rootTT == TargetType.none;
98
98
const copyDynamicLibDepsRuntimeFiles = copyDynamicLibDepsLinkerFiles || rootTT == TargetType.executable;
99
99
100
- bool [string ] visited;
100
+ // Check to see if given a compiler and platform target
101
+ // are Windows and linking using a MSVC link compatible linker.
102
+ const isWindowsCOFF = settings.compiler.isWindowsCOFF(settings.platform);
103
+
104
+ bool [string ] visited, visitedStaticInDll;
105
+
106
+ void visitStaticLibsInDll (ref BuildSettings bs, string target) {
107
+ if (target in visitedStaticInDll) return ;
108
+ visitedStaticInDll[target] = true ;
109
+
110
+ auto ti = targets[target];
111
+ if (ti.buildSettings.targetType != TargetType.staticLibrary)
112
+ return ;
113
+
114
+ const ldepPath = target_paths[target].toNativeString();
115
+
116
+ // Add the MSVC link /WHOLEARCHIVE flag with static library path passed in
117
+ // the purpose of this is to allow all exports from a static library to contribute
118
+ // towards the dll's exports.
119
+ bs.addLFlags(" /WHOLEARCHIVE:" ~ ldepPath);
120
+
121
+ foreach (ldep; ti.linkDependencies) {
122
+ visitStaticLibsInDll(bs, ldep);
123
+ }
124
+ }
125
+
101
126
void buildTargetRec (string target)
102
127
{
103
128
if (target in visited) return ;
@@ -111,6 +136,17 @@ class BuildGenerator : ProjectGenerator {
111
136
NativePath[] additional_dep_files;
112
137
auto bs = ti.buildSettings.dup ;
113
138
const tt = bs.targetType;
139
+
140
+ // Windows only behavior for DLL's with static library dependencies
141
+ if (tt == TargetType.dynamicLibrary && isWindowsCOFF) {
142
+ // discover all static libraries that are going into our DLL
143
+ visitedStaticInDll = null ;
144
+
145
+ foreach (ldep; ti.linkDependencies) {
146
+ visitStaticLibsInDll(bs, ldep);
147
+ }
148
+ }
149
+
114
150
foreach (ldep; ti.linkDependencies) {
115
151
const ldepPath = target_paths[ldep].toNativeString();
116
152
const doLink = tt != TargetType.staticLibrary && ! (bs.options & BuildOption.syntaxOnly);
0 commit comments