Skip to content

Commit

Permalink
LDC: Don't keep around temporary object files for static libs
Browse files Browse the repository at this point in the history
This was a workaround for older LDC versions. Since LDC v1.25,
`-cleanup-obj` implies that the temporary object files are placed
into a unique temp directory (per compiler invocation), so that
object file collisions across parallel dub invocations cannot happen
anymore.
  • Loading branch information
kinke committed Aug 24, 2023
1 parent 84ddba0 commit 050ca7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
7 changes: 3 additions & 4 deletions source/dub/compilers/ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
settings.addDFlags(t[1]);
}

// since LDC always outputs multiple object files, avoid conflicts by default
settings.addDFlags("--oq", format("-od=%s/obj", settings.targetPath));

if (!(fields & BuildSetting.versions)) {
settings.addDFlags(settings.versions.map!(s => "-d-version="~s)().array());
settings.versions = null;
Expand Down Expand Up @@ -234,7 +231,9 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
case TargetType.executable: break;
case TargetType.library:
case TargetType.staticLibrary:
settings.addDFlags("-lib");
// -oq: name object files uniquely (so the files don't collide)
// -cleanup-obj: remove object files after archiving to static lib, and put them in a unique temp directory
settings.addDFlags("-lib", "-oq", "-cleanup-obj");
break;
case TargetType.dynamicLibrary:
settings.addDFlags("-shared");
Expand Down
16 changes: 5 additions & 11 deletions test/removed-dub-obj.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
. $(dirname "${BASH_SOURCE[0]}")/common.sh
cd ${CURR_DIR}/removed-dub-obj

DUB_CACHE_PATH="$HOME/.dub/cache/removed-dub-obj/"
DUB_CACHE_PATH="$HOME/.dub/cache/removed-dub-obj"

rm -rf $DUB_CACHE_PATH
rm -rf "$DUB_CACHE_PATH"

${DUB} build --compiler=${DC}

[ -d "$DUB_CACHE_PATH/obj" ] && die $LINENO "$DUB_CACHE_PATH/obj was found"
[ -d "$DUB_CACHE_PATH" ] || die $LINENO "$DUB_CACHE_PATH not found"

if [[ ${DC} == *"ldc"* ]]; then
if [ ! -f $DUB_CACHE_PATH/~master/build/library-*/obj/test.o* ]; then
ls -lR $DUB_CACHE_PATH
die $LINENO '$DUB_CACHE_PATH/~master/build/library-*/obj/test.o* was not found'
fi
fi

exit 0
numObjectFiles=$(find "$DUB_CACHE_PATH" -type f -iname '*.o*' | wc -l)
[ "$numObjectFiles" -eq 0 ] || die $LINENO "Found left-over object files in $DUB_CACHE_PATH"

0 comments on commit 050ca7f

Please sign in to comment.