Skip to content

Commit

Permalink
Enable specifying full target triples as --arch for ldc2
Browse files Browse the repository at this point in the history
By treating all 'architectures' containing a `-` as `-mtriple` values.
E.g., `dub --arch=wasm32-unknown-unknown-wasm` to cross-compile to
WebAssembly. This dub switch is already used when probing the compiler,
so the build platform detection works as expected.

Also add `wasm` as detected platform and use the .wasm executable file
extension (for ldc2).

This fixes dlang#1749 when moving the `-mtriple` option from the dub config
file to the dub command line.
  • Loading branch information
kinke committed Aug 17, 2019
1 parent c8fe948 commit 7e1b58d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion source/dub/compilers/ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
{
string[] arch_flags;
switch (arch_override) {
default: throw new Exception("Unsupported architecture: "~arch_override);
case "": break;
case "x86": arch_flags = ["-march=x86"]; break;
case "x86_64": arch_flags = ["-march=x86-64"]; break;
default:
if (arch_override.canFind('-'))
arch_flags = ["-mtriple="~arch_override];
else
throw new Exception("Unsupported architecture: "~arch_override);
break;
}
settings.addDFlags(arch_flags);

Expand Down Expand Up @@ -176,6 +181,8 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
case TargetType.executable:
if (platform.platform.canFind("windows"))
return settings.targetName ~ ".exe";
else if (platform.platform.canFind("wasm"))
return settings.targetName ~ ".wasm";
else return settings.targetName;
case TargetType.library:
case TargetType.staticLibrary:
Expand Down
1 change: 1 addition & 0 deletions source/dub/platform.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum string platformCheck = q{
version(Android) ret ~= "android";
version(Cygwin) ret ~= "cygwin";
version(MinGW) ret ~= "mingw";
version(WebAssembly) ret ~= "wasm";
return ret;
};

Expand Down

0 comments on commit 7e1b58d

Please sign in to comment.