Skip to content

Commit

Permalink
Merge pull request #505 from machindertechnologies/singleFileFixes
Browse files Browse the repository at this point in the history
Fixed singleFile build mode issues
  • Loading branch information
MartinNowak committed Feb 12, 2015
2 parents 00c5478 + 0dc606e commit 83b2926
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
3 changes: 2 additions & 1 deletion source/dub/compilers/buildsettings.d
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ enum TargetType {
library,
sourceLibrary,
dynamicLibrary,
staticLibrary
staticLibrary,
object
}

enum BuildRequirements {
Expand Down
4 changes: 4 additions & 0 deletions source/dub/compilers/compiler.d
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ string getTargetFileName(in BuildSettings settings, in BuildPlatform platform)
if( platform.platform.canFind("windows") )
return settings.targetName ~ ".dll";
else return "lib" ~ settings.targetName ~ ".so";
case TargetType.object:
if (platform.platform.canFind("windows"))
return settings.targetName ~ ".obj";
else return settings.targetName ~ ".o";
}
}

Expand Down
13 changes: 10 additions & 3 deletions source/dub/compilers/dmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ class DmdCompiler : Compiler {
version (Windows) settings.addDFlags("-shared");
else settings.addDFlags("-shared", "-fPIC");
break;
case TargetType.object:
settings.addDFlags("-c");
break;
}

if (tpath is null)
Expand All @@ -189,14 +192,18 @@ class DmdCompiler : Compiler {
{
import std.string;
auto tpath = Path(settings.targetPath) ~ getTargetFileName(settings, platform);
auto args = [platform.compilerBinary, "-of"~tpath.toNativeString()];
auto args = ["-of"~tpath.toNativeString()];
args ~= objects;
args ~= settings.sourceFiles;
version(linux) args ~= "-L--no-as-needed"; // avoids linker errors due to libraries being speficied in the wrong order by DMD
args ~= settings.lflags.map!(l => "-L"~l)().array;
args ~= settings.dflags.filter!(f => isLinkerDFlag(f)).array;
logDiagnostic("%s", args.join(" "));
invokeTool(args, output_callback);

auto res_file = getTempFile("dub-build", ".lnk");
std.file.write(res_file.toNativeString(), join(args, "\n"));

logDiagnostic("%s %s", platform.compilerBinary, args.join(" "));
invokeTool([platform.compilerBinary, "@"~res_file.toNativeString()], output_callback);
}

private static bool isLinkerDFlag(string arg)
Expand Down
1 change: 1 addition & 0 deletions source/dub/compilers/gdc.d
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class GdcCompiler : Compiler {
case TargetType.executable: break;
case TargetType.library:
case TargetType.staticLibrary:
case TargetType.object:
settings.addDFlags("-c");
break;
case TargetType.dynamicLibrary:
Expand Down
3 changes: 3 additions & 0 deletions source/dub/compilers/ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ class LdcCompiler : Compiler {
case TargetType.dynamicLibrary:
settings.addDFlags("-shared");
break;
case TargetType.object:
settings.addDFlags("-c");
break;
}

if (tpath is null)
Expand Down
9 changes: 7 additions & 2 deletions source/dub/generators/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,20 @@ class BuildGenerator : ProjectGenerator {
/// Output an unique name to represent the source file.
/// Calls with path that resolve to the same file on the filesystem will return the same,
/// unless they include different symbolic links (which are not resolved).
static string pathToObjName(string path) { return std.path.buildNormalizedPath(getcwd(), path~objSuffix)[1..$].replace("/", "."); }

static string pathToObjName(string path)
{
return std.path.stripDrive(std.path.buildNormalizedPath(getcwd(), path~objSuffix))[1..$].replace(std.path.dirSeparator, ".");
}

/// Compile a single source file (srcFile), and write the object to objName.
static string compileUnit(string srcFile, string objName, BuildSettings bs, GeneratorSettings gs) {
Path tempobj = Path(bs.targetPath)~objName;
string objPath = tempobj.toNativeString();
bs.libs = null;
bs.lflags = null;
bs.addDFlags("-c");
bs.sourceFiles = [ srcFile ];
bs.targetType = TargetType.object;
gs.compiler.prepareBuildSettings(bs, BuildSetting.commandLine);
gs.compiler.setTarget(bs, gs.platform, objPath);
gs.compiler.invoke(bs, gs.platform, gs.compileCallback);
Expand Down

0 comments on commit 83b2926

Please sign in to comment.