Skip to content

Commit

Permalink
build.d: Use pragmas to detect host compiler
Browse files Browse the repository at this point in the history
Less brittle than parsing the output of --version
(especially to determine the frontend version)
  • Loading branch information
MoonlightSentinel committed Aug 28, 2020
1 parent 4028c58 commit 8653a7b
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -991,21 +991,24 @@ void processEnvironment()

const os = env["OS"];

const hostDMDVersion = [env["HOST_DMD_RUN"], "--version"].execute.output;

alias DMD = AliasSeq!("DMD");
alias LDC = AliasSeq!("LDC");
alias GDC = AliasSeq!("GDC", "gdmd", "gdc");
const kindIdx = hostDMDVersion.canFind(DMD, LDC, GDC);

enforce(kindIdx, "Invalid Host DMD found: " ~ hostDMDVersion);

if (kindIdx <= DMD.length)
env["HOST_DMD_KIND"] = "dmd";
else if (kindIdx <= LDC.length + DMD.length)
env["HOST_DMD_KIND"] = "ldc";
else
env["HOST_DMD_KIND"] = "gdc";
// Detect the host compiler kind and version
with (pipeProcess([env["HOST_DMD_RUN"], "-c", "-o-", "-"]))
{
stdin.writeln(q{
pragma(msg, __VENDOR__);
pragma(msg, __VERSION__);
});
stdin.close();
pid.wait();
const vendor = stderr.readln().strip();

env["HOST_DMD_KIND"] = [
"Digital Mars D": "dmd",
"LDC": "ldc",
"GNU D": "gdc"
][vendor];
env["HOST_DMD_VERSION"] = stderr.readln().strip()[0 .. $ - 1]; // Remove L
}

env["DMD_PATH"] = env["G"].buildPath("dmd").exeName;
env.getDefault("DETAB", "detab");
Expand Down

0 comments on commit 8653a7b

Please sign in to comment.