diff --git a/source/dub/compilers/compiler.d b/source/dub/compilers/compiler.d index 7eb236b..af35c7b 100644 --- a/source/dub/compilers/compiler.d +++ b/source/dub/compilers/compiler.d @@ -252,6 +252,9 @@ /// Invokes the underlying linker directly void invokeLinker(in BuildSettings settings, in BuildPlatform platform, string[] objects, void delegate(int, string) output_callback); + /// Convert linker flags to compiler format + string[] lflagsToDFlags(in string[] lflags) const; + protected final void invokeTool(string[] args, void delegate(int, string) output_callback) { import std.string; diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index b77bc6e..c3a549f 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -130,7 +130,7 @@ } if (!(fields & BuildSetting.lflags)) { - settings.addDFlags(settings.lflags.map!(f => "-L"~f)().array()); + settings.addDFlags(lflagsToDFlags(settings.lflags)); settings.lflags = null; } @@ -203,7 +203,7 @@ 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 ~= lflagsToDFlags(settings.lflags); args ~= settings.dflags.filter!(f => isLinkerDFlag(f)).array; auto res_file = getTempFile("dub-build", ".lnk"); @@ -213,6 +213,11 @@ invokeTool([platform.compilerBinary, "@"~res_file.toNativeString()], output_callback); } + string[] lflagsToDFlags(in string[] lflags) const + { + return lflags.map!(f => "-L"~f)().array(); + } + private auto escapeArgs(in string[] args) { return args.map!(s => s.canFind(' ') ? "\""~s~"\"" : s); diff --git a/source/dub/compilers/gdc.d b/source/dub/compilers/gdc.d index 548f28c..a2d889e 100644 --- a/source/dub/compilers/gdc.d +++ b/source/dub/compilers/gdc.d @@ -135,8 +135,7 @@ } if (!(fields & BuildSetting.lflags)) { - foreach( f; settings.lflags ) - settings.addDFlags(["-Xlinker", f]); + settings.addDFlags(lflagsToDFlags(settings.lflags)); settings.lflags = null; } @@ -210,6 +209,18 @@ logDiagnostic("%s", args.join(" ")); invokeTool(args, output_callback); } + + string[] lflagsToDFlags(in string[] lflags) const + { + string[] dflags; + foreach( f; lflags ) + { + dflags ~= "-Xlinker"; + dflags ~= f; + } + + return dflags; + } } private string extractTarget(const string[] args) { auto i = args.countUntil("-o"); return i >= 0 ? args[i+1] : null; } diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index 2899d4a..16e0270 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -119,7 +119,7 @@ } if (!(fields & BuildSetting.lflags)) { - settings.addDFlags(settings.lflags.map!(s => "-L="~s)().array()); + settings.addDFlags(lflagsToDFlags(settings.lflags)); settings.lflags = null; } @@ -183,4 +183,9 @@ { assert(false, "Separate linking not implemented for LDC"); } + + string[] lflagsToDFlags(in string[] lflags) const + { + return lflags.map!(s => "-L="~s)().array(); + } } diff --git a/source/dub/project.d b/source/dub/project.d index a438953..5e65007 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -693,9 +693,9 @@ compiler.prepareBuildSettings(bs, BuildSetting.all & ~to!BuildSetting(attributeName)); if (bs.lflags) - values = bs.lflags; + values = compiler.lflagsToDFlags( bs.lflags ); else if (bs.sourceFiles) - values = bs.sourceFiles; + values = compiler.lflagsToDFlags( bs.sourceFiles ); else values = bs.dflags; diff --git a/test/4-describe-data-2-dmd.sh b/test/4-describe-data-2-dmd.sh index af0681c..64af07d 100755 --- a/test/4-describe-data-2-dmd.sh +++ b/test/4-describe-data-2-dmd.sh @@ -43,8 +43,8 @@ echo -n "-L--some-lflag " >> "$expected_file" echo -n "-L--another-lflag " >> "$expected_file" # --data=libs -echo -n "-lcrypto " >> "$expected_file" -echo -n "-lcurl " >> "$expected_file" +echo -n "-L-lcrypto " >> "$expected_file" +echo -n "-L-lcurl " >> "$expected_file" # --data=linker-files echo -n "'$CURR_DIR/describe-dependency-3/libdescribe-dependency-3.a' " >> "$expected_file" echo -n "'$CURR_DIR/describe-project/some.a' " >> "$expected_file"