Skip to content

Commit

Permalink
Revert "Make all static library exports contribute to dlls on Windows"
Browse files Browse the repository at this point in the history
This reverts commit 076022c / PR2614.
  • Loading branch information
Geod24 committed Mar 6, 2023
1 parent 076022c commit 61c6b89
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 65 deletions.
8 changes: 0 additions & 8 deletions changelog/static_libraries_exported_dll.dd

This file was deleted.

3 changes: 0 additions & 3 deletions source/dub/compilers/compiler.d
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,6 @@ interface Compiler {

return build_platform;
}

/// Given a platform specification, determine if a compiler is on Windows and PE-COFF with MSVC link compatible linker.
bool isWindowsCOFF(in BuildPlatform platform);
}

private {
Expand Down
6 changes: 0 additions & 6 deletions source/dub/compilers/dmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,4 @@ config /etc/dmd.conf
|| arg.startsWith("-defaultlib=");
}
}

bool isWindowsCOFF(in BuildPlatform platform)
{
// x86_omf and x86_mscoff shouldn't be something you have to worry about here, but just in case something leaks
return platform.isWindows && platform.architecture.canFind("x86", "x86_64", "x86_mscoff") && !platform.architecture.canFind("x86_omf");
}
}
5 changes: 0 additions & 5 deletions source/dub/compilers/gdc.d
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,6 @@ class GDCCompiler : Compiler {

return dflags;
}

bool isWindowsCOFF(in BuildPlatform platform)
{
return false;
}
}

private string extractTarget(const string[] args) { auto i = args.countUntil("-o"); return i >= 0 ? args[i+1] : null; }
Expand Down
6 changes: 0 additions & 6 deletions source/dub/compilers/ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,4 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
|| arg.startsWith("-mtriple=");
}
}

bool isWindowsCOFF(in BuildPlatform platform)
{
// What will happen on ARM Windows? Who knows. Once LDC ships for ARM, lets find out!
return platform.isWindows();
}
}
38 changes: 1 addition & 37 deletions source/dub/generators/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,7 @@ class BuildGenerator : ProjectGenerator {
const copyDynamicLibDepsLinkerFiles = rootTT == TargetType.dynamicLibrary || rootTT == TargetType.none;
const copyDynamicLibDepsRuntimeFiles = copyDynamicLibDepsLinkerFiles || rootTT == TargetType.executable;

// Check to see if given a compiler and platform target
// are Windows and linking using a MSVC link compatible linker.
const isWindowsCOFF = settings.compiler.isWindowsCOFF(settings.platform);

bool[string] visited, visitedStaticInDll;

void visitStaticLibsInDll(ref BuildSettings bs, string target) {
if (target in visitedStaticInDll) return;
visitedStaticInDll[target] = true;

auto ti = targets[target];
if (ti.buildSettings.targetType != TargetType.staticLibrary)
return;

const ldepPath = target_paths[target].toNativeString();

// Add the MSVC link /WHOLEARCHIVE flag with static library path passed in
// the purpose of this is to allow all exports from a static library to contribute
// towards the dll's exports.
bs.addLFlags("/WHOLEARCHIVE:" ~ ldepPath);

foreach (ldep; ti.linkDependencies) {
visitStaticLibsInDll(bs, ldep);
}
}

bool[string] visited;
void buildTargetRec(string target)
{
if (target in visited) return;
Expand All @@ -136,17 +111,6 @@ class BuildGenerator : ProjectGenerator {
NativePath[] additional_dep_files;
auto bs = ti.buildSettings.dup;
const tt = bs.targetType;

// Windows only behavior for DLL's with static library dependencies
if (tt == TargetType.dynamicLibrary && isWindowsCOFF) {
// discover all static libraries that are going into our DLL
visitedStaticInDll = null;

foreach (ldep; ti.linkDependencies) {
visitStaticLibsInDll(bs, ldep);
}
}

foreach (ldep; ti.linkDependencies) {
const ldepPath = target_paths[ldep].toNativeString();
const doLink = tt != TargetType.staticLibrary && !(bs.options & BuildOption.syntaxOnly);
Expand Down

0 comments on commit 61c6b89

Please sign in to comment.