diff --git a/source/dub/compilers/compiler.d b/source/dub/compilers/compiler.d index dbf7b3f..b066ab7 100644 --- a/source/dub/compilers/compiler.d +++ b/source/dub/compilers/compiler.d @@ -9,7 +9,9 @@ import dub.compilers.dmd; import dub.compilers.gdc; +import dub.compilers.ldc; +import std.algorithm; import std.array; import vibe.data.json; @@ -18,15 +20,21 @@ { registerCompiler(new DmdCompiler); registerCompiler(new GdcCompiler); + registerCompiler(new LdcCompiler); } Compiler getCompiler(string name) { - if( name == "gdmd" || name == "ldmd" ) name = "dmd"; foreach( c; s_compilers ) if( c.name == name ) return c; + + // try to match names like gdmd or gdc-2.61 + if( name.canFind("dmd") ) return getCompiler("dmd"); + if( name.canFind("gdc") ) return getCompiler("gdc"); + if( name.canFind("ldc") ) return getCompiler("ldc"); + throw new Exception("Unknown compiler: "~name); } diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d new file mode 100644 index 0000000..62bb5b8 --- /dev/null +++ b/source/dub/compilers/ldc.d @@ -0,0 +1,77 @@ +/** + LDC compiler support. + + Copyright: © 2013 rejectedsoftware e.K. + License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. + Authors: Sönke Ludwig +*/ +module dub.compilers.ldc; + +import dub.compilers.compiler; + +import std.algorithm; +import std.array; +import std.conv; +import std.exception; +import stdx.process; +import vibe.core.log; + + +class LdcCompiler : Compiler { + @property string name() const { return "ldc"; } + + void prepareBuildSettings(ref BuildSettings settings, BuildSetting fields = BuildSetting.all) + { + // convert common DMD flags to the corresponding GDC flags + string[] newdflags; + foreach(f; settings.dflags){ + switch(f){ + default: newdflags ~= f; break; + } + } + settings.dflags = newdflags; + + if( !(fields & BuildSetting.libs) ){ + try { + logDebug("Trying to use pkg-config to resolve library flags for %s.", settings.libs); + auto libflags = execute("pkg-config", "--libs" ~ settings.libs.map!(l => "lib"~l)().array()); + enforce(libflags.status == 0, "pkg-config exited with error code "~to!string(libflags.status)); + settings.addLFlags(libflags.output.split()); + } catch( Exception e ){ + logDebug("pkg-config failed: %s", e.msg); + logDebug("Falling back to direct -lxyz flags."); + settings.addLFlags(settings.libs.map!(l => "-l"~l)().array()); + } + settings.libs = null; + } + + if( !(fields & BuildSetting.versions) ){ + settings.addDFlags(settings.versions.map!(s => "-fversion="~s)().array()); + settings.versions = null; + } + + if( !(fields & BuildSetting.importPaths) ){ + settings.addDFlags(settings.importPaths.map!(s => "-I"~s)().array()); + settings.importPaths = null; + } + + if( !(fields & BuildSetting.stringImportPaths) ){ + settings.addDFlags(settings.stringImportPaths.map!(s => "-J"~s)().array()); + settings.stringImportPaths = null; + } + + if( !(fields & BuildSetting.files) ){ + settings.addDFlags(settings.files); + settings.files = null; + } + + if( !(fields & BuildSetting.lflags) ){ + foreach( f; settings.lflags ) + settings.addDFlags(["-Xlinker", f]); + settings.lflags = null; + } + + assert(fields & BuildSetting.dflags); + assert(fields & BuildSetting.copyFiles); + } +}