diff --git a/changelog/improved-ldc-cross-compile.dd b/changelog/improved-ldc-cross-compile.dd new file mode 100644 index 0000000..1ddaf22 --- /dev/null +++ b/changelog/improved-ldc-cross-compile.dd @@ -0,0 +1,3 @@ +Improve ldc cross compilation + +Enables co-existence and parallel compilation of the same project with different settings (e.g. cross compilation) by moving `.dub/obj` to `$DUB_TARGET_PATH/obj`. \ No newline at end of file diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index b92cbea..7d018c9 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -103,6 +103,7 @@ void prepareBuildSettings(ref BuildSettings settings, const scope ref BuildPlatform platform, BuildSetting fields = BuildSetting.all) const { + import std.format : format; enforceBuildRequirements(settings); if (!(fields & BuildSetting.options)) { @@ -112,7 +113,7 @@ } // since LDC always outputs multiple object files, avoid conflicts by default - settings.addDFlags("--oq", "-od=.dub/obj"); + settings.addDFlags("--oq", format("-od=%s/obj", settings.targetPath)); if (!(fields & BuildSetting.versions)) { settings.addDFlags(settings.versions.map!(s => "-d-version="~s)().array()); diff --git a/source/dub/dub.d b/source/dub/dub.d index f5b4699..e88ece2 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -820,7 +820,6 @@ // TODO: clear target files and copy files if (existsFile(path ~ ".dub/build")) rmdirRecurse((path ~ ".dub/build").toNativeString()); - if (existsFile(path ~ ".dub/obj")) rmdirRecurse((path ~ ".dub/obj").toNativeString()); if (existsFile(path ~ ".dub/metadata_cache.json")) std.file.remove((path ~ ".dub/metadata_cache.json").toNativeString()); auto p = Package.load(path); diff --git a/test/removed-dub-obj.sh b/test/removed-dub-obj.sh new file mode 100755 index 0000000..3686c61 --- /dev/null +++ b/test/removed-dub-obj.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +. $(dirname "${BASH_SOURCE[0]}")/common.sh +cd ${CURR_DIR}/removed-dub-obj +rm -rf .dub + +${DUB} build --compiler=${DC} + +[ -d ".dub/obj" ] && die $LINENO '.dub/obj was found' + +if [[ ${DC} == *"ldc"* ]]; then + [ -f .dub/build/library-*ldc*/obj/test.o* ] || die $LINENO '.dub/build/library-*ldc*/obj/test.o* was not found' +fi + +exit 0 \ No newline at end of file diff --git a/test/removed-dub-obj/.no_build b/test/removed-dub-obj/.no_build new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/removed-dub-obj/.no_build diff --git a/test/removed-dub-obj/.no_run b/test/removed-dub-obj/.no_run new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/removed-dub-obj/.no_run diff --git a/test/removed-dub-obj/.no_test b/test/removed-dub-obj/.no_test new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/removed-dub-obj/.no_test diff --git a/test/removed-dub-obj/dub.sdl b/test/removed-dub-obj/dub.sdl new file mode 100644 index 0000000..86660c8 --- /dev/null +++ b/test/removed-dub-obj/dub.sdl @@ -0,0 +1,3 @@ +name "removed-dub-obj" + +targetType "staticLibrary" \ No newline at end of file diff --git a/test/removed-dub-obj/source/test.d b/test/removed-dub-obj/source/test.d new file mode 100644 index 0000000..c6e2276 --- /dev/null +++ b/test/removed-dub-obj/source/test.d @@ -0,0 +1,6 @@ +module test; + +unittest +{ + assert(true); +} \ No newline at end of file