Skip to content

Commit

Permalink
ldc2: Fix MSVC target detection for static libs
Browse files Browse the repository at this point in the history
With --arch, the build (target) platform might now diverge from the host
platform. The compiler's default triple doesn't matter when
cross-compiling, so use the <name>.lib MSVC format when targeting Windows
but not MinGW.

This fixes one aspect of #1599.
  • Loading branch information
kinke committed Aug 17, 2019
1 parent 7e1b58d commit 3d9abc4
Showing 1 changed file with 7 additions and 31 deletions.
38 changes: 7 additions & 31 deletions source/dub/compilers/ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -174,29 +174,30 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
const {
assert(settings.targetName.length > 0, "No target name set.");

const p = platform.platform;
final switch (settings.targetType) {
case TargetType.autodetect: assert(false, "Configurations must have a concrete target type.");
case TargetType.none: return null;
case TargetType.sourceLibrary: return null;
case TargetType.executable:
if (platform.platform.canFind("windows"))
if (p.canFind("windows"))
return settings.targetName ~ ".exe";
else if (platform.platform.canFind("wasm"))
else if (p.canFind("wasm"))
return settings.targetName ~ ".wasm";
else return settings.targetName;
case TargetType.library:
case TargetType.staticLibrary:
if (platform.platform.canFind("windows") && generatesCOFF(platform))
if (p.canFind("windows") && !p.canFind("mingw"))
return settings.targetName ~ ".lib";
else return "lib" ~ settings.targetName ~ ".a";
case TargetType.dynamicLibrary:
if (platform.platform.canFind("windows"))
if (p.canFind("windows"))
return settings.targetName ~ ".dll";
else if (platform.platform.canFind("osx"))
else if (p.canFind("osx"))
return "lib" ~ settings.targetName ~ ".dylib";
else return "lib" ~ settings.targetName ~ ".so";
case TargetType.object:
if (platform.platform.canFind("windows"))
if (p.canFind("windows"))
return settings.targetName ~ ".obj";
else return settings.targetName ~ ".o";
}
Expand Down Expand Up @@ -284,29 +285,4 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
|| arg.startsWith("-mtriple=");
}
}

private static bool generatesCOFF(in BuildPlatform platform)
{
import std.string : splitLines, strip;
import std.uni : toLower;

static bool[string] compiler_coff_map;

if (auto pret = platform.compilerBinary in compiler_coff_map)
return *pret;

auto result = executeShell(escapeShellCommand([platform.compilerBinary, "-version"]));
enforce (result.status == 0, "Failed to determine linker used by LDC. \""
~platform.compilerBinary~" -version\" failed with exit code "
~result.status.to!string()~".");

bool ret = result.output
.splitLines
.find!(l => l.strip.toLower.startsWith("default target:"))
.front
.canFind("msvc");

compiler_coff_map[platform.compilerBinary] = ret;
return ret;
}
}

0 comments on commit 3d9abc4

Please sign in to comment.