diff --git a/source/app.d b/source/app.d index 62faea9..a0e9cb4 100644 --- a/source/app.d +++ b/source/app.d @@ -193,11 +193,6 @@ auto settings = dub.getBuildSettings(build_platform, build_config); settings.addDFlags(["-w", "-property"]); settings.addVersions(getPackagesAsVersion(dub)); - - compiler.prepareBuildSettings(settings, BuildSetting.commandLine); - flags ~= settings.dflags; - flags ~= (mainsrc).toNativeString(); - string dflags = environment.get("DFLAGS"); if( dflags ){ build_type = "$DFLAGS"; @@ -212,12 +207,17 @@ case "docs": assert(false, "docgen not implemented"); } } + settings.addDFlags(dflags.split()); + + compiler.prepareBuildSettings(settings, BuildSetting.commandLine); + flags ~= settings.dflags; + flags ~= (mainsrc).toNativeString(); if( build_config.length ) logInfo("Building configuration "~build_config~", build type "~build_type); else logInfo("Building default configuration, build type "~build_type); - logInfo("Running %s", "rdmd " ~ dflags ~ " " ~ join(flags, " ")); - auto rdmd_pid = spawnProcess("rdmd " ~ dflags ~ " " ~ join(flags, " ")); + logInfo("Running %s", "rdmd " ~ join(flags, " ")); + auto rdmd_pid = spawnProcess("rdmd", flags); auto result = rdmd_pid.wait(); enforce(result == 0, "Build command failed with exit code "~to!string(result)); diff --git a/source/dub/compilers/gdc.d b/source/dub/compilers/gdc.d new file mode 100644 index 0000000..01aad25 --- /dev/null +++ b/source/dub/compilers/gdc.d @@ -0,0 +1,120 @@ +/** + GDC 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.gdc; + +import dub.compilers.compiler; + +import std.algorithm; +import std.array; +import std.conv; +import std.exception; +import stdx.process; +import vibe.core.log; + + +class GdcCompiler : Compiler { + @property string name() const { return "gdc"; } + + 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; + case "-cov": newdflags ~= ["-fprofile-arcs", "-ftest-coverage"]; break; + case "-D": newdflags ~= "-fdoc"; break; + //case "-Dd[dir]": newdflags ~= ""; break; + //case "-Df[file]": newdflags ~= ""; break; + case "-d": newdflags ~= "-fdeprecated"; break; + case "-dw": break; + case "-de": break; + case "-debug": newdflags ~= "-fdebug"; break; + //case "-debug=[level/ident]": newdflags ~= ""; break; + //case "-debuglib=[ident]": newdflags ~= ""; break; + //case "-defaultlib=[ident]": newdflags ~= ""; break; + //case "-deps=[file]": newdflags ~= ""; break; + case "-fPIC": newdflags ~= ""; break; + case "-g": newdflags ~= "-g"; break; + case "-gc": newdflags ~= ["-g" ~ "-fdebug-c"]; break; + case "-gs": break; + case "-H": newdflags ~= "-fintfc"; break; + //case "-Hd[dir]": newdflags ~= ""; break; + //case "-Hf[file]": newdflags ~= ""; break; + case "-ignore": newdflags ~= "-fignore-unknown-pragmas"; break; + case "-inline": newdflags ~= "-finline-functions"; break; + //case "-lib": newdflags ~= ""; break; + //case "-m32": newdflags ~= ""; break; + //case "-m64": newdflags ~= ""; break; + case "-noboundscheck": newdflags ~= "-fno-bounds-check"; break; + case "-O": newdflags ~= "-O3"; break; + case "-o-": newdflags ~= "-fsyntax-only"; break; + //case "-od[dir]": newdflags ~= ""; break; + //case "-of[file]": newdflags ~= ""; break; + //case "-op": newdflags ~= ""; break; + //case "-profile": newdflags ~= "-pg"; break; + case "-property": newdflags ~= "-fproperty"; break; + //case "-quiet": newdflags ~= ""; break; + case "-release": newdflags ~= "-frelease"; break; + case "-shared": newdflags ~= "-shared"; break; + case "-unittest": newdflags ~= "-funittest"; break; + case "-v": newdflags ~= "-fd-verbose"; break; + //case "-version=[level/ident]": newdflags ~= ""; break; + case "-vtls": newdflags ~= "-fd-vtls"; break; + case "-w": newdflags ~= "-Werror"; break; + case "-wi": newdflags ~= "-Wall"; break; + //case "-X": newdflags ~= ""; break; + //case "-Xf[file]": newdflags ~= ""; 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); + } +}