Skip to content

Commit

Permalink
Verify test
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonlightSentinel committed Mar 6, 2022
1 parent 74d9ba8 commit b8015a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 66 deletions.
4 changes: 1 addition & 3 deletions source/dub/compilers/compiler.d
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ interface Compiler {
// cmdline option does not lead to the same string being found among
// `build_platform.architecture`, as it's brittle and doesn't work with triples.
if (build_platform.compiler != "ldc") {
if (arch_override.length && !build_platform.architecture.canFind(arch_override) &&
!(build_platform.compiler == "dmd" && arch_override.among("x86_omf", "x86_mscoff")) // Will be fixed in determinePlatform
) {
if (arch_override.length && !build_platform.architecture.canFind(arch_override)) {
logWarn(`Failed to apply the selected architecture %s. Got %s.`,
arch_override, build_platform.architecture);
}
Expand Down
83 changes: 20 additions & 63 deletions source/dub/compilers/dmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -106,70 +106,29 @@ config /etc/dmd.conf

BuildPlatform determinePlatform(ref BuildSettings settings, string compiler_binary, string arch_override)
{
// Set basic arch flags for the probe - might be revised based on the exact value + compiler version
string[] arch_flags;
if (arch_override.length)
arch_flags = [ arch_override != "x86_64" ? "-m32" : "-m64" ];
else
{
// Don't use Optlink by default on Windows
version (Windows) {
const is64bit = isWow64();
if (!is64bit.isNull)
arch_flags = [ is64bit.get ? "-m64" : "-m32" ];
}
}

BuildPlatform bp = probePlatform(
compiler_binary,
arch_flags ~ ["-quiet", "-c", "-o-", "-v"],
arch_override
);

/// Replace archticture string in `bp.archtiecture`
void replaceArch(const string from, const string to)
{
const idx = bp.architecture.countUntil(from);
if (idx != -1)
bp.architecture[idx] = to;
}

// DMD 2.099 changed the default for -m32 from OMF to MsCOFF
const m32IsCoff = bp.frontendVersion >= 2_099;

switch (arch_override) {
default: throw new UnsupportedArchitectureException(arch_override);
case "": break;
case "x86": arch_flags = ["-m32"]; break;
case "x86_64": arch_flags = ["-m64"]; break;

case "x86_omf":
if (m32IsCoff)
{
arch_flags = [ "-m32omf" ];
replaceArch("x86_mscoff", "x86_omf"); // Probe used the wrong default
}
else // -m32 is OMF
{
arch_flags = [ "-m32" ];
}
break;

case "x86_mscoff":
if (m32IsCoff)
{
arch_flags = [ "-m32" ];
}
else // -m32 is OMF
{
arch_flags = [ "-m32mscoff" ];
replaceArch("x86_omf", "x86_mscoff"); // Probe used the wrong default
case "":
// Don't use Optlink by default on Windows
version (Windows) {
const is64bit = isWow64();
if (!is64bit.isNull)
arch_flags = [is64bit.get ? "-m64" : "-m32mscoff"];
}
break;
case "x86": arch_flags = ["-m32"]; break;
case "x86_omf": arch_flags = ["-m32"]; break;
case "x86_64": arch_flags = ["-m64"]; break;
case "x86_mscoff": arch_flags = ["-m32mscoff"]; break;
}
settings.addDFlags(arch_flags);

return bp;
return probePlatform(
compiler_binary,
arch_flags ~ ["-quiet", "-c", "-o-", "-v"],
arch_override
);
}
version (Windows) version (DigitalMars) unittest
{
Expand Down Expand Up @@ -208,17 +167,15 @@ config /etc/dmd.conf
}

version (LDC) unittest {
import std.conv : to;

BuildSettings settings;
auto compiler = new DMDCompiler;
auto bp = compiler.determinePlatform(settings, "ldmd2", "x86");
assert(bp.architecture.canFind("x86"), bp.architecture.to!string);
assert(!bp.architecture.canFind("x86_omf"), bp.architecture.to!string);
assert(bp.architecture.canFind("x86"));
assert(!bp.architecture.canFind("x86_omf"));
bp = compiler.determinePlatform(settings, "ldmd2", "");
version (X86) assert(bp.architecture.canFind("x86"), bp.architecture.to!string);
version (X86_64) assert(bp.architecture.canFind("x86_64"), bp.architecture.to!string);
assert(!bp.architecture.canFind("x86_omf"), bp.architecture.to!string);
version (X86) assert(bp.architecture.canFind("x86"));
version (X86_64) assert(bp.architecture.canFind("x86_64"));
assert(!bp.architecture.canFind("x86_omf"));
}

void prepareBuildSettings(ref BuildSettings settings, const scope ref BuildPlatform platform,
Expand Down

0 comments on commit b8015a2

Please sign in to comment.